From 3957d9fae4db22281a99d99e9a065d2a1270505c Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 17:34:07 +0200 Subject: [PATCH 01/10] Add support for `parse_headers` --- toolchain/cc_toolchain_config.bzl | 2 ++ toolchain/cc_wrapper.sh.tpl | 13 +++++++++++++ toolchain/internal/configure.bzl | 1 + toolchain/osx_cc_wrapper.sh.tpl | 13 +++++++++++++ 4 files changed, 29 insertions(+) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 487af000..2107286b 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -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"), @@ -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: diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 16c24eff..fdf9c24e 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -82,8 +82,16 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then exit 5 fi +OUTPUT= + function sanitize_option() { local -r opt=$1 + if [[ "${OUTPUT}" == "1" ]]; then + OUTPUT=${opt} + elif [[ "${opt}" == -o ]]; then + # Output path comes next. + OUTPUT=1 + fi if [[ ${opt} == */cc_wrapper.sh ]]; then printf "%s" "${toolchain_path_prefix}bin/clang" elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]] && [[ ${script_dir} == /* ]]; then @@ -120,3 +128,8 @@ done # Call the C++ compiler. "${cmd[@]}" + +# Generate an empty file if header processing succeeded. +if [[ "${OUTPUT}" == *.h.processed ]]; then + echo -n >"${OUTPUT}" +fi diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 4ce00c51..3467f929 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -531,6 +531,7 @@ cc_toolchain( strip_files = "strip-files-{suffix}", toolchain_config = "local-{suffix}", module_map = "module-{suffix}", + supports_header_parsing = True, ) """ diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 6363eb43..7bb7bf3a 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -119,8 +119,16 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then exit 5 fi +OUTPUT= + function sanitize_option() { local -r opt=$1 + if [[ "${OUTPUT}" == "1" ]]; then + OUTPUT=${opt} + elif [[ "${opt}" == -o ]]; then + # Output path comes next. + OUTPUT=1 + fi if [[ ${opt} == */cc_wrapper.sh ]]; then printf "%s" "${toolchain_path_prefix}bin/clang" elif [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then @@ -183,6 +191,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 From c3ded4e4622c2b7e5685fd67e9f619bd3b2c9205 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 18:07:08 +0200 Subject: [PATCH 02/10] TMP: Debug CI --- tests/scripts/bazel.sh | 3 ++- toolchain/cc_wrapper.sh.tpl | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/scripts/bazel.sh b/tests/scripts/bazel.sh index a7db03c7..c70e06a5 100644 --- a/tests/scripts/bazel.sh +++ b/tests/scripts/bazel.sh @@ -47,9 +47,10 @@ common_test_args=( "--symlink_prefix=/" "--color=yes" "--show_progress_rate_limit=30" - "--keep_going" "--test_output=errors" "--features=layering_check" + "-s" + "--process_headers_in_dependencies" ) # Do not run autoconf to configure local CC toolchains. diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index fdf9c24e..b9efe8de 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -86,12 +86,14 @@ OUTPUT= function sanitize_option() { local -r opt=$1 + set -x if [[ "${OUTPUT}" == "1" ]]; then OUTPUT=${opt} elif [[ "${opt}" == -o ]]; then # Output path comes next. OUTPUT=1 fi + set +x if [[ ${opt} == */cc_wrapper.sh ]]; then printf "%s" "${toolchain_path_prefix}bin/clang" elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]] && [[ ${script_dir} == /* ]]; then @@ -129,6 +131,7 @@ done # Call the C++ compiler. "${cmd[@]}" +set -x # Generate an empty file if header processing succeeded. if [[ "${OUTPUT}" == *.h.processed ]]; then echo -n >"${OUTPUT}" From 5eef359e467403626876e41b0dd7ab67af419155 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:01:10 +0200 Subject: [PATCH 03/10] Update cc_wrapper.sh.tpl --- toolchain/cc_wrapper.sh.tpl | 1 + 1 file changed, 1 insertion(+) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index b9efe8de..77dd68a6 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -85,6 +85,7 @@ fi OUTPUT= function sanitize_option() { + global OUTPUT local -r opt=$1 set -x if [[ "${OUTPUT}" == "1" ]]; then From 931c1f89a46abab933d785a2e447ac8724a20bbc Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:01:49 +0200 Subject: [PATCH 04/10] Update osx_cc_wrapper.sh.tpl --- toolchain/osx_cc_wrapper.sh.tpl | 1 + 1 file changed, 1 insertion(+) diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 7bb7bf3a..214f0b13 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -122,6 +122,7 @@ fi OUTPUT= function sanitize_option() { + global OUTPUT local -r opt=$1 if [[ "${OUTPUT}" == "1" ]]; then OUTPUT=${opt} From 12f65c679a90eeccd81812283e7c96f5a11a61e2 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:12:34 +0200 Subject: [PATCH 05/10] Update osx_cc_wrapper.sh.tpl --- toolchain/osx_cc_wrapper.sh.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 214f0b13..7bb7bf3a 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -122,7 +122,6 @@ fi OUTPUT= function sanitize_option() { - global OUTPUT local -r opt=$1 if [[ "${OUTPUT}" == "1" ]]; then OUTPUT=${opt} From 0a47597cb7fff150dba31406dfaa261d14ca6d06 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:15:42 +0200 Subject: [PATCH 06/10] Update osx_cc_wrapper.sh.tpl --- toolchain/osx_cc_wrapper.sh.tpl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 7bb7bf3a..1ab90a05 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -119,16 +119,8 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then exit 5 fi -OUTPUT= - function sanitize_option() { local -r opt=$1 - if [[ "${OUTPUT}" == "1" ]]; then - OUTPUT=${opt} - elif [[ "${opt}" == -o ]]; then - # Output path comes next. - OUTPUT=1 - fi if [[ ${opt} == */cc_wrapper.sh ]]; then printf "%s" "${toolchain_path_prefix}bin/clang" elif [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then From 8cf1a6b5fc91ca7dba310bcf4910fbe87ea8ce02 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:57:46 +0200 Subject: [PATCH 07/10] Update cc_wrapper.sh.tpl --- toolchain/cc_wrapper.sh.tpl | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 77dd68a6..6f1faf28 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -82,19 +82,8 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then exit 5 fi -OUTPUT= - function sanitize_option() { - global OUTPUT local -r opt=$1 - set -x - if [[ "${OUTPUT}" == "1" ]]; then - OUTPUT=${opt} - elif [[ "${opt}" == -o ]]; then - # Output path comes next. - OUTPUT=1 - fi - set +x if [[ ${opt} == */cc_wrapper.sh ]]; then printf "%s" "${toolchain_path_prefix}bin/clang" elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]] && [[ ${script_dir} == /* ]]; then @@ -132,7 +121,6 @@ done # Call the C++ compiler. "${cmd[@]}" -set -x # Generate an empty file if header processing succeeded. if [[ "${OUTPUT}" == *.h.processed ]]; then echo -n >"${OUTPUT}" From 057553996ae83d562ceb2cc41bb94f9a071ab9d8 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 19:59:25 +0200 Subject: [PATCH 08/10] Update cc_wrapper.sh.tpl --- toolchain/cc_wrapper.sh.tpl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 6f1faf28..55f75498 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -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 @@ -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}") @@ -114,6 +127,7 @@ for ((i = 0; i <= $#; i++)); do set -e sanitize_option "${!i}" )" + parse_option "${opt}" cmd+=("${opt}") fi done From 72e6124c510d7ff3569453039c1ef0e4ae05849c Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 20:02:49 +0200 Subject: [PATCH 09/10] Update cc_wrapper.sh.tpl --- toolchain/cc_wrapper.sh.tpl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 55f75498..8a23f121 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -85,13 +85,13 @@ 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 + local -r opt="$1" + if [[ "${OUTPUT}" = "1" ]]; then + OUTPUT=${opt} + elif [[ "${opt}" = "-o" ]]; then + # output is coming + OUTPUT=1 + fi } function sanitize_option() { From 46e5f70d45552eb7251cf4af51437c041ceba644 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sun, 6 Jul 2025 20:04:00 +0200 Subject: [PATCH 10/10] Update bazel.sh --- tests/scripts/bazel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/bazel.sh b/tests/scripts/bazel.sh index c70e06a5..ed498b92 100644 --- a/tests/scripts/bazel.sh +++ b/tests/scripts/bazel.sh @@ -47,9 +47,9 @@ common_test_args=( "--symlink_prefix=/" "--color=yes" "--show_progress_rate_limit=30" + "--keep_going" "--test_output=errors" "--features=layering_check" - "-s" "--process_headers_in_dependencies" )