move --no-gc-sections
hack to the toolchain definition
Thanks laurynasl for the tip.
This commit is contained in:
parent
9ce21b5276
commit
94d5864cb7
@ -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 = [
|
||||
|
@ -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,27 +32,42 @@ all_compile_actions = [
|
||||
]
|
||||
|
||||
def _zig_cc_toolchain_config_impl(ctx):
|
||||
default_compiler_flags = feature(
|
||||
name = "default_compiler_flags",
|
||||
compiler_flags = [
|
||||
"-I" + d
|
||||
for d in ctx.attr.cxx_builtin_include_directories
|
||||
] + [
|
||||
"-target",
|
||||
ctx.attr.target + ctx.attr.target_suffix,
|
||||
"-no-canonical-prefixes",
|
||||
"-Wno-builtin-macro-redefined",
|
||||
"-D__DATE__=\"redacted\"",
|
||||
"-D__TIMESTAMP__=\"redacted\"",
|
||||
"-D__TIME__=\"redacted\"",
|
||||
]
|
||||
no_gc_sections = ["-Wl,--no-gc-sections"]
|
||||
|
||||
compile_and_link_flags = feature(
|
||||
name = "compile_and_link_flags",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
actions = compile_and_link_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-I" + d
|
||||
for d in ctx.attr.cxx_builtin_include_directories
|
||||
] + [
|
||||
"-target",
|
||||
ctx.attr.target + ctx.attr.target_suffix,
|
||||
"-no-canonical-prefixes",
|
||||
"-Wno-builtin-macro-redefined",
|
||||
"-D__DATE__=\"redacted\"",
|
||||
"-D__TIMESTAMP__=\"redacted\"",
|
||||
"-D__TIME__=\"redacted\"",
|
||||
] + ctx.attr.copts,
|
||||
),
|
||||
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,
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user