Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set gc_goopts for all targets in a build #2402

Closed
prestonvanloon opened this issue Mar 15, 2020 · 4 comments · Fixed by #3340
Closed

Set gc_goopts for all targets in a build #2402

prestonvanloon opened this issue Mar 15, 2020 · 4 comments · Fixed by #3340

Comments

@prestonvanloon
Copy link
Contributor

What version of rules_go are you using?

0.22.1

What version of gazelle are you using?

0.20.0

What version of Bazel are you using?

2.1.1

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

Linux amd64

Any other potentially useful information about your toolchain?

Trying to build a go_binary as a c-archive with all dependencies build with gc_goopts=-d=libfuzzer

What did you do?

So I tried setting gc_goopts="-d=libfuzzer" on my go_binary target, but this flag is only applied at compile time to that specific target. So I need to apply this flag to all libraries / dependencies up to this target.

I have tried a simple bazel build setting flag like --define=gc_goopts=-d=libfuzzer, but this is not supported in rules_go. I've considered a transition rule, but I'm not sure it could be applied here.

What do you recommend as the best approach to support this functionality?

This is part of #2284, which I managed to get working, but missing some coverage symbols since -d=libfuzzer is not applied to all targets.

@jayconrod
Copy link
Contributor

Unfortunately, there's no way to do this at the moment. I'll re-title this issue as a feature request.

rules_go was modeled after Google's native Go rules in Blaze. Any kind of alternative configuration is discouraged within Google, because it means re-analyzing and re-building a large number of targets, which is expensive at scale. But that rationale doesn't make sense for regular repositories, and of course, cmd/go supports this without any issue.

It probably makes the most sense to implement this using build settings and configuration transitions, so consider this blocked on #2219. I have a prototype for that mostly working, but it still needs to be cleaned up and productionized.

@jayconrod jayconrod changed the title Question: Is there any way to set gc_goopts for all targets in a build? Set gc_goopts for all targets in a build Mar 16, 2020
@prattmic
Copy link
Contributor

With #2219 complete, it looks like this shouldn't be too hard to add via an option (e.g., --@io_bazel_rules_go//go/config:gc_goopts=flags). I'll take a look at adding this for gc_goopts, gc_linkopts, and gc_asmopts (#2612).

@prattmic
Copy link
Contributor

Note that there is also the consideration of specific configuration transitions (not sure if this is the right term?). i.e., setting gc_goopts on a go_binary would get applied to all dependencies. I'm not planning to do that, and I assume it would require more work than just the flag, though I'm not certain.

@jayconrod
Copy link
Contributor

@prattmic I think that's right, setting gc_goopts or gc_asmopts on a go_binary shouldn't trigger a configuration transition and shouldn't affect downstream targets.

We'll basically have two lists of flags: those specified in the configuration (using --@io_bazel_rules_go//go/config:gc_goopts=flags) and those specified on the target. If we can just concatenate those lists, that would be the easiest thing; not sure if that will cause problems if a flag is set more than once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants