diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 23867b4831..21f57b12c3 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1040,6 +1040,8 @@ def construct_arguments( # Ensure the sysroot is set for the target platform env["SYSROOT"] = toolchain.sysroot + if toolchain._experimental_toolchain_generated_sysroot: + rustc_flags.add(toolchain.sysroot, format = "--sysroot=%s") if toolchain._rename_first_party_crates: env["RULES_RUST_THIRD_PARTY_DIR"] = toolchain._third_party_dir diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl index bc00ce3450..66f6b0e52c 100644 --- a/rust/toolchain.bzl +++ b/rust/toolchain.bzl @@ -538,12 +538,6 @@ def _rust_toolchain_impl(ctx): sysroot_path = sysroot.sysroot_anchor.dirname sysroot_short_path, _, _ = sysroot.sysroot_anchor.short_path.rpartition("/") - # Override "rustc --print sysroot" with sysroot generated by `_generate_sysroot` - # in this rule implementation - rustc_flags = ctx.attr.extra_rustc_flags - if ctx.attr._experimental_toolchain_generated_sysroot[IncompatibleFlagInfo].enabled == True: - rustc_flags = ["--sysroot=" + sysroot_path] + rustc_flags - # Variables for make variable expansion make_variables = { "RUSTC": sysroot.rustc.path, @@ -630,7 +624,7 @@ def _rust_toolchain_impl(ctx): rustfmt = sysroot.rustfmt, staticlib_ext = ctx.attr.staticlib_ext, stdlib_linkflags = stdlib_linkflags_cc_info, - extra_rustc_flags = rustc_flags, + extra_rustc_flags = ctx.attr.extra_rustc_flags, extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags, per_crate_rustc_flags = ctx.attr.per_crate_rustc_flags, sysroot = sysroot_path, @@ -648,6 +642,7 @@ def _rust_toolchain_impl(ctx): _experimental_use_cc_common_link = experimental_use_cc_common_link, _experimental_use_global_allocator = experimental_use_global_allocator, _experimental_use_coverage_metadata_files = ctx.attr._experimental_use_coverage_metadata_files[BuildSettingInfo].value, + _experimental_toolchain_generated_sysroot = ctx.attr._experimental_toolchain_generated_sysroot[IncompatibleFlagInfo].enabled, _no_std = no_std, ) return [