Skip to content

Commit

Permalink
support selectively disabling NS_BLOCK_ASSERTIONS for opt builds (#341)
Browse files Browse the repository at this point in the history
maintains the default behavior of passing `-DNS_BLOCK_ASSERTIONS=1` for
opt builds. for builds where this is undesirable, set
`--features=-ns_block_assertions` to unconditionally not-set this flag,
without having to unset the entire `default_compile_flags` feature.
  • Loading branch information
aaronsky authored Aug 12, 2024
1 parent 4cd9e15 commit 691a7b1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
27 changes: 26 additions & 1 deletion crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,6 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
"-g0",
"-O2",
"-DNDEBUG",
"-DNS_BLOCK_ASSERTIONS=1",
],
),
],
Expand Down Expand Up @@ -2116,6 +2115,31 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
],
)

ns_block_assertions_feature = feature(
name = "ns_block_assertions",
enabled = True,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
ACTION_NAMES.lto_backend,
ACTION_NAMES.clif_match,
ACTION_NAMES.objc_compile,
ACTION_NAMES.objcpp_compile,
],
flag_groups = [flag_group(flags = ["-DNS_BLOCK_ASSERTIONS=1"])],
with_features = [with_feature_set(features = ["opt"])],
),
],
)

objcopy_embed_flags_feature = feature(
name = "objcopy_embed_flags",
enabled = True,
Expand Down Expand Up @@ -2656,6 +2680,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
# Features with more configuration
link_libcpp_feature,
default_compile_flags_feature,
ns_block_assertions_feature,
debug_prefix_map_pwd_is_dot_feature,
remap_xcode_path_feature,
generate_dsym_file_feature,
Expand Down
39 changes: 39 additions & 0 deletions test/compiling_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ load(

default_test = make_action_command_line_test_rule()

opt_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:compilation_mode": "opt",
},
)

disable_ns_block_assertions_feature_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:compilation_mode": "opt",
"//command_line_option:features": [
"-ns_block_assertions",
],
},
)

def compiling_test_suite(name):
"""Tests for compilation behavior.
Expand All @@ -26,6 +41,30 @@ def compiling_test_suite(name):
target_under_test = "//test/test_data:cc_main",
)

opt_test(
name = "{}_opt_link_test".format(name),
tags = [name],
expected_argv = [
"-DNDEBUG",
"-DNS_BLOCK_ASSERTIONS=1",
],
mnemonic = "CppCompile",
target_under_test = "//test/test_data:cc_main",
)

disable_ns_block_assertions_feature_test(
name = "{}_disable_ns_block_assertions_feature_test".format(name),
tags = [name],
expected_argv = [
"-DNDEBUG",
],
not_expected_argv = [
"-DNS_BLOCK_ASSERTIONS=1",
],
mnemonic = "CppCompile",
target_under_test = "//test/test_data:cc_main",
)

native.test_suite(
name = name,
tags = [name],
Expand Down

0 comments on commit 691a7b1

Please sign in to comment.