forked from bazelbuild/rules_go
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declare toolchains in a separate repository (bazelbuild#3348)
For instance, if the SDK repository is `@go_sdk`, the toolchain rules will be defined in `@go_sdk_toolchains`. This avoids eagerly fetching `@go_sdk`, fixing bazelbuild#3196. One caveat: `:sdk_version_setting` needs to be defined in the same repo as the toolchain rule, e.g. in `@go_sdk_toolchains`. I tried `target_settings = "@go_sdk//:sdk_version_setting"`, but that causes `@go_sdk` to be eagerly fetched again. This means that `@go_sdk_toolchains` needs to know the SDK version. There are two possibilities: * The user specifies the version up front, for instance via `go_register_toolchains(version = ...)`. In that case, `@go_sdk_toolchains` uses this version. * The user does not specify the version up front. `go_wrap_sdk`, `go_download_sdk`, and `go_local_sdk` do not require a `version` attribute. In this case, we have no choice but to inspect the SDK itself to obtain the version, forcing an eager load. However, we can at least add an optional `version` attribute to these rules, so that users can avoid the eager fetch if they wish. In all cases, when a `version` attribute is provided by the user, the implementation (lazily) validates that it matches the actual SDK version.
- Loading branch information
1 parent
bc7af8b
commit df66cd2
Showing
7 changed files
with
274 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
load("@{rules_go_repo_name}//go/private:go_toolchain.bzl", "declare_bazel_toolchains") | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
|
||
{version_constants} | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
sdk_version_label = "@{rules_go_repo_name}//go/toolchain:sdk_version" | ||
|
||
config_setting( | ||
name = "match_all_versions", | ||
flag_values = { | ||
sdk_version_label: "", | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
config_setting( | ||
name = "match_major_version", | ||
flag_values = { | ||
sdk_version_label: MAJOR_VERSION, | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
config_setting( | ||
name = "match_major_minor_version", | ||
flag_values = { | ||
sdk_version_label: MAJOR_VERSION + "." + MINOR_VERSION, | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
config_setting( | ||
name = "match_patch_version", | ||
flag_values = { | ||
sdk_version_label: MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION, | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
# If prerelease version is "", this will be the same as ":match_patch_version", but that's fine since we use match_any in config_setting_group. | ||
config_setting( | ||
name = "match_prerelease_version", | ||
flag_values = { | ||
sdk_version_label: MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION + PRERELEASE_SUFFIX, | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
config_setting( | ||
name = "match_sdk_type", | ||
flag_values = { | ||
sdk_version_label: "{sdk_type}", | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
selects.config_setting_group( | ||
name = "sdk_version_setting", | ||
match_any = [ | ||
":match_all_versions", | ||
":match_major_version", | ||
":match_major_minor_version", | ||
":match_patch_version", | ||
":match_prerelease_version", | ||
":match_sdk_type", | ||
], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
declare_bazel_toolchains( | ||
host_goos = "{goos}", | ||
host_goarch = "{goarch}", | ||
toolchain_prefix = "@{sdk_repo}//", | ||
sdk_version_setting = ":sdk_version_setting", | ||
) |
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.