From db4c6a1b5dcd3fe3e0f8c02c1454cc8fbd6f1cd0 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Mon, 1 Aug 2016 17:03:26 +0100 Subject: [helpers] Teach llvm-env to self-host In addition to debug builds, this teaches llvm-env to create self-hosted bots that will use the "build" directory of the branch to compile a self-hosted version of the toolchain. It'll use clang and also lld, if available. Review changes: * Check for clang, not just build dir * Use -x instead of -f * Always export LLVM_SELFHOST * Quote strings for good measure * Using LLVM_CMAKE_FLAGS Change-Id: I55af0c213ae06cb8b99a33d1a80a05f09fe64c85 --- helpers/llvm-build | 2 +- helpers/llvm-env | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'helpers') diff --git a/helpers/llvm-build b/helpers/llvm-build index 5ef0662..d38cf1d 100755 --- a/helpers/llvm-build +++ b/helpers/llvm-build @@ -59,7 +59,7 @@ if [ ! -f build.ninja ] && [ ! -f Makefile ]; then -DLLVM_ENABLE_ASSERTIONS=True \ -DPYTHON_EXECUTABLE=/usr/bin/python2 \ -DCMAKE_INSTALL_PREFIX=$install_dir \ - $targets $shared + $LLVM_CMAKE_FLAGS $targets $shared fi ## Allow the user to override the number of CPUs used with -jN diff --git a/helpers/llvm-env b/helpers/llvm-env index 50c4c81..ba9c98f 100755 --- a/helpers/llvm-env +++ b/helpers/llvm-env @@ -75,6 +75,7 @@ elif [ "$1" = "-h" ]; then echo " it will not clean up any branches (you should use" echo " llvm-branch for that)" echo " -d : build the debug version." + echo " -s : build the self-hosted version (CC is set to /build)." eval $clean_exit fi @@ -100,10 +101,13 @@ if [ "$1" = "-cleanup" ]; then fi debug_build=false +selfhost_build=false OPTIND=0 -while getopts "d" opt; do +while getopts "ds" opt; do if [ "$opt" = "d" ]; then debug_build=true + elif [ "$opt" = "s" ]; then + selfhost_build=true else eval $clean_exit fi @@ -121,6 +125,16 @@ llvm_worktree_dir=$LLVM_ROOT/$branch/llvm llvm_build_dir=$LLVM_ROOT/$branch/build if $debug_build; then llvm_build_dir=$LLVM_ROOT/$branch/debug +elif $selfhost_build; then + if [ ! -d "$llvm_build_dir" ] || \ + [ ! -x "$llvm_build_dir/bin/clang" ] || \ + [ ! -x "$llvm_build_dir/bin/clang++" ]; then + echo "Stage 1 build dir not found at: $llvm_build_dir" + echo "Build stage 1 first, then the self-hosted" + eval $clean_exit + fi + llvm_stage1_dir=$llvm_build_dir + llvm_build_dir=$LLVM_ROOT/$branch/selfhost fi llvm_install_dir=$LLVM_ROOT/$branch/install @@ -149,7 +163,17 @@ fi export LLVM_SRC=$llvm_worktree_dir export LLVM_BLD=$llvm_build_dir export LLVM_INSTALL=$llvm_install_dir -export LLVM_DEBUG=$debug_build # For llvm-build to know +# For llvm-build to know +export LLVM_DEBUG=$debug_build +export LLVM_SELFHOST=$selfhost_build + +# Self-hosted builds need to use the previously built clang, maybe LLD. +if $selfhost_build; then + # Clang will automatically pick LLD if available on the same dir + LLVM_CMAKE_FLAGS="-DCMAKE_C_COMPILER=$llvm_stage1_dir/bin/clang \ + -DCMAKE_CXX_COMPILER=$llvm_stage1_dir/bin/clang++" + export LLVM_CMAKE_FLAGS +fi # Make it possible to undo changes to the PATH: we export an LLVM_OLD_PATH, and # instead of appending the binary dir to $PATH, we append to $LLVM_OLD_PATH (if -- cgit v1.2.3