summaryrefslogtreecommitdiff
path: root/_setup_env.sh
diff options
context:
space:
mode:
Diffstat (limited to '_setup_env.sh')
-rw-r--r--_setup_env.sh37
1 files changed, 35 insertions, 2 deletions
diff --git a/_setup_env.sh b/_setup_env.sh
index 8a9d7e2a..4bb04330 100644
--- a/_setup_env.sh
+++ b/_setup_env.sh
@@ -131,12 +131,45 @@ if [ "${HERMETIC_TOOLCHAIN:-0}" -eq 1 ]; then
ldflags+="-L ${ROOT_DIR}/prebuilts/kernel-build-tools/linux-x86/lib64 "
# Have host compiler use LLD and compiler-rt.
- ldflags+="-fuse-ld=lld --rtlib=compiler-rt"
+ LLD_COMPILER_RT="-fuse-ld=lld --rtlib=compiler-rt"
+ ldflags+=${LLD_COMPILER_RT}
export HOSTCFLAGS="$sysroot_flags $cflags"
export HOSTLDFLAGS="$sysroot_flags $ldflags"
- export USERCFLAGS="--sysroot=/dev/null"
+ if [[ -n "${NDK_TRIPLE}" ]]; then
+ NDK_DIR=${ROOT_DIR}/prebuilts/ndk-r23
+ if [[ ! -d "${NDK_DIR}" ]]; then
+ # Kleaf/Bazel will checkout the ndk to a different directory than
+ # build.sh.
+ NDK_DIR=${ROOT_DIR}/external/prebuilt_ndk
+ if [[ ! -d "${NDK_DIR}" ]]; then
+ echo "ERROR: NDK_TRIPLE set, but unable to find prebuilts/ndk." 1>&2
+ echo "Did you forget to checkout prebuilts/ndk?" 1>&2
+ exit 1
+ fi
+ fi
+ USERCFLAGS="--target=${NDK_TRIPLE} "
+ USERCFLAGS+="--sysroot=${NDK_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot "
+ # Some kernel headers trigger -Wunused-function for unused static functions
+ # with clang; GCC does not warn about unused static inline functions. The
+ # kernel sets __attribute__((maybe_unused)) on such functions when W=1 is
+ # not set.
+ USERCFLAGS+="-Wno-unused-function "
+ # To help debug these flags, consider commenting back in the following, and
+ # add `echo $@ > /tmp/log.txt` and `2>>/tmp/log.txt` to the invocation of $@
+ # in scripts/cc-can-link.sh.
+ #USERCFLAGS+=" -Wl,--verbose -v"
+ # We need to set -fuse-ld=lld for Android's build env since AOSP LLVM's
+ # clang is not configured to use LLD by default, and BFD has been
+ # intentionally removed. This way CC_CAN_LINK can properly link the test in
+ # scripts/cc-can-link.sh.
+ USERLDFLAGS="${LLD_COMPILER_RT} "
+ USERLDFLAGS+="--target=${NDK_TRIPLE} "
+ else
+ USERCFLAGS="--sysroot=/dev/null"
+ fi
+ export USERCFLAGS USERLDFLAGS
fi
for prebuilt_bin in "${prebuilts_paths[@]}"; do