Skip to content

Commit cba8163

Browse files
author
Vinh Tran
committed
Add _experimental_toolchain_generated_sysroot attr
1 parent 00078eb commit cba8163

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

.bazelci/presubmit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ tasks:
9292
test_targets: *default_linux_targets
9393
build_flags:
9494
- "--compilation_mode=opt"
95+
- "--@rules_rust//rust/settings:experimental_toolchain_generated_sysroot=True"
9596
test_flags:
9697
- "--compilation_mode=opt"
98+
- "--@rules_rust//rust/settings:experimental_toolchain_generated_sysroot=True"
9799
macos_opt:
98100
name: Opt Mode
99101
platform: macos

rust/private/rust.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ _common_attrs = {
635635
default = Label("//:experimental_per_crate_rustc_flag"),
636636
),
637637
"_experimental_toolchain_generated_sysroot": attr.label(
638-
default = Label("//rust/settings:experimental_toolchain_generated_sysroot"),
638+
default = Label("@rules_rust//rust/settings:experimental_toolchain_generated_sysroot"),
639639
),
640640
"_process_wrapper": attr.label(
641641
doc = "A process wrapper for running rustc on all platforms.",

rust/private/rustc.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,10 @@ def construct_arguments(
967967
rustc_flags.add(linker_script, format = "--codegen=link-arg=-T%s")
968968

969969
if sandboxed:
970-
rustc_flags.add("--sysroot", toolchain.sysroot)
971-
elif hasattr(ctx.attr, "_experimental_toolchain_generated_sysroot") and getattr(ctx.attr, "_experimental_toolchain_generated_sysroot") == True:
970+
if hasattr(ctx.attr, "_experimental_toolchain_generated_sysroot"):
971+
if ctx.attr._experimental_toolchain_generated_sysroot[BuildSettingInfo].value == True:
972+
rustc_flags.add("--sysroot", toolchain.sysroot)
973+
else:
972974
rustc_flags.add(toolchain.sysroot_short_path, format = "--sysroot=${{pwd}}/%s")
973975

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

rust/private/rustdoc.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def rustdoc_compile_action(
126126
rustdoc = True,
127127
force_depend_on_objects = is_test,
128128
skip_expanding_rustc_env = True,
129-
is_test = True,
130129
# rustdoc tests compile tests outside of the sandbox
131130
sandboxed = not is_test,
132131
)

rust/settings/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ bzl_library(
6767
# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain
6868
bool_flag(
6969
name = "experimental_toolchain_generated_sysroot",
70-
build_setting_default = False,
70+
build_setting_default = True,
7171
)

rust/toolchain.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,13 @@ rust_toolchain = rule(
797797
"This flag is only relevant when used together with --@rules_rust//rust/settings:experimental_use_global_allocator."
798798
),
799799
),
800+
"_experimental_toolchain_generated_sysroot": attr.label(
801+
default = Label("//rust/settings:experimental_toolchain_generated_sysroot"),
802+
doc = (
803+
"Label to a boolean build setting that lets the rule knows wheter to set --sysroot to rustc" +
804+
"This flag is only relevant when used together with --@rules_rust//rust/settings:experimental_toolchain_generated_sysroot."
805+
),
806+
),
800807
"_no_std": attr.label(
801808
default = Label("//:no_std"),
802809
),

0 commit comments

Comments
 (0)