Skip to content

Commit 2da3afb

Browse files
committed
llvm_toolchain: fixes for using/running the toolchain from other locations in the execroot
As the message within explains, `rules_foreign_cc` will use a different PWD than the execroot root for cmake targets which breaks the wrapper script. This commit has the wrapper script search alongside itself for `clang` when it isn't in the usual places.
1 parent b71147e commit 2da3afb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

toolchain/cc_wrapper.sh.tpl

+12-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,19 @@ done
5656
if [[ "${PATH}:" == *"%{toolchain_path_prefix}bin:"* ]]; then
5757
# GoCompile sets the PATH to the directory containing the linker, and changes CWD.
5858
clang "$@"
59-
else
59+
elif [[ -f %{toolchain_path_prefix}bin/clang ]]; then
6060
%{toolchain_path_prefix}bin/clang "$@"
61+
else
62+
# Some consumers of `CcToolchainConfigInfo`s will use a PWD that *isn't*
63+
# the execroot (i.e. `cmake` from `rules_foreign_cc`). For cases like this,
64+
# we'll try to find `clang` by assuming it's next to this script.
65+
potential_clang_path="$(dirname "${0}")/clang"
66+
if [[ -f ${potential_clang_path} ]]; then
67+
"${potential_clang_path}" "${@}"
68+
else
69+
echo "ERROR: could not find clang; PWD is: $(pwd)."
70+
exit 5
71+
fi
6172
fi
6273

6374
function get_library_path() {

0 commit comments

Comments
 (0)