-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Cross compiled Go (and possibly other languages), fully rebuilds when unrelated skylib flags change #13317
Comments
Thanks for the clear reproduction, @mishas. I tried to minimize it at https://gist.github.com/gregestren/5c999b7cafeec3718a9afbf4fe17d2bf. I think #12171 is relevant, but that's a lot to wade through. The relevant logic is bazel/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java Lines 381 to 396 in 09c621e
bazel/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java Lines 434 to 435 in 09c621e
The latter determines the Long-story short, all the logic setting All said, I agree with your basic point. I believe one of Julie's proposals would address this: have The implementation of that logic may be complicated within Bazel, since it requires every transition to know what the top-level default values are. One strong Bazel design principle is targets don't have to understand anything about whoever depends on them. So passing this info from the top level down to a target is a bit of a challenge. I believe there are decent solutions to that. But this isn't a 1-hour fix. |
Thank you @gregestren for the analysis! Some things that still don't make sense to me: Thanks again! |
By cross-compile, do you mean do a build with a transition in it? If a build has no transitions, the Also, I'd never expect host tools to re-compile. Can you clarify that observation? |
@gregestren, Thanks again for the swift reply. Regarding the cross compilation / transition: To enable cross-compilation in Go, one needs to set the (It seems like it only applies transitions if one of the following keys are set: But then I tried to set I must admin that it was really hard for me to follow Regarding tools recompile. You can see that we have the following lines repeating in 2 of the compilations (
The compilation above (if I understand correctly) is of the protoc compiler, which is a tool. I'm kind of confused why it's not recompiling for Thanks again for your help! |
I'm not deeply familiar with the go rules logic either. But I think the basic principle stands that there are are reasonable scenarios where re-compilation happens and shouldn't, and we can focus this issue on that. Re: the host deps, if you run:
this shows that those actions come from
|
@gregestren, Thank you for the explanation. I wasn't aware of the difference between In any case, as you noted above, there's still recompilation when one is not necessary, and I now better understand how the issue of I guess, the only thing left for me, is to wait for this to get prioritized and fixed. Thanks again! |
Apologies about the |
This sounds promising. This in combination with the ability for a transition to reset a flag to it's top-level default value would also solve the scenario below where D is affected by build-settings from both B and C. |
Just FYI @sdtwigg and I have been actively discussing this theme recently. I think we're going to formally up-prioritize this in the new quarter (July+). |
Update: I have an idea I'm going to try prototyping to address this specific issue. Bazel has a map of "changed" Starlark options that determines hash values. I think it adds options that are set at the command line to this map, which produces the effect you see. I also think that's unnecessary - if we exclude command-line settings from that map we'll still get correct builds without this issue. I'll link a PR if it looks like it works or an updated comment if there are complications. Re: the larger issue of transitions and hashes, see #12171 (comment). |
I think #13580 will address this. I'm prioritizing the review on it now. |
Should be fixed by #13580. |
Description of the problem / feature request:
When adding a flag (e.g.
string_flag
rule) from skylib, and passing that flag to a build for a Go binary that hasgoos
andgoarch
set for it (even if not cross-compiling) - everything fully rebuilds (including host-run tools, like protoc).This happens even if that flag is not used anywhere (see example below).
This happens without protoc as well, but I'm using it in the example, as something that should not even be cross-compiled that recompiles.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Minimal example can be found here: https://github.com/mishas/bazel-cross-compile-rebuild
First run:
bazel build //pkg/demo --//pkg/demo:myflag=a
then run:
bazel build //pkg/demo --//pkg/demo:myflag=b
You'll see that it recompiles everything (including protoc compiler) when it should really not compile anything.
main BUILD file for completness:
What operating system are you running Bazel on?
I tried it both on Mac (Big Sur, 11.1) and Linux (Debian10).
It recompiles on both, even when not cross-compiling.
What's the output of
bazel info release
?release 4.0.0
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.Not relevant
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?Not relevant
Have you found anything relevant by searching the web?
I also opened a bug for rules_go (as I thought it's a bug there), but got an answer from @jayconrod:
Any other information, logs, or outputs that you want to share?
The same doesn't happen, if I use
--define myflag=<whatever>
- in the case of the (deprecated)--define
flag, only analysis runs twice, not the build.The text was updated successfully, but these errors were encountered: