diff options
author | Zach Yu <zachyu@google.com> | 2023-07-07 13:25:39 -0700 |
---|---|---|
committer | Zach Yu <zachyu@google.com> | 2023-07-07 13:25:39 -0700 |
commit | 82363d90fdca800d71831cda0409bd0e0d5724f0 (patch) | |
tree | 345fe6584d7f0273cd07afd0f162852d52a629c8 /toolchains/cc/mac_clang | |
parent | a20c893266723576f22a54f467549f13c1dac7bd (diff) | |
download | bazel-82363d90fdca800d71831cda0409bd0e0d5724f0.tar.gz |
Add opt and dbg features.emu-33-dev
This enables build modes with different flags. To make it consistent
with current emulator builds, debug symbols are being generated in all
modes (enabled in bazelrc).
Change-Id: Ic7e2130b5043c107a1bcc3e9d25708908eecd407
Diffstat (limited to 'toolchains/cc/mac_clang')
-rw-r--r-- | toolchains/cc/mac_clang/features.bzl | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/toolchains/cc/mac_clang/features.bzl b/toolchains/cc/mac_clang/features.bzl index 934bd074..c45228f1 100644 --- a/toolchains/cc/mac_clang/features.bzl +++ b/toolchains/cc/mac_clang/features.bzl @@ -14,6 +14,8 @@ load( load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load( "@//build/bazel/toolchains/cc:actions.bzl", + "CPP_COMPILE_ACTIONS", + "C_COMPILE_ACTIONS", "LINK_ACTIONS", ) load( @@ -44,7 +46,9 @@ load( "archiver_flags_feature", "compiler_input_feature", "compiler_output_feature", + "dbg_feature", "dependency_file_feature", + "generate_debug_symbols_feature", "get_toolchain_include_paths_feature", "get_toolchain_lib_search_paths_feature", "get_toolchain_libraries_to_link_feature", @@ -78,8 +82,7 @@ rpath_feature = feature( ], ), ], - expand_if_available = - "runtime_library_search_directories", + expand_if_available = "runtime_library_search_directories", ), ], ), @@ -239,7 +242,6 @@ force_pic_feature = feature( flag_groups = [ flag_group( expand_if_available = "force_pic", - iterate_over = "user_link_flags", flags = ["-Wl,-pie"], ), ], @@ -247,6 +249,38 @@ force_pic_feature = feature( ], ) +opt_feature = feature( + name = "opt", + flag_sets = [ + flag_set( + actions = C_COMPILE_ACTIONS + CPP_COMPILE_ACTIONS, + flag_groups = [ + flag_group(flags = [ + "-O2", + # Buffer overrun detection. + "-D_FORTIFY_SOURCE=1", + # Disable assertions + "-DNDEBUG", + # Allow removal of unused sections at link time. + "-ffunction-sections", + "-fdata-sections", + # Needed by --icf=safe + "-faddrsig", + ]), + ], + ), + flag_set( + actions = LINK_ACTIONS, + flag_groups = [ + flag_group(flags = [ + "-Wl,-dead_strip", + "-Wl,--icf=safe", + ]), + ], + ), + ], +) + def _cc_features_impl(ctx): import_config = toolchain_import_configs( ctx.attr.toolchain_imports, @@ -277,15 +311,21 @@ def _cc_features_impl(ctx): lib_search_paths_feature, get_toolchain_lib_search_paths_feature(import_config), archiver_flags_feature, + generate_debug_symbols_feature, + # Start flag ordering: the order of following features impacts how + # flags override each other. + opt_feature, + dbg_feature, libraries_to_link_feature, - get_toolchain_libraries_to_link_feature(import_config), - force_pic_feature, get_toolchain_link_flags_feature(ctx.attr.link_flags), user_link_flags_feature, + get_toolchain_libraries_to_link_feature(import_config), + force_pic_feature, strip_debug_symbols_feature, get_toolchain_compile_flags_feature(ctx.attr.compile_flags), get_toolchain_cxx_flags_feature(ctx.attr.cxx_flags), user_compile_flags_feature, + ### End flag ordering ## sysroot_feature, linker_param_file_feature, compiler_input_feature, |