Skip to content

Commit

Permalink
Revert "Patch github.com/bazelbuild/pull/1899"
Browse files Browse the repository at this point in the history
This reverts commit cdc82e2.
  • Loading branch information
Vinh Tran committed Oct 27, 2023
1 parent c791b63 commit 94b8be0
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 415 deletions.
81 changes: 0 additions & 81 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -572,87 +572,6 @@ tasks:
test_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//:no_std=alloc"
cc_common_link_panic_abort_ubuntu2004:
name: Build via cc_common.link and -Cpanic=abort
platform: ubuntu2004
working_directory: test/cc_common_link
build_targets:
- "--"
- "//..."
# The with_global_alloc directory is a repository on its own tested in the 'Build via cc_common.link using a global allocator' task.
- "-//with_global_alloc/..."
test_targets:
- "--"
- "//..."
# The with_global_alloc directory is a repository on its own tested in the 'Build via cc_common.link using a global allocator' task.
- "-//with_global_alloc/..."
build_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//:panic_style=abort"
test_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//:panic_style=abort"
cc_common_link_with_global_alloc_panic_abort_ubuntu2004:
name: Build via cc_common.link using a global allocator and -Cpanic=abort
platform: ubuntu2004
working_directory: test/cc_common_link/with_global_alloc
build_targets:
- "//..."
test_targets:
- "//..."
build_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//rust/settings:experimental_use_global_allocator=True"
- "--@rules_rust//:panic_style=abort"
test_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//rust/settings:experimental_use_global_allocator=True"
- "--@rules_rust//:panic_style=abort"
cc_common_link_no_std_panic_abort_ubuntu2004:
name: Build with no_std + alloc using cc_common.link infrastructure for linking and -Cpanic=abort
platform: ubuntu2004
working_directory: test/no_std
build_targets:
- "//..."
test_targets:
- "//..."
build_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//rust/settings:experimental_use_global_allocator=True"
- "--@rules_rust//:no_std=alloc"
- "--@rules_rust//:panic_style=abort"
test_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//rust/settings:experimental_use_global_allocator=True"
- "--@rules_rust//:no_std=alloc"
- "--@rules_rust//:panic_style=abort"
no_std_panic_abort_ubuntu2004:
name: Build with no_std + alloc + -Cpanic=abort
platform: ubuntu2004
working_directory: test/no_std
build_targets:
- "//..."
test_targets:
- "//..."
build_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//:no_std=alloc"
- "--@rules_rust//:panic_style=abort"
test_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//:no_std=alloc"
- "--@rules_rust//:panic_style=abort"
panic_abort_ubuntu2004:
name: Build and test with -Cpanic=abort
platform: ubuntu2004
build_targets: *default_linux_targets
test_targets: *default_linux_targets
build_flags:
- "--@rules_rust//:panic_style=abort"
test_flags:
- "--@rules_rust//:panic_style=abort"
android_examples_ubuntu2004:
name: Android Examples
platform: ubuntu2004
Expand Down
12 changes: 0 additions & 12 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ error_format(
visibility = ["//visibility:public"],
)

# This setting may be changed from the command line to panic immediately upon abort.
string_flag(
name = "panic_style",
build_setting_default = "",
values = [
"abort",
"unwind",
"",
],
visibility = ["//visibility:public"],
)

# This setting may be used to pass extra options to clippy from the command line.
# It applies across all targets.
clippy_flags(
Expand Down
12 changes: 1 addition & 11 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ load(
"determine_output_hash",
"expand_dict_value_locations",
"find_toolchain",
"force_panic_unwind_transition",
"get_edition",
"get_import_macro_deps",
"transform_deps",
Expand Down Expand Up @@ -632,9 +631,6 @@ _common_attrs = {
"_is_proc_macro_dep_enabled": attr.label(
default = Label("//:is_proc_macro_dep_enabled"),
),
"_panic_style": attr.label(
default = Label("//:panic_style"),
),
"_per_crate_rustc_flag": attr.label(
default = Label("//:experimental_per_crate_rustc_flag"),
),
Expand Down Expand Up @@ -894,7 +890,6 @@ _proc_macro_dep_transition = transition(
rust_proc_macro = rule(
implementation = _rust_proc_macro_impl,
provides = _common_providers,
cfg = force_panic_unwind_transition,
# Start by copying the common attributes, then override the `deps` attribute
# to apply `_proc_macro_dep_transition`. To add this transition we additionally
# need to declare `_allowlist_function_transition`, see
Expand Down Expand Up @@ -1111,11 +1106,7 @@ rust_test = rule(
implementation = _rust_test_impl,
provides = _common_providers,
attrs = dict(_common_attrs.items() +
_rust_test_attrs.items() + {
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}.items()),
_rust_test_attrs.items()),
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
Expand All @@ -1124,7 +1115,6 @@ rust_test = rule(
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
],
cfg = force_panic_unwind_transition,
incompatible_use_toolchain_transition = True,
doc = dedent("""\
Builds a Rust test crate.
Expand Down
35 changes: 5 additions & 30 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def collect_inputs(
force_depend_on_objects (bool, optional): Forces dependencies of this rule to be objects rather than
metadata, even for libraries. This is used in rustdoc tests.
experimental_use_cc_common_link (bool, optional): Whether rules_rust uses cc_common.link to link
rust binaries.
rust binaries.
Returns:
tuple: A tuple: A tuple of the following items:
Expand Down Expand Up @@ -932,8 +932,6 @@ def construct_arguments(

rustc_flags.add(error_format, format = "--error-format=%s")

rustc_flags.add("-Cpanic=" + _get_panic_style(ctx, toolchain))

# Mangle symbols to disambiguate crates with the same name. This could
# happen only for non-final artifacts where we compute an output_hash,
# e.g., rust_library.
Expand Down Expand Up @@ -1082,15 +1080,6 @@ def construct_arguments(

return args, env

def _get_panic_style(ctx, toolchain):
panic_style = toolchain.default_panic_style

if hasattr(ctx.attr, "_panic_style"):
flag_value = ctx.attr._panic_style[BuildSettingInfo].value
if flag_value:
panic_style = flag_value
return panic_style

def rustc_compile_action(
ctx,
attr,
Expand Down Expand Up @@ -1480,29 +1469,15 @@ def _is_no_std(ctx, toolchain, crate_info):
return True

def _get_std_and_alloc_info(ctx, toolchain, crate_info):
panic_style = _get_panic_style(ctx, toolchain)
if panic_style != "unwind" and panic_style != "abort":
fail("Unrecognized panic style: " + panic_style)

if is_exec_configuration(ctx):
if panic_style == "unwind":
return toolchain.libstd_and_allocator_unwind_ccinfo
else:
return toolchain.libstd_and_allocator_abort_ccinfo
return toolchain.libstd_and_allocator_ccinfo
if toolchain._experimental_use_global_allocator:
if _is_no_std(ctx, toolchain, crate_info):
if panic_style == "unwind":
return toolchain.nostd_and_global_allocator_unwind_ccinfo
else:
return toolchain.nostd_and_global_allocator_abort_ccinfo
elif panic_style == "unwind":
return toolchain.libstd_and_global_allocator_unwind_ccinfo
return toolchain.nostd_and_global_allocator_cc_info
else:
return toolchain.libstd_and_global_allocator_abort_ccinfo
elif panic_style == "unwind":
return toolchain.libstd_and_allocator_unwind_ccinfo
return toolchain.libstd_and_global_allocator_ccinfo
else:
return toolchain.libstd_and_allocator_abort_ccinfo
return toolchain.libstd_and_allocator_ccinfo

def _is_dylib(dep):
return not bool(dep.static_library or dep.pic_static_library)
Expand Down
6 changes: 1 addition & 5 deletions rust/private/rustdoc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
load("//rust/private:common.bzl", "rust_common")
load("//rust/private:providers.bzl", "CrateInfo")
load("//rust/private:rustdoc.bzl", "rustdoc_compile_action")
load("//rust/private:utils.bzl", "dedent", "find_toolchain", "force_panic_unwind_transition", "transform_deps")
load("//rust/private:utils.bzl", "dedent", "find_toolchain", "transform_deps")

def _construct_writer_arguments(ctx, test_runner, opt_test_params, action, crate_info):
"""Construct arguments and environment variables specific to `rustdoc_test_writer`.
Expand Down Expand Up @@ -207,9 +207,6 @@ rust_doc_test = rule(
"""),
providers = [[CrateInfo], [CcInfo]],
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_cc_toolchain": attr.label(
doc = (
"In order to use find_cc_toolchain, your rule has to depend " +
Expand All @@ -232,7 +229,6 @@ rust_doc_test = rule(
),
},
test = True,
cfg = force_panic_unwind_transition,
fragments = ["cpp"],
host_fragments = ["cpp"],
toolchains = [
Expand Down
9 changes: 0 additions & 9 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,3 @@ def _symlink_for_non_generated_source(ctx, src_file, package_root):
return src_symlink
else:
return src_file

def _force_panic_unwind_transition_impl(_settings, _attr):
return {"//:panic_style": "unwind"}

force_panic_unwind_transition = transition(
implementation = _force_panic_unwind_transition_impl,
inputs = [],
outputs = ["//:panic_style"],
)
Loading

0 comments on commit 94b8be0

Please sign in to comment.