summaryrefslogtreecommitdiff
path: root/_setup_env.sh
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2022-03-21 09:56:38 -0700
committerNick Desaulniers <ndesaulniers@google.com>2022-04-05 21:10:18 +0000
commit66e4dc49470ed1412a596050fdc1f1950de80ca5 (patch)
tree5361195f601a34f1ca2b40a0891c30f601e31102 /_setup_env.sh
parentf874ab318c40d39d052f9902430a2b332002919d (diff)
downloadbuild-66e4dc49470ed1412a596050fdc1f1950de80ca5.tar.gz
_setup_env: support Bionic sysroot for USERCFLAGS
This is necessary to support CONFIG_UAPI_HEADER_TEST=y in a build environment which does not have a cross compiled version of glibc. Instead, we will use Bionic. This requires setting the correct path to the prebuilt Bionic headers and libraries via --sysroot, and using the correct --target= triple, which differs from what we generally use to cross compile the kernel itself (which doesn't require a libc). Bug: 190019968 Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Change-Id: Iac98c377f516ea642cc605ab6d6d3fd022cb20d4
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 8a9d7e2..4bb0433 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