Skip to content

Add support for parse_headers #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/scripts/bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ common_test_args=(
"--keep_going"
"--test_output=errors"
"--features=layering_check"
"--process_headers_in_dependencies"
)

# Do not run autoconf to configure local CC toolchains.
Expand Down
2 changes: 2 additions & 0 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def cc_toolchain_config(
# https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl;l=75;drc=f0150efd1cca473640269caaf92b5a23c288089d
# https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java;l=1257;drc=6743d76f9ecde726d592e88d8914b9db007b1c43
# https://cs.opensource.google/bazel/bazel/+/refs/tags/7.0.0:tools/cpp/unix_cc_toolchain_config.bzl;l=192,201;drc=044a14cca2747aeff258fc71eaeb153c08cb34d5
# https://github.com/bazelbuild/rules_cc/blob/fe41fc4ea219c9d3680ee536bba6681f3baf838e/cc/private/toolchain/unix_cc_toolchain_config.bzl#L1887
# NOTE: Ensure these are listed in toolchain_tools in toolchain/internal/common.bzl.
tool_paths = {
"ar": tools_path_prefix + ("llvm-ar" if not use_libtool else "libtool"),
Expand All @@ -362,6 +363,7 @@ def cc_toolchain_config(
"objcopy": tools_path_prefix + "llvm-objcopy",
"objdump": tools_path_prefix + "llvm-objdump",
"strip": tools_path_prefix + "llvm-strip",
"parse_headers": wrapper_bin_prefix + "cc_wrapper.sh",
}

# Start-end group linker support:
Expand Down
19 changes: 19 additions & 0 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then
exit 5
fi

OUTPUT=

function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=${opt}
elif [[ "${opt}" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
}

function sanitize_option() {
local -r opt=$1
if [[ ${opt} == */cc_wrapper.sh ]]; then
Expand All @@ -106,6 +118,7 @@ for ((i = 0; i <= $#; i++)); do
set -e
sanitize_option "${opt}"
)"
parse_option "${opt}"
echo "${opt}" >>"${tmpfile}"
done <"${!i:1}"
cmd+=("@${tmpfile}")
Expand All @@ -114,9 +127,15 @@ for ((i = 0; i <= $#; i++)); do
set -e
sanitize_option "${!i}"
)"
parse_option "${opt}"
cmd+=("${opt}")
fi
done

# Call the C++ compiler.
"${cmd[@]}"

# Generate an empty file if header processing succeeded.
if [[ "${OUTPUT}" == *.h.processed ]]; then
echo -n >"${OUTPUT}"
fi
1 change: 1 addition & 0 deletions toolchain/internal/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ cc_toolchain(
strip_files = "strip-files-{suffix}",
toolchain_config = "local-{suffix}",
module_map = "module-{suffix}",
supports_header_parsing = True,
)
"""

Expand Down
5 changes: 5 additions & 0 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ fi
# Call the C++ compiler.
"${cmd[@]}"

# Generate an empty file if header processing succeeded.
if [[ "${OUTPUT}" == *.h.processed ]]; then
echo -n >"${OUTPUT}"
fi

function get_library_path() {
for libdir in ${LIB_DIRS}; do
if [[ -f "${libdir}/lib$1".so ]]; then
Expand Down