Skip to content

Commit

Permalink
Promote experimental_toolchain_generated_sysroot to non-experimental (#…
Browse files Browse the repository at this point in the history
…2849)

No functional changes intended.

We've got a use case where the ability to turn this off is useful, see
(#2848 (comment)).

Closes #2298
  • Loading branch information
krasimirgg authored Sep 11, 2024
1 parent e4ba5e8 commit 6086030
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ def construct_arguments(
))

# Ensure the sysroot is set for the target platform
if toolchain._experimental_toolchain_generated_sysroot:
if toolchain._toolchain_generated_sysroot:
rustc_flags.add(toolchain.sysroot, format = "--sysroot=%s")

if toolchain._rename_first_party_crates:
Expand Down
8 changes: 3 additions & 5 deletions rust/settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//rust/private:unpretty.bzl", "rust_unpretty_flag")
load(":incompatible.bzl", "incompatible_flag")

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

Expand Down Expand Up @@ -85,11 +84,10 @@ bool_flag(
build_setting_default = True,
)

# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain
incompatible_flag(
name = "experimental_toolchain_generated_sysroot",
# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain.
bool_flag(
name = "toolchain_generated_sysroot",
build_setting_default = True,
issue = "https://github.com/bazelbuild/rules_rust/issues/2039",
)

# A flag to control whether to link libstd dynamically.
Expand Down
17 changes: 8 additions & 9 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ load(
"is_std_dylib",
"make_static_lib_symlink",
)
load("//rust/settings:incompatible.bzl", "IncompatibleFlagInfo")

rust_analyzer_toolchain = _rust_analyzer_toolchain
rustfmt_toolchain = _rustfmt_toolchain
Expand Down Expand Up @@ -697,7 +696,7 @@ def _rust_toolchain_impl(ctx):
_experimental_use_cc_common_link = _experimental_use_cc_common_link(ctx),
_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,
_toolchain_generated_sysroot = ctx.attr._toolchain_generated_sysroot[BuildSettingInfo].value,
_no_std = no_std,
)
return [
Expand Down Expand Up @@ -872,13 +871,6 @@ rust_toolchain = rule(
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
"_experimental_toolchain_generated_sysroot": attr.label(
default = Label("//rust/settings:experimental_toolchain_generated_sysroot"),
doc = (
"Label to a boolean build setting that lets the rule knows wheter to set --sysroot to rustc" +
"This flag is only relevant when used together with --@rules_rust//rust/settings:experimental_toolchain_generated_sysroot."
),
),
"_experimental_use_coverage_metadata_files": attr.label(
default = Label("//rust/settings:experimental_use_coverage_metadata_files"),
),
Expand All @@ -901,6 +893,13 @@ rust_toolchain = rule(
"_third_party_dir": attr.label(
default = Label("//rust/settings:third_party_dir"),
),
"_toolchain_generated_sysroot": attr.label(
default = Label("//rust/settings:toolchain_generated_sysroot"),
doc = (
"Label to a boolean build setting that lets the rule knows wheter to set --sysroot to rustc. " +
"This flag is only relevant when used together with --@rules_rust//rust/settings:toolchain_generated_sysroot."
),
),
},
toolchains = [
"@bazel_tools//tools/cpp:toolchain_type",
Expand Down
4 changes: 2 additions & 2 deletions test/toolchain/toolchain_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ toolchain_adds_rustc_flags_lib_test = analysistest.make(
_toolchain_adds_rustc_flags_lib_impl,
config_settings = {
str(Label("//:extra_rustc_flags")): [CONFIG_FLAG],
str(Label("//rust/settings:experimental_toolchain_generated_sysroot")): True,
str(Label("//rust/settings:toolchain_generated_sysroot")): True,
},
)

toolchain_adds_rustc_flags_shared_lib_test = analysistest.make(
_toolchain_adds_rustc_flags_shared_lib_impl,
config_settings = {
str(Label("//:extra_rustc_flags")): [CONFIG_FLAG],
str(Label("//rust/settings:experimental_toolchain_generated_sysroot")): True,
str(Label("//rust/settings:toolchain_generated_sysroot")): True,
},
)

Expand Down

0 comments on commit 6086030

Please sign in to comment.