Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1778,11 +1778,23 @@ def rustc_compile_action(
elif ctx.attr.require_explicit_unstable_features == -1:
require_explicit_unstable_features = toolchain.require_explicit_unstable_features

use_split_debuginfo = (
use_split_debuginfo = False
if (
feature_configuration and
cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "per_object_debug_info") and
ctx.fragments.cpp.fission_active_for_current_compilation_mode()
)
):
# `-Zsplit-dwarf-out-dir` is only available on nightly.
if toolchain.channel == "nightly":
use_split_debuginfo = True
elif toolchain._skip_fission_for_rust:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user, I'd expect that if _skip_fission_for_rust is true and toolchain.channel == "nightly", fission-for-rust is disabled... In other words, the setting takes precedence. What do you think?

use_split_debuginfo = False
else:
fail(
"Split debug info (fission) was requested, but `-Zsplit-dwarf-out-dir` requires a nightly Rust toolchain " +
"(current toolchain channel is \"{}\"). ".format(toolchain.channel) +
"To skip fission for Rust objects and suppress this error, set `--@rules_rust//rust/settings:skip_fission_for_rust`.",
)
if use_split_debuginfo:
rust_flags = rust_flags + [
"--codegen=split-debuginfo=unpacked",
Expand Down
4 changes: 4 additions & 0 deletions rust/private/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,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_compile_rustdoc_tests = ctx.attr._experimental_compile_rustdoc_tests[BuildSettingInfo].value,
_skip_fission_for_rust = ctx.attr._skip_fission_for_rust[BuildSettingInfo].value,
_experimental_use_coverage_metadata_files = ctx.attr._experimental_use_coverage_metadata_files[BuildSettingInfo].value,
_toolchain_generated_sysroot = ctx.attr._toolchain_generated_sysroot[BuildSettingInfo].value,
_incompatible_do_not_include_data_in_compile_data = ctx.attr._incompatible_do_not_include_data_in_compile_data[IncompatibleFlagInfo].enabled,
Expand Down Expand Up @@ -925,6 +926,9 @@ rust_toolchain = rule(
"_rename_first_party_crates": attr.label(
default = Label("//rust/settings:rename_first_party_crates"),
),
"_skip_fission_for_rust": attr.label(
default = Label("//rust/settings:skip_fission_for_rust"),
),
"_third_party_dir": attr.label(
default = Label("//rust/settings:third_party_dir"),
),
Expand Down
3 changes: 3 additions & 0 deletions rust/settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ load(
"require_explicit_unstable_features",
"rustc_output_diagnostics",
"rustfmt_toml",
"skip_fission_for_rust",
"third_party_dir",
"toolchain_generated_sysroot",
"toolchain_linker_preference",
Expand Down Expand Up @@ -140,3 +141,5 @@ toolchain_linker_preference()
unpretty()

zself_profile_events()

skip_fission_for_rust()
8 changes: 8 additions & 0 deletions rust/settings/settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,11 @@ def zself_profile_events(name = "zself_profile_events"):
name = name,
build_setting_default = [],
)

def skip_fission_for_rust():
"""A flag to skip split debug info (Fission) for Rust objects when using a non-nightly toolchain.
"""
bool_flag(
name = "skip_fission_for_rust",
build_setting_default = False,
)
67 changes: 67 additions & 0 deletions test/unit/debug_info/debug_info_analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,37 @@ _FISSION_COMPATIBILITY = ["@platforms//os:linux"] + select({
"//conditions:default": ["@platforms//:incompatible"],
})

# `-Zsplit-dwarf-out-dir` requires nightly. When testing split debug info,
# stable and beta should error out unless `skip_fission_for_rust` is set.
not_nightly_fission_test = analysistest.make(
_no_fission_test_impl,
config_settings = {
"//command_line_option:features": ["per_object_debug_info"],
"//command_line_option:fission": ["yes"],
str(Label("//rust/settings:skip_fission_for_rust")): True,
},
)

def _not_nightly_fission_error_test_impl(ctx):
env = analysistest.begin(ctx)
asserts.expect_failure(env, "skip_fission_for_rust")
return analysistest.end(env)

not_nightly_fission_error_test = analysistest.make(
_not_nightly_fission_error_test_impl,
expect_failure = True,
config_settings = {
"//command_line_option:features": ["per_object_debug_info"],
"//command_line_option:fission": ["yes"],
},
)

_NOT_NIGHTLY_COMPATIBILITY = ["@platforms//os:linux"] + select({
"//rust/toolchain/channel:beta": [],
"//rust/toolchain/channel:stable": [],
"//conditions:default": ["@platforms//:incompatible"],
})

def debug_info_analysis_test_suite(name):
"""Analysis tests for debug info in cdylib and bin targets.

Expand Down Expand Up @@ -295,6 +326,16 @@ def debug_info_analysis_test_suite(name):
name = "lib_no_fission_test",
target_under_test = ":mylib",
)
not_nightly_fission_test(
name = "lib_not_nightly_fission_test",
target_under_test = ":mylib",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)
not_nightly_fission_error_test(
name = "lib_not_nightly_fission_error_test",
target_under_test = ":mylib",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)

fission_test(
name = "bin_fission_test",
Expand All @@ -305,6 +346,16 @@ def debug_info_analysis_test_suite(name):
name = "bin_no_fission_test",
target_under_test = ":myrustbin",
)
not_nightly_fission_test(
name = "bin_not_nightly_fission_test",
target_under_test = ":myrustbin",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)
not_nightly_fission_error_test(
name = "bin_not_nightly_fission_error_test",
target_under_test = ":myrustbin",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)

fission_test(
name = "test_fission_test",
Expand All @@ -315,6 +366,16 @@ def debug_info_analysis_test_suite(name):
name = "test_no_fission_test",
target_under_test = ":myrusttest",
)
not_nightly_fission_test(
name = "test_not_nightly_fission_test",
target_under_test = ":myrusttest",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)
not_nightly_fission_error_test(
name = "test_not_nightly_fission_error_test",
target_under_test = ":myrusttest",
target_compatible_with = _NOT_NIGHTLY_COMPATIBILITY,
)

native.test_suite(
name = name,
Expand All @@ -324,10 +385,16 @@ def debug_info_analysis_test_suite(name):
":test_dsym_test",
":lib_fission_test",
":lib_no_fission_test",
":lib_not_nightly_fission_test",
":lib_not_nightly_fission_error_test",
":bin_fission_test",
":bin_no_fission_test",
":bin_not_nightly_fission_test",
":bin_not_nightly_fission_error_test",
":test_fission_test",
":test_no_fission_test",
":test_not_nightly_fission_test",
":test_not_nightly_fission_error_test",
] + [
":lib_pdb_test_{}".format(compilation_mode)
for compilation_mode in pdb_file_tests
Expand Down
Loading