-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Cross compiled Go (and possibly other languages), fully rebuilds when unrelated skylib flags change #13317
Description
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 has goos and goarch 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:
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
# Example copied from https://docs.bazel.build/versions/master/skylark/config.html#predefined-settings
# Please note that this rule is not used anywhere.
string_flag(
name = "myflag",
build_setting_default = "a",
values = ["a", "b", "c"],
)
go_library(
... # removing for simplicity. Generated with Gazelle
deps = ["//pkg/pb"], # depending on some protobuf. The BUILD file in //pb:BUILD is gazelle generated.
)
go_binary(
... # removing for simplicity. Generated with Gazelle
goarch = "amd64",
goos = "linux", # The problem happens even if I set this to "darwin", which should NOT cross-compile.
)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:
This sounds like a Bazel bug, especially since protoc is rebuilt. Have you asked in bazel-discuss or opened an issue in bazelbuild/bazel
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.