Skip to content

Commit

Permalink
Add support for params files for darwin
Browse files Browse the repository at this point in the history
Clang has supported params files for a while now. This updates the cc
toolchain for darwin to use them.

The logic for processing response files is mostly copied from
rules_swift where similar processing is done.
  • Loading branch information
keith committed Oct 22, 2020
1 parent 9327306 commit 97bec0c
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 70 deletions.
12 changes: 0 additions & 12 deletions src/test/shell/integration/aquery_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,6 @@ EOF
}

function test_aquery_include_param_file_cc_binary() {
if is_darwin; then
return 0
fi

local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
cat > "$pkg/BUILD" <<'EOF'
Expand All @@ -737,10 +733,6 @@ EOF
}

function test_aquery_include_param_file_starlark_rule() {
if is_darwin; then
return 0
fi

local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
cat > "$pkg/test_rule.bzl" <<'EOF'
Expand Down Expand Up @@ -791,10 +783,6 @@ EOF
}

function test_aquery_include_param_file_not_enabled_by_default() {
if is_darwin; then
return 0
fi

local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
cat > "$pkg/BUILD" <<'EOF'
Expand Down
2 changes: 1 addition & 1 deletion tools/cpp/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ cc_toolchain(
linker_files = ":osx_wrapper",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
supports_param_files = 1,
toolchain_config = ":local_darwin",
toolchain_identifier = "local_darwin",
)
Expand Down
2 changes: 1 addition & 1 deletion tools/cpp/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cc_toolchain(
linker_files = ":compiler_deps",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = %{supports_param_files},
supports_param_files = 1,
module_map = %{modulemap},
)

Expand Down
27 changes: 20 additions & 7 deletions tools/cpp/osx_cc_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,33 @@ LIBS=
LIB_DIRS=
RPATHS=
OUTPUT=
# let parse the option list
for i in "$@"; do

function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=$i
elif [[ "$i" =~ ^-l(.*)$ ]]; then
OUTPUT=$opt
elif [[ "$opt" =~ ^-l(.*)$ ]]; then
LIBS="${BASH_REMATCH[1]} $LIBS"
elif [[ "$i" =~ ^-L(.*)$ ]]; then
elif [[ "$opt" =~ ^-L(.*)$ ]]; then
LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS"
elif [[ "$i" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
elif [[ "$opt" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ "$i" = "-o" ]]; then
elif [[ "$opt" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
}

# let parse the option list
for i in "$@"; do
if [[ "$i" = @* ]]; then
while IFS= read -r opt
do
parse_option "$opt"
done < "${i:1}" || exit 1
else
parse_option "$i"
fi
done

# Call gcc
Expand Down
27 changes: 20 additions & 7 deletions tools/cpp/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,33 @@ LIBS=
LIB_DIRS=
RPATHS=
OUTPUT=
# let parse the option list
for i in "$@"; do

function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=$i
elif [[ "$i" =~ ^-l(.*)$ ]]; then
OUTPUT=$opt
elif [[ "$opt" =~ ^-l(.*)$ ]]; then
LIBS="${BASH_REMATCH[1]} $LIBS"
elif [[ "$i" =~ ^-L(.*)$ ]]; then
elif [[ "$opt" =~ ^-L(.*)$ ]]; then
LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS"
elif [[ "$i" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
elif [[ "$opt" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ "$i" = "-o" ]]; then
elif [[ "$opt" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
}

# let parse the option list
for i in "$@"; do
if [[ "$i" = @* ]]; then
while IFS= read -r opt
do
parse_option "$opt"
done < "${i:1}" || exit 1
else
parse_option "$i"
fi
done

# Set-up the environment
Expand Down
1 change: 0 additions & 1 deletion tools/cpp/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
"%{cc_toolchain_identifier}": cc_toolchain_identifier,
"%{name}": cpu_value,
"%{modulemap}": ("\":module.modulemap\"" if is_clang else "None"),
"%{supports_param_files}": "0" if darwin else "1",
"%{cc_compiler_deps}": get_starlark_list([":builtin_include_directory_paths"] + (
[":cc_wrapper"] if darwin else []
)),
Expand Down
2 changes: 1 addition & 1 deletion tools/osx/crosstool/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cc_toolchain_suite(
linker_files = ":osx_tools_" + arch,
objcopy_files = ":empty",
strip_files = ":osx_tools_" + arch,
supports_param_files = 0,
supports_param_files = 1,
toolchain_config = ":" + (
arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"
),
Expand Down
19 changes: 10 additions & 9 deletions tools/osx/crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5194,20 +5194,18 @@ def _impl(ctx):
else:
unfiltered_compile_flags_feature = None

do_not_split_linking_cmdline = feature(name = "do_not_split_linking_cmdline")
linker_param_file_feature = feature(
name = "linker_param_file",
flag_sets = [
flag_set(
actions = all_link_actions,
flag_groups = [
flag_group(
flags = ["-Wl,@%{linker_param_file}"],
expand_if_available = "linker_param_file",
),
actions = all_link_actions + [
ACTION_NAMES.cpp_link_static_library,
ACTION_NAMES.objc_archive,
ACTION_NAMES.objc_fully_link,
ACTION_NAMES.objc_executable,
ACTION_NAMES.objcpp_executable,
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = ["@%{linker_param_file}"],
Expand Down Expand Up @@ -6145,6 +6143,7 @@ def _impl(ctx):
user_compile_flags_feature,
unfiltered_compile_flags_feature,
linker_param_file_feature,
do_not_split_linking_cmdline,
compiler_input_flags_feature,
compiler_output_flags_feature,
objcopy_embed_flags_feature,
Expand Down Expand Up @@ -6222,6 +6221,7 @@ def _impl(ctx):
user_compile_flags_feature,
unfiltered_compile_flags_feature,
linker_param_file_feature,
do_not_split_linking_cmdline,
compiler_input_flags_feature,
compiler_output_flags_feature,
supports_dynamic_linker_feature,
Expand Down Expand Up @@ -6299,6 +6299,7 @@ def _impl(ctx):
user_compile_flags_feature,
unfiltered_compile_flags_feature,
linker_param_file_feature,
do_not_split_linking_cmdline,
compiler_input_flags_feature,
compiler_output_flags_feature,
supports_pic_feature,
Expand Down
Loading

0 comments on commit 97bec0c

Please sign in to comment.