-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make toolchain vars available but don't automatically set them
Previously if a target depended on a toolchain which exposed $(FOO), we would automatically set $FOO as an env var. This was not correct. Toolchains should make Make variables available for expansion in env vars, but should not automatically promote them to action env. If you want $FOO set, you should set $FOO=$(FOO) in the appropriate env var attribute.
- Loading branch information
1 parent
a6426e0
commit bd79d29
Showing
9 changed files
with
94 additions
and
7 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
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,25 @@ | ||
load("//cargo:defs.bzl", "cargo_build_script") | ||
load("//test/foreign_toolchain_make_variables:toolchain.bzl", "current_dummy_env_var_toolchain_toolchain", "dummy_env_var_toolchain") | ||
|
||
cargo_build_script( | ||
name = "bs", | ||
srcs = ["build.rs"], | ||
build_script_env = { | ||
"FROM_TOOLCHAIN": "$(FROM_TOOLCHAIN)", | ||
"MODIFIED_FROM_TOOLCHAIN": "modified$(FROM_TOOLCHAIN)", | ||
}, | ||
edition = "2021", | ||
toolchains = [":current_dummy_env_var_toolchain_toolchain"], | ||
) | ||
|
||
toolchain_type(name = "toolchain_type_for_test") | ||
|
||
toolchain( | ||
name = "toolchain_for_test", | ||
toolchain = ":dummy_env_var_toolchain", | ||
toolchain_type = ":toolchain_type_for_test", | ||
) | ||
|
||
dummy_env_var_toolchain(name = "dummy_env_var_toolchain") | ||
|
||
current_dummy_env_var_toolchain_toolchain(name = "current_dummy_env_var_toolchain_toolchain") |
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,9 @@ | ||
fn main() { | ||
assert_eq!(std::env::var("FROM_TOOLCHAIN").unwrap(), "present"); | ||
assert_eq!( | ||
std::env::var("MODIFIED_FROM_TOOLCHAIN").unwrap(), | ||
"modifiedpresent" | ||
); | ||
// This was not explicitly forwarded by the cargo_build_script target, so should not be present. | ||
assert!(std::env::var_os("ALSO_FROM_TOOLCHAIN").is_none()); | ||
} |
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,32 @@ | ||
def _dummy_env_var_toolchain_impl(ctx): | ||
make_variables = platform_common.TemplateVariableInfo({ | ||
"ALSO_FROM_TOOLCHAIN": "absent", | ||
"FROM_TOOLCHAIN": "present", | ||
}) | ||
|
||
return [ | ||
platform_common.ToolchainInfo( | ||
make_variables = make_variables, | ||
), | ||
make_variables, | ||
] | ||
|
||
dummy_env_var_toolchain = rule( | ||
implementation = _dummy_env_var_toolchain_impl, | ||
) | ||
|
||
def _current_dummy_env_var_toolchain_impl(ctx): | ||
toolchain = ctx.toolchains[str(Label("@rules_rust//test/foreign_toolchain_make_variables:toolchain_type_for_test"))] | ||
|
||
return [ | ||
toolchain, | ||
toolchain.make_variables, | ||
] | ||
|
||
current_dummy_env_var_toolchain_toolchain = rule( | ||
doc = "A rule for exposing the current registered `dummy_env_var_toolchain`.", | ||
implementation = _current_dummy_env_var_toolchain_impl, | ||
toolchains = [ | ||
str(Label("@rules_rust//test/foreign_toolchain_make_variables:toolchain_type_for_test")), | ||
], | ||
) |