Skip to content

Commit

Permalink
Generate ccache wrapper scripts instead of symlink (#39)
Browse files Browse the repository at this point in the history
Tested with Bazel 5.2. It is a workaround for issue
bazelbuild/rules_cc#130
  • Loading branch information
chenhao94 authored Jun 11, 2022
1 parent 1f4ae16 commit fee58b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scripts/codebase_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export CRIS_CODE_DIRS="$(sed 's/^[[:space:]]*//' <<< "
" | grep '[^[:space:]]')"

function bazel_common_all () {
bazel "$@" '//...'
# Need to set PATH instead of CC because Bazel does not like '/'s in the CC value.
PATH="$(dirname "$CC"):$PATH" CC="$(basename "$CC")" bazel "$@" '//...'
}
18 changes: 14 additions & 4 deletions scripts/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ pushd "$(dirname "$0")/.."
if which ccache >/dev/null 2>&1 && ([ -d 'run' ] && [ -w 'run' ] || [ -w '.' ]); then
rm -rf 'run/toolchain'
mkdir -p 'run/toolchain'
ln -sf "$(which ccache)" "run/toolchain/$CC"
ln -sf "$(which ccache)" "run/toolchain/$CXX"
export CC="$( realpath -e "run/toolchain")/$CC"
export CXX="$(realpath -e "run/toolchain")/$CXX"
CR_CCACHE_CC_DIR="$(realpath -e "run/toolchain")"

for compiler_varname in "CC"; do
compiler="$(eval echo "\$$compiler_varname")"
ccache_wrapper="$CR_CCACHE_CC_DIR/$(basename "$compiler")"
# Bazel may dereference the ccache symlink, so we use wrapper scripts instead.
# See https://github.com/bazelbuild/rules_cc/issues/130
cat << ____________EOF | sed 's/^ //' > "$ccache_wrapper"
#!/bin/bash
'$(which ccache)' '$(which "$compiler")' "\$@"
____________EOF
chmod +x "$ccache_wrapper"
eval "export $compiler_varname='$ccache_wrapper'"
done
fi

popd

0 comments on commit fee58b9

Please sign in to comment.