Skip to content

Commit

Permalink
start, make built artifacts more reproducible but specifying -ffile-p…
Browse files Browse the repository at this point in the history
…refix-map
  • Loading branch information
ParkMyCar committed Jan 18, 2025
1 parent bb3f7d0 commit 3f7280c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -150,6 +151,8 @@ def cc_toolchain_config(
link_flags = [
"--target=" + target_system_name,
"-no-canonical-prefixes",
# Reproducibility.
"-ffile-prefix-map=${{pwd}}=__bazel_toolchain_llvm_repo__",
]

stdlib = compiler_configuration["stdlib"]
Expand Down
5 changes: 5 additions & 0 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f7280c

Please sign in to comment.