diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 9dbb41db..db76e424 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -113,11 +113,12 @@ def cc_toolchain_config( unfiltered_compile_flags = [ # Do not resolve our symlinked resource prefixes to real paths. "-no-canonical-prefixes", - # Reproducibility + # Reproducibility. "-Wno-builtin-macro-redefined", "-D__DATE__=\"redacted\"", "-D__TIMESTAMP__=\"redacted\"", "-D__TIME__=\"redacted\"", + "-ffile-prefix-map=${{pwd}}=__bazel_toolchain_llvm_repo__", ] is_xcompile = not (exec_os == target_os and exec_arch == target_arch) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index e972d57e..74b36a63 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -34,12 +34,14 @@ set -euo pipefail if [[ -f %{toolchain_path_prefix}bin/clang ]]; then execroot_path="" + execroot_abs_path="${PWD}/" elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then # Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc) # change CWD and call $CC (this script) with its absolute path. # For cases like this, we'll try to find `clang` through an absolute path. # This script is at _execroot_/external/_repo_name_/bin/cc_wrapper.sh execroot_path="${BASH_SOURCE[0]%/*/*/*/*}/" + execroot_abs_path="$(cd "${execroot_path}" && pwd -P)/" else echo >&2 "ERROR: could not find clang; PWD=\"${PWD}\"; PATH=\"${PATH}\"." exit 5 @@ -53,6 +55,9 @@ function sanitize_option() { # shellcheck disable=SC2206 parts=(${opt/=/ }) # Split flag name and value into array. printf "%s" "${parts[0]}=${execroot_path}${parts[1]}" + elif [[ ${opt} == *"\${{pwd}}"* ]]; then + # Replace the literal string '${{pwd}}' with the execroot. + printf "%s" "${opt//\$\{\{pwd\}\}/${execroot_abs_path%/}}" else printf "%s" "${opt}" fi diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 31122784..9c1ec4bf 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -79,6 +79,9 @@ function sanitize_option() { # shellcheck disable=SC2206 parts=(${opt/=/ }) # Split flag name and value into array. printf "%s" "${parts[0]}=${execroot_path}${parts[1]}" + elif [[ ${opt} == *"\${{pwd}}"* ]]; then + # Replace the literal string '${{pwd}}' with the execroot. + printf "%s" "${opt//\$\{\{pwd\}\}/${execroot_abs_path%/}}" else printf "%s" "${opt}" fi