forked from bazel-contrib/rules_go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go: use configuration transitions instead of aspect (bazel-contrib#2414)
This changes how the goos, goarch, race, msan, static, and pure attributes of go_binary and go_test are implemented. Previously, the go_binary and go_test rules used an aspect on the deps and embed attributes. If any of the mode attributes listed above were set, the aspect declared additional output files and actions to generate them for the specified configuration. This approach had two significant problems. First, the aspect caused the analysis to be performed twice, wasting time and memory even in the case where no cross-compilation was needed. Second, the aspect was not compatible with conditional dependencies specified with select expressions: aspects run on the configured target graph, but the mode attributes could not affect Bazel's configuration. This change deletes the aspect and implements these attributes using a different mechanism: build settings and configuration transitions. A new package is added //go/config with a build setting for each attribute. Most settings are flags that may be set on the command-line. This is an alternative to --feature flags, which will be deprecated and eventually removed. The target //:go_config gathers build settings relevant to Go and provides a GoContextInfo (private). The target //:go_context_data depends on //:go_config, //:stdlib, //:nogo, and a few other standard dependencies. go_binary and go_test rules no longer need to depend on these targets directly. Go rules should now only need to depend on //:go_context_data and the Go toolchain. Unfortunately, neither //:go_context_data nor //:go_config can be part of the toolchain because the toolchain is always analyzed for the execution configuration, not the target configuration. Because of the simplified dependencies, the go_rule function is no longer needed by most rules. This change makes it possible to deprecate it. Fixes bazel-contrib#1351 Fixes bazel-contrib#2219 Updates bazel-contrib#2302
- Loading branch information
Jay Conrod
authored
Apr 17, 2020
1 parent
f9a4fb1
commit 3edc6d5
Showing
38 changed files
with
967 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
load( | ||
"@bazel_skylib//rules:common_settings.bzl", | ||
"bool_flag", | ||
"bool_setting", | ||
"string_flag", | ||
"string_list_flag", | ||
) | ||
load( | ||
"//go/private:mode.bzl", | ||
"LINKMODE_NORMAL", | ||
) | ||
|
||
bool_flag( | ||
name = "static", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bool_flag( | ||
name = "race", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bool_flag( | ||
name = "msan", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bool_flag( | ||
name = "pure", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bool_setting( | ||
name = "strip", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bool_flag( | ||
name = "debug", | ||
build_setting_default = False, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
string_flag( | ||
name = "linkmode", | ||
build_setting_default = LINKMODE_NORMAL, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
string_list_flag( | ||
name = "tags", | ||
build_setting_default = [], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
testonly = True, | ||
srcs = glob(["**"]), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.