1

move --no-gc-sections hack to the toolchain definition

Thanks laurynasl for the tip.
This commit is contained in:
Motiejus Jakštys 2022-05-05 14:36:36 +03:00
parent 9ce21b5276
commit 94d5864cb7
2 changed files with 44 additions and 52 deletions

View File

@ -78,33 +78,7 @@ fi
export ZIG_LOCAL_CACHE_DIR="$_cache_prefix/bazel-zig-cc"
export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR
lookup_args=()
add_arg=
case "{zig_tool}" in
cc|c++)
lookup_args=("-Wl,--gc-sections" "-Wl,--no-gc-sections")
add_arg="-Wl,--no-gc-sections"
;;
ld.lld)
lookup_args=("--gc-sections" "--no-gc-sections")
add_arg="--no-gc-sections"
;;
esac
has_special_arg=0
for arg in "${{lookup_args[@]}}"; do
if [[ " ${{args[*]}} " == *" $arg "* ]]; then
has_special_arg=1
break
fi
done
args=( "$@" )
if [[ "$has_special_arg" == 0 ]]; then
args+=( "$add_arg" )
fi
exec "{zig}" "{zig_tool}" "${{args[@]}}"
exec "{zig}" "{zig_tool}" "$@"
"""
_ZIG_TOOLS = [

View File

@ -14,12 +14,15 @@ all_link_actions = [
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]
all_compile_actions = [
ACTION_NAMES.assemble,
compile_and_link_actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
]
rest_compile_actions = [
ACTION_NAMES.assemble,
ACTION_NAMES.cc_flags_make_variable,
ACTION_NAMES.clif_match,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_codegen,
ACTION_NAMES.cpp_module_compile,
@ -29,15 +32,7 @@ all_compile_actions = [
]
def _zig_cc_toolchain_config_impl(ctx):
default_compiler_flags = feature(
name = "default_compiler_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
compiler_flags = [
"-I" + d
for d in ctx.attr.cxx_builtin_include_directories
] + [
@ -48,9 +43,32 @@ def _zig_cc_toolchain_config_impl(ctx):
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
] + ctx.attr.copts,
]
no_gc_sections = ["-Wl,--no-gc-sections"]
compile_and_link_flags = feature(
name = "compile_and_link_flags",
enabled = True,
flag_sets = [
flag_set(
actions = compile_and_link_actions,
flag_groups = [
flag_group(flags = no_gc_sections),
flag_group(flags = compiler_flags + ctx.attr.copts),
],
),
],
)
rest_compile_flags = feature(
name = "rest_compile_flags",
enabled = True,
flag_sets = [
flag_set(
actions = rest_compile_actions,
flag_groups = [
flag_group(flags = compiler_flags + ctx.attr.copts),
],
),
],
)
@ -63,10 +81,9 @@ def _zig_cc_toolchain_config_impl(ctx):
actions = all_link_actions,
flag_groups = ([
flag_group(
flags = [
"-target",
ctx.attr.target,
] + ctx.attr.linkopts,
flags = ["-target", ctx.attr.target] +
no_gc_sections +
ctx.attr.linkopts,
),
]),
),
@ -74,7 +91,8 @@ def _zig_cc_toolchain_config_impl(ctx):
)
features = [
default_compiler_flags,
compile_and_link_flags,
rest_compile_flags,
default_linker_flags,
]