Skip to content

Commit 6eb7a7c

Browse files
author
Vinh Tran
committed
Use incompatible_flag rule
1 parent a9e7809 commit 6eb7a7c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

rust/private/rustc.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load(
3838
"make_static_lib_symlink",
3939
"relativize",
4040
)
41+
load("//rust/settings:incompatible.bzl", "IncompatibleFlagInfo")
4142

4243
BuildInfo = _BuildInfo
4344

@@ -966,7 +967,7 @@ def construct_arguments(
966967
rustc_flags.add(linker_script, format = "--codegen=link-arg=-T%s")
967968

968969
if hasattr(attr, "_experimental_toolchain_generated_sysroot"):
969-
if attr._experimental_toolchain_generated_sysroot[BuildSettingInfo].value == True:
970+
if attr._experimental_toolchain_generated_sysroot[IncompatibleFlagInfo].enabled == True:
970971
rustc_flags.add("--sysroot", toolchain.sysroot)
971972

972973
# Tell Rustc where to find the standard library (or libcore)

rust/settings/BUILD.bazel

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
3+
load(":incompatible.bzl", "incompatible_flag")
34

45
package(default_visibility = ["//visibility:public"])
56

@@ -65,7 +66,8 @@ bzl_library(
6566
)
6667

6768
# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain
68-
bool_flag(
69+
incompatible_flag(
6970
name = "experimental_toolchain_generated_sysroot",
70-
build_setting_default = True,
71+
build_setting_default = False,
72+
issue = "https://github.com/bazelbuild/rules_rust/issues/2039",
7173
)

test/toolchain/toolchain_test.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ def _toolchain_adds_rustc_flags_impl(ctx):
3636
"Found exec toolchain flag ({}) in rustc flags: {}".format(EXEC_TOOLCHAIN_FLAG, action.argv),
3737
)
3838

39+
asserts.true(
40+
env,
41+
"--sysroot" in action.argv,
42+
"Missing --sysroot flag",
43+
)
44+
45+
asserts.true(
46+
env,
47+
action.argv[action.argv.index("--sysroot") + 1].endswith("test/toolchain/rust_extra_flags_toolchain"),
48+
"--sysroot does not set to directory generated by rust_toolchain",
49+
)
50+
3951
return analysistest.end(env)
4052

4153
toolchain_adds_rustc_flags_test = analysistest.make(
4254
_toolchain_adds_rustc_flags_impl,
4355
config_settings = {
4456
str(Label("//:extra_rustc_flags")): [CONFIG_FLAG],
57+
str(Label("//rust/settings:experimental_toolchain_generated_sysroot")): True,
4558
},
4659
)
4760

0 commit comments

Comments
 (0)