toolchain: Fallback on a single stage toolchain without LTO

This commit is contained in:
Sameer Rahmani 2023-03-07 11:47:04 +00:00
parent a8e938eab2
commit a8d8de611a
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
7 changed files with 121 additions and 840 deletions

View File

@ -59,8 +59,8 @@ source "$ME/scripts/devfs.sh"
# during the build process of Serene, these dependencies must be present but
# the builder script will not build them as part of the build process. They
# can be built using the `builder deps` subcommand.
LLVM_VERSION="fa66e4bd9315d20990c86ef57c7901b6dc71bd02"
IWUY_VERSION="435ad9d35ceee7759ea8f8fd658579e979ee5146"
LLVM_VERSION="9fda8322243168cbfcb78c4cf80afa838473a573"
IWYU_VERSION="435ad9d35ceee7759ea8f8fd658579e979ee5146"
BDWGC_VERSION="release-8_2"
MUSL_VERSION="v1.2.3"
# We need this version to use it with our ldd when creating the toolchain
@ -69,7 +69,7 @@ LLVM_MAJOR_VERSION="17"
# The target architectures that we want to build Serene in and also we want
# serene to support. We use this variable when we're building the llvm
TARGET_ARCHS="X86;AArch64;AMDGPU;ARM;RISCV;WebAssembly"
export TARGET_ARCHS LLVM_MAJOR_VERSION MUSL_VERSION BDWGC_VERSION IWUY_VERSION \
export TARGET_ARCHS LLVM_MAJOR_VERSION MUSL_VERSION BDWGC_VERSION IWYU_VERSION \
LLVM_VERSION
# -----------------------------------------------------------------------------
# CONFIG VARS
@ -88,7 +88,7 @@ if [[ "$CXX" = "" ]]; then
fi
# The repository to push/pull packages to/from.
DEV_HEROES="https://beta.devheroes.codes"
DEV_HEROES="https://devheroes.codes"
BUILD_DIR_NAME="build"
export BUILD_DIR_NAME

View File

@ -15,9 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file sets up a CMakeCache for a LLVM toolchain build
set(CMAKE_CXX_STANDARD 17)
#Enable LLVM projects and runtimes
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;lldb;mlir" CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
# Distributions should never be built using the BUILD_SHARED_LIBS CMake option.
@ -26,40 +27,18 @@ set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
# duplicated across shared libraries resulting in bugs. As such this is not a
# safe way to distribute LLVM or LLVM-based tools.
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
#set(LLVM_USE_STATIC_ZSTD ON CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")
# Enable libc++
set(LLVM_ENABLE_LIBCXX OFF CACHE BOOL "")
#set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
#set(LLVM_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_BUILD_LLVM_DYLIB OFF CACHE BOOL "")
set(LLVM_ENABLE_EH ON CACHE BOOL "")
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
set(LLVM_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-gnu CACHE STRING "")
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-gnu CACHE STRING "")
set(LLVM_HOST_TRIPLE x86_64-unknown-linux-gnu CACHE STRING "")
set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 17)
# set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
# set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
# set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
# set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
# set(COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
# set(COMPILER_RT_CAN_EXECUTE_TESTS OFF CACHE BOOL "")
# set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS OFF CACHE BOOL "")
set(COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
# This option causes a weird error with the build system that misjudge the
# arch to elf32-i386
#set(COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "")
# Create the builtin libs of compiler-rt
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
@ -81,37 +60,24 @@ set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL
"Build libc++abi with definitions for operator new/delete. These are normally
defined in libc++abi, but it is also possible to define them in libc++, in
which case the definition in libc++abi should be turned off.")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL " ")
set(LIBCXX_HAS_GCC_LIB OFF CACHE BOOL "")
set(LIBCXX_ENABLE_EXCEPTIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_RTTI ON CACHE BOOL "")
set(LIBCXX_ENABLE_THREADS ON CACHE BOOL "")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
#set(LIBUNWIND_ENABLE_CROSS_UNWINDING ON CACHE BOOL "")
set(LLVM_EXTERNAL_PROJECTS iwyu ON CACHE STRING "")
# Only build the native target in stage1 since it is a throwaway build.
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD ${TARGET_ARCHS} CACHE STRING "")
# Optimize the stage1 compiler, but don't LTO it because that wastes time.
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
# Setup vendor-specific settings.
# set(PACKAGE_VENDOR serene-lang.org CACHE STRING "")
# TODO: Turn this on for the final build
# Setting up the stage2 LTO option needs to be done on the stage1 build so that
# the proper LTO library dependencies can be connected.
set(LLVM_ENABLE_LTO OFF CACHE BOOL "")
#set(LLVM_ENABLE_LTO OFF CACHE BOOL "")
# Since LLVM_ENABLE_LTO is ON we need a LTO capable linker
set(LLVM_ENABLE_LLD ON CACHE BOOL "")
# include(ExternalProject)
# ExternalProject_Add(musl
# GIT_REPOSITORY ${MUSL_REPO}
# GIT_TAG ${MUSL_VERSION}
# GIT_SHALLOW ON
# CONFIGURE_COMMAND "./configure" "--prefix=${}"
# )

View File

@ -1,38 +0,0 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(triple x86_64-unknown-linux-gnu)
set(CMAKE_C_COMPILER "${SERENE_TOOLCHAIN_PATH}/bin/clang")
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER "${SERENE_TOOLCHAIN_PATH}/bin/clang++")
set(CMAKE_CXX_COMPILER_TARGET ${triple})
# where is the target environment located
set(CMAKE_FIND_ROOT_PATH "${SERENE_TOOLCHAIN_PATH}")
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
message(">>>> ${CMAKE_C_COMPILER} -- ${SERENE_TOOLCHAIN_PATH}")

View File

@ -1,74 +0,0 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file sets up a CMakeCache for a LLVM toolchain build
set(BOOTSTRAP_CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
#Enable LLVM projects and runtimes
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
# Optimize the stage1 compiler, but don't LTO it because that wastes time.
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
# Setup vendor-specific settings.
set(PACKAGE_VENDOR serene-lang.org CACHE STRING "")
# Setting up the stage2 LTO option needs to be done on the stage1 build so that
# the proper LTO library dependencies can be connected.
set(BOOTSTRAP_LLVM_ENABLE_LTO OFF CACHE BOOL "")
set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 17)
# Expose stage2 targets through the stage1 build configuration.
set(CLANG_BOOTSTRAP_TARGETS
check-all
check-llvm
check-clang
llvm-config
test-suite
test-depends
llvm-test-depends
clang-test-depends
distribution
install-distribution
install-clang
clang CACHE STRING "")
# Setup the bootstrap build.
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
if(STAGE2_CACHE_FILE)
set(CLANG_BOOTSTRAP_CMAKE_ARGS
-C ${STAGE2_CACHE_FILE}
CACHE STRING "")
else()
set(CLANG_BOOTSTRAP_CMAKE_ARGS
-C ${CMAKE_CURRENT_LIST_DIR}/stage2.cmake
CACHE STRING "")
endif()

View File

@ -1,59 +0,0 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file sets up a CMakeCache for a LLVM toolchain build
# This file sets up a CMakeCache for the second stage of the toolchain
# bootstrap build.
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
set(CMAKE_CXX_STANDARD 17)
# setup toolchain
set(LLVM_INSTALL_TOOLCHAIN_ONLY OFF CACHE BOOL "")
set(LLVM_TOOLCHAIN_TOOLS
dsymutil
llvm-cov
llvm-dwarfdump
llvm-profdata
llvm-objdump
llvm-nm
llvm-size
libclang
CACHE STRING "")
set(LLVM_DISTRIBUTION_COMPONENTS
clang
LTO
clang-format
clang-resource-headers
builtins
libclang
runtimes
${LLVM_TOOLCHAIN_TOOLS}
CACHE STRING "")

View File

@ -1,111 +0,0 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file sets up a CMakeCache for a LLVM toolchain build
#Enable LLVM projects and runtimes
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
# Distributions should never be built using the BUILD_SHARED_LIBS CMake option.
# That option exists for optimizing developer workflow only. Due to design and
# implementation decisions, LLVM relies on global data which can end up being
# duplicated across shared libraries resulting in bugs. As such this is not a
# safe way to distribute LLVM or LLVM-based tools.
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
# Enable libc++
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
set(LLVM_STATIC_LINK_CXX_STDLIB OFF CACHE BOOL "")
set(LLVM_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_BUILD_LLVM_DYLIB OFF CACHE BOOL "")
# This option causes a weird error with the build system that misjudge the
# arch to elf32-i386
#set(COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LLVM_ENABLE_EH ON CACHE BOOL "")
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
set(LLVM_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-musl CACHE STRING "")
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-musl CACHE STRING "")
set(LLVM_HOST_TRIPLE x86_64-pc-linux-gnu CACHE STRING "")
set(LLVM_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-musl CACHE STRING "")
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE x86_64-pc-linux-musl CACHE STRING "")
set(LLVM_HOST_TRIPLE x86_64-pc-linux-musl CACHE STRING "")
set(LLVM_RUNTIME_TARGETS x86_64-pc-linux-gnu CACHE STRING "")
set(COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
# Create the builtin libs of compiler-rt
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
set(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC OFF CACHE BOOL "")
set(COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
set(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN OFF CACHE BOOL "")
set(COMPILER_RT_STATIC_CXX_LIBRARY ON CACHE BOOL "")
set(COMPILER_RT_CXX_LIBRARY "libcxx" CACHE STRING "")
set(COMPILER_RT_USE_LIBCXX ON CACHE BOOL "Enable compiler-rt to use libc++ from the source tree")
set(LIBUNWIND_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE BOOL "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(CLANG_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXX_HAS_GCC_LIB OFF CACHE BOOL "")
set(LIBCXX_HAS_MUSL_LIBC ON CACHE BOOL "")
set(CLANG_DEFAULT_CXX_STDLIB "libc++" CACHE STRING "")
set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
#set(LIBUNWIND_ENABLE_CROSS_UNWINDING ON CACHE BOOL "")
# Only build the native target in stage1 since it is a throwaway build.
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
# Optimize the stage1 compiler, but don't LTO it because that wastes time.
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
# Setup vendor-specific settings.
# set(PACKAGE_VENDOR serene-lang.org CACHE STRING "")
# TODO: Turn this on for the final build
# Setting up the stage2 LTO option needs to be done on the stage1 build so that
# the proper LTO library dependencies can be connected.
set(LLVM_ENABLE_LTO OFF CACHE BOOL "")
# Since LLVM_ENABLE_LTO is ON we need a LTO capable linker
set(LLVM_ENABLE_LLD ON CACHE BOOL "")
# project(dummy CXX)
# include(CheckLinkerFlag)
# check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
# if(NOT CXX_LINKER_SUPPORTS_STDLIB)
# message(FATAL_ERROR "hnthnthnt")
# else()
# message(FATAL_ERROR "eeeeEeeeeeeehnthnthnt ${}")
# endif()
# set(CMAKE_COMPILE_WARNING_AS_ERROR ON CACHE BOOL "")

View File

@ -22,13 +22,6 @@
# portable llvm toolchain
LLVM_DIR_NAME="llvm"
LLVM_BUILD_DIR="$DEPS_BUILD_DIR/${LLVM_DIR_NAME}_build"
MUSL_DIR_NAME="musl"
STAGE0_DIR="$DEPS_BUILD_DIR/stage0.$LLVM_VERSION.$MUSL_VERSION"
STAGE1_DIR="$DEPS_BUILD_DIR/stage1.$LLVM_VERSION.$MUSL_VERSION"
STAGE2_DIR="$DEPS_BUILD_DIR/stage2.$LLVM_VERSION.$MUSL_VERSION"
STAGE2_TC_DIR="$DEPS_BUILD_DIR/stage2_tc.$LLVM_VERSION.$MUSL_VERSION"
DOCKER_IMAGE="serene/toolchain-base"
DOCKER_TAG="latest"
@ -43,17 +36,23 @@ function run_in_container() {
"$@"
}
function build_toolchain_stage0() {
local version repo src stage1 old_path install_dir build_dir
function build_llvm() {
local version repo src install_dir build_dir
version="$LLVM_VERSION"
repo="${LLVM_REPO:-https://github.com/llvm/llvm-project.git}"
src="$DEPS_SOURCE_DIR/$LLVM_DIR_NAME.$version"
install_dir="$STAGE0_DIR"
build_dir="$DEPS_BUILD_DIR/${LLVM_DIR_NAME}_build.stage0.$version"
install_dir="$DEPS_BUILD_DIR/llvm.$LLVM_VERSION"
build_dir="$DEPS_BUILD_DIR/${LLVM_DIR_NAME}_build.$version"
clone_dep "$repo" "$version" "$src"
local iwyu_src iwyu_repo
iwyu_src="$DEPS_SOURCE_DIR/iwyu.$IWYU_VERSION"
iwyu_repo="${IWYU_REPO:-https://github.com/include-what-you-use/include-what-you-use.git}"
clone_dep "$iwyu_repo" "$IWYU_VERSION" "$iwyu_src"
info "Building the stage0 toolchain version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "A build dir for 'toolchain' already exists at '$build_dir'"
@ -64,502 +63,127 @@ function build_toolchain_stage0() {
_push "$build_dir"
export CFLAGS=' -g -g1 ' # -nodefaultlibs -nostdlibs -nostdinc++ -nostdlib++
export CXXFLAGS="$CFLAGS"
#export LDFLAGS="-lc -lc++"
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$install_dir" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-C "$ME/cmake/toolchains/stage1.standalone.cmake" \
-S "$src/llvm"
cmake --build . --parallel
# ninja stage2-distribution
# ninja stage2-install
# ninja stage2-install-distribution
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -P cmake_install.cmake
unset CC
unset CXX
_pop
info "Stage0 toolchain build is ready at '$install_dir'"
}
function build_musl_stage1() {
local version repo src build_dir install_dir old_path stage1
version="$MUSL_VERSION"
install_dir="$DEPS_BUILD_DIR/musl.stage1.$version"
#install_dir="$STAGE1_DIR.tmp"
build_dir="$DEPS_BUILD_DIR/${MUSL_DIR_NAME}_build.stage1.$version"
repo="${MUSL_REPO:-git://git.musl-libc.org/musl}"
src="$DEPS_SOURCE_DIR/$MUSL_DIR_NAME.$version"
clone_dep "$repo" "$version" "$src"
info "Building the stage2 musl version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "A build dir for 'musl' already exists at '$build_dir'"
warn "Cleaning up..."
rm -rf "$build_dir"
fi
info "Copy the source to the build directory at: '$build_dir'"
cp -r "$src" "$build_dir"
mkdir -p "$install_dir"
_push "$build_dir"
old_path="$PATH"
PATH="$STAGE0_DIR/bin:$PATH"
CC=$(which clang)
CXX=$(which clang++)
LDFLAGS="-fuse-ld=lld"
export CC CXX LDFLAGS PATH LDFLAGS
./configure --prefix="$install_dir"
make -j "$(nproc)"
make install
ln -sv "$install_dir/lib/libc.so" "$install_dir/lib/ld-musl-$(uname -m).so.1"
# Create a symlink that can be used to print
# the required shared objects of a program or
# shared object
# ln -sv "$install_dir/lib/libc.so" "$install_dir/bin/ldd"
# # Configure the dynamic linker
# mkdir -p "$install_dir/etc"
# {
# echo "/usr/lib/gcc/x86_64-pc-linux-gnu/12"
# echo "/usr/lib/gcc/x86_64-pc-linux-gnu/11"
# echo "/usr/lib64/"
# echo "/usr/lib/"
# echo "$STAGE0_DIR/lib/clang/$LLVM_MAJOR_VERSION/lib/x86_64-unknown-linux-gnu"
# echo "$STAGE0_DIR/lib/x86_64-unknown-linux-gnu"
# echo "$install_dir/lib"
# echo "$install_dir/x86_64-unknown-linux-gnu/lib"
# echo "$install_dir/usr/lib64"
# echo "$install_dir/lib64"
# echo "$install_dir/usr/lib"
# echo "$STAGE0_DIR/lib"
# echo "$STAGE0_DIR/x86_64-pc-linux-gnu/lib"
# echo "$STAGE0_DIR/usr/lib64"
# echo "$STAGE0_DIR/lib64"
# echo "$STAGE0_DIR/usr/lib"
# } >> "$install_dir/etc/ld-musl-$(uname -m).path"
# cp -v "$ME/scripts/templates/musl-clang" "$stage1/bin/"
# chmod +x "$stage1/bin/musl-clang"
# sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/musl-clang"
# sed -i "s'@PREFIX@'$install_dir'" "$stage1/bin/musl-clang"
# sed -i "s'@INCDIR@'$install_dir/include'" "$stage1/bin/musl-clang"
# sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/musl-clang"
# cp -v "$ME/scripts/templates/ld.musl-lld" "$stage1/bin/"
# chmod +x "$stage1/bin/ld.musl-lld"
# sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/ld.musl-lld"
# sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/ld.musl-lld"
# TODO: [toolchain] Hardcoded value for dynamic linker of musl is BAAAAD
# idea. We need a way to make sure the name is correct
#sed -i "s'@LDSO@'/lib/ld-musl-x86_64.so.1'" "$stage1/bin/ld.musl-lld"
# /TODO
echo -e "#include <string.h>\nint main() {return 0;}" > "$install_dir/main.cpp"
$CXX -stdlib=libc++ -static "$install_dir/main.cpp" -o "$install_dir/main" -fuse-ld=lld -v
unset CC CXX LDFLAGS
PATH="$old_path"
export PATH
_pop
info "Stage1 musl has been built at: '$install_dir'"
}
function build_toolchain_stage1() {
local version repo src install_dir build_dir old_path musl
#musl="$DEPS_BUILD_DIR/musl.stage1.$MUSL_VERSION"
musl="$STAGE1_DIR.tmp"
version="$LLVM_VERSION"
install_dir="$STAGE1_DIR"
build_dir="$LLVM_BUILD_DIR.stage1.$version"
repo="${LLVM_REPO:-https://github.com/llvm/llvm-project.git}"
src="$DEPS_SOURCE_DIR/$LLVM_DIR_NAME.$version"
clone_dep "$repo" "$version" "$src"
info "Building the stage1 toolchain version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "Stage1 build dir already exists at '$build_dir'"
fi
mkdir -p "$build_dir"
mkdir -p "$install_dir"
_push "$LLVM_BUILD_DIR.stage1.$version"
old_path="$PATH"
PATH="$STAGE0_DIR/bin:$PATH"
CC=$(which clang)
CXX=$(which clang++)
export CC CXX PATH
info "Testing libc++ availability..."
(printf "#include <cstddef>\nint main(){return sizeof(size_t);}" \
| $CXX -x c++ -stdlib=libc++ -v - || {
>&2 echo "Need libc++ for this to work"
exit 1
}) && {
info "libc++ looks ok!"
}
# -isystem $STAGE0_DIR/include/c++/v1/ -isystem $STAGE0_DIR/include -isystem $musl/include
export CFLAGS=' -g -g1 -nodefaultlibs'
export CXXFLAGS="$CFLAGS -nostdinc++ -nostdlib++ -isystem $STAGE0_DIR/include/x86_64-pc-linux-gnu/c++/v1/ -isystem $STAGE0_DIR/include/c++/v1/ -isystem $musl/include -isystem $STAGE0_DIR/include"
export LDFLAGS="-fuse-ld=lld -L $musl/lib/ -L $STAGE0_DIR/lib/ -lc++ -lc++abi -L $STAGE0_DIR/lib/x86_64-pc-linux-gnu -L $STAGE0_DIR/lib/clang/17/lib/x86_64-pc-linux-gnu -lc --rtlib=compiler-rt -lunwind -rpath $STAGE0_DIR/lib"
# Set the compiler and linker flags...
#LINKERFLAGS="-Wl,-dynamic-linker $install_dir/lib/ld-musl-x86_64.so.1"
cmake -G Ninja -Wno-dev \
-DCMAKE_INSTALL_PREFIX="$install_dir" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-C "$ME/cmake/toolchains/stage2.standalone.cmake" \
"$src/llvm"
# -DCMAKE_SYSROOT="$STAGE0_DIR" \
# -DDEFAULT_SYSROOT="$STAGE0_DIR" \
# -DCMAKE_EXE_LINKER_FLAGS="${LINKERFLAGS}" \
# -DCMAKE_SHARED_LINKER_FLAGS="${LINKERFLAGS}" \
# -DCMAKE_SYSROOT="$STAGE0_DIR" \
#-DCMAKE_C_LINK_EXECUTABLE="$STAGE0_DIR/bin/bla" \
# -DCMAKE_CXX_LINK_EXECUTABLE="$STAGE0_DIR/bin/bla" \
# -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl \
# -DLLVM_HOST_TRIPLE=x86_64-unknown-linux-musl \
# -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl \
# -DCMAKE_EXE_LINKER_FLAGS="${LINKERFLAGS}" \
# -DCMAKE_SHARED_LINKER_FLAGS="${LINKERFLAGS}" \
# "${CONFIG_TOOLS}" "${CONFIG_TUPLES}" \
# "${CONFIG_CRT}" "${CONFIG_CLANG}" "${CONFIG_OPTIONS}" \
# "${CONFIG_LIBUNWIND}" "${CONFIG_LIBCXXABI}" \
# "${CONFIG_LIBCXX}" "${CONFIG_PATHS}" "${BUILD_OFF}" \
# -DLLVM_ENABLE_PROJECTS="clang;lld" \
# -DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
# -DLLVM_ENABLE_LLD=ON \
# -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
# -DCOMPILER_RT_BUILD_BUILTINS=ON \
# -DLIBCXX_USE_COMPILER_RT=ON \
# -DLIBCXXABI_USE_COMPILER_RT=ON \
# -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
# -DLLVM_BUILD_EXAMPLES=OFF \
# -DLLVM_TARGETS_TO_BUILD="X86" \
# -DCMAKE_BUILD_TYPE=Release \
# -DLLVM_ENABLE_PROJECTS='clang;lld' \
# -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
# -DCOMPILER_RT_BUILD_BUILTINS=ON \
# -DLIBCXX_USE_COMPILER_RT=ON \
# -DLIBCXXABI_USE_COMPILER_RT=ON \
# -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
# -DLLVM_INCLUDE_BENCHMARKS=OFF \
# -DLLVM_ENABLE_LLD=ON \
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -P cmake_install.cmake
unset CC CXX LDFLAGS
PATH="$old_path"
export PATH
_pop
info "Stage1 is ready at '$install_dir'"
}
function build_libcxx_stage2() {
local version repo src stage1 old_path install_dir build_dir
version="$LLVM_VERSION"
repo="${LLVM_REPO:-https://github.com/llvm/llvm-project.git}"
src="$DEPS_SOURCE_DIR/$LLVM_DIR_NAME.$version"
stage1="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.stage1.$version"
install_dir="$STAGE2_DIR"
build_dir="$DEPS_BUILD_DIR/libcxx_build.stage2.$version"
if [ ! -d "$stage1" ]; then
error "Stage1 compiler is not there yet. Did you forget to build it?"
exit 1
fi
clone_dep "$repo" "$version" "$src"
info "Building the stage2 libcxx version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "A build dir for 'libcxx' already exists at '$build_dir'"
fi
mkdir -p "$build_dir"
mkdir -p "$install_dir"
_push "$build_dir"
old_path="$PATH"
export PATH="$stage1/bin:$PATH"
export CC="$stage1/bin/clang"
export CXX="$stage1/bin/clang++"
# musl_dir="$DEPS_BUILD_DIR/$MUSL_DIR_NAME.stage2.$version"
# export CFLAGS="-L $musl_dir/lib -isystem $musl_dir/include -nostdinc"
# export CXXFLAGS="$CFLAGS"
# CFLAGS="-flto=thin"
# CXXFLAGS="$CFLAGS"
# LDFLAGS="-flto=thin"
export CC CXX
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$install_dir" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS='clang;lld' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
-DLLVM_ENABLE_LLD=ON \
-DLLVM_EXTERNAL_IWYU_SOURCE_DIR="$iwyu_src" \
-DTARGET_ARCHS="$TARGET_ARCHS" \
-C "$ME/cmake/caches/llvm.cmake" \
-S "$src/llvm"
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -P cmake_install.cmake
export PATH="$old_path"
# unset CFLAGS
# unset CXXFLAGS
unset CC
unset CXX
_pop
info "Stage2 'libcxx' build is ready at '$install_dir'"
info "llvm build is ready at '$install_dir'"
info "Just add the 'bin' dir to you PATH"
}
function build_musl_stage2() {
local version repo src build_dir install_dir old_path stage1
version="$MUSL_VERSION"
install_dir="$STAGE2_DIR"
build_dir="$DEPS_BUILD_DIR/${MUSL_DIR_NAME}_build.stage2.$version"
repo="${MUSL_REPO:-git://git.musl-libc.org/musl}"
src="$DEPS_SOURCE_DIR/$MUSL_DIR_NAME.$version"
stage1="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.stage1.$LLVM_VERSION"
# function build_musl_stage1() {
# local version repo src build_dir install_dir old_path stage1
clone_dep "$repo" "$version" "$src"
# version="$MUSL_VERSION"
# install_dir="$DEPS_BUILD_DIR/musl.stage1.$version"
# #install_dir="$STAGE1_DIR.tmp"
# build_dir="$DEPS_BUILD_DIR/${MUSL_DIR_NAME}_build.stage1.$version"
# repo="${MUSL_REPO:-git://git.musl-libc.org/musl}"
# src="$DEPS_SOURCE_DIR/$MUSL_DIR_NAME.$version"
info "Building the stage2 musl version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "A build dir for 'musl' already exists at '$build_dir'"
warn "Cleaning up..."
rm -rf "$build_dir"
fi
# clone_dep "$repo" "$version" "$src"
info "Copy the source to the build directory at: '$build_dir'"
cp -r "$src" "$build_dir"
# info "Building the stage2 musl version '$version'..."
# if [[ -d "$build_dir" ]]; then
# warn "A build dir for 'musl' already exists at '$build_dir'"
# warn "Cleaning up..."
# rm -rf "$build_dir"
# fi
mkdir -p "$install_dir"
# info "Copy the source to the build directory at: '$build_dir'"
# cp -r "$src" "$build_dir"
_push "$build_dir"
old_path="$PATH"
export PATH="$stage1/bin:$PATH"
# mkdir -p "$install_dir"
export CC="$stage1/bin/clang"
export CXX="$stage1/bin/clang++"
export CFLAGS="-fuse-ld=lld -Os -pipe"
export LDFLAGS="-fuse-ld=lld"
export LIBCC="--rtlib=compiler-rt"
# _push "$build_dir"
./configure --disable-shared --prefix="$install_dir"
# old_path="$PATH"
# PATH="$STAGE0_DIR/bin:$PATH"
# CC=$(which clang)
# CXX=$(which clang++)
# LDFLAGS="-fuse-ld=lld"
make -j "$(nproc)"
make install
# export CC CXX LDFLAGS PATH LDFLAGS
unset CC
unset CXX
unset CFLAGS
unset LIBCC
unset LDFLAGS
export PATH="$old_path"
# ./configure --prefix="$install_dir"
cp -v "$ME/scripts/templates/musl-clang" "$stage1/bin/"
chmod +x "$stage1/bin/musl-clang"
sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/musl-clang"
sed -i "s'@PREFIX@'$install_dir'" "$stage1/bin/musl-clang"
sed -i "s'@INCDIR@'$install_dir/include'" "$stage1/bin/musl-clang"
sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/musl-clang"
# make -j "$(nproc)"
# make install
# ln -sv "$install_dir/lib/libc.so" "$install_dir/lib/ld-musl-$(uname -m).so.1"
cp -v "$ME/scripts/templates/ld.musl-lld" "$stage1/bin/"
chmod +x "$stage1/bin/ld.musl-lld"
sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/ld.musl-lld"
sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/ld.musl-lld"
# TODO: [toolchain] Hardcoded value for dynamic linker of musl is BAAAAD
# idea. We need a way to make sure the name is correct
sed -i "s'@LDSO@'/lib/ld-musl-x86_64.so.1'" "$stage1/bin/ld.musl-lld"
# /TODO
# # Create a symlink that can be used to print
# # the required shared objects of a program or
# # shared object
# # ln -sv "$install_dir/lib/libc.so" "$install_dir/bin/ldd"
_pop
info "Stage2 musl has been built at: '$install_dir'"
}
# # # Configure the dynamic linker
# # mkdir -p "$install_dir/etc"
# # {
# # echo "/usr/lib/gcc/x86_64-pc-linux-gnu/12"
# # echo "/usr/lib/gcc/x86_64-pc-linux-gnu/11"
# # echo "/usr/lib64/"
# # echo "/usr/lib/"
# # echo "$STAGE0_DIR/lib/clang/$LLVM_MAJOR_VERSION/lib/x86_64-unknown-linux-gnu"
# # echo "$STAGE0_DIR/lib/x86_64-unknown-linux-gnu"
# # echo "$install_dir/lib"
# # echo "$install_dir/x86_64-unknown-linux-gnu/lib"
# # echo "$install_dir/usr/lib64"
# # echo "$install_dir/lib64"
# # echo "$install_dir/usr/lib"
# # echo "$STAGE0_DIR/lib"
# # echo "$STAGE0_DIR/x86_64-pc-linux-gnu/lib"
# # echo "$STAGE0_DIR/usr/lib64"
# # echo "$STAGE0_DIR/lib64"
# # echo "$STAGE0_DIR/usr/lib"
# # } >> "$install_dir/etc/ld-musl-$(uname -m).path"
function build_toolchain_stage2() {
local version repo src install_dir stage1 build_dir old_path
# # cp -v "$ME/scripts/templates/musl-clang" "$stage1/bin/"
# # chmod +x "$stage1/bin/musl-clang"
# # sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/musl-clang"
# # sed -i "s'@PREFIX@'$install_dir'" "$stage1/bin/musl-clang"
# # sed -i "s'@INCDIR@'$install_dir/include'" "$stage1/bin/musl-clang"
# # sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/musl-clang"
version="$LLVM_VERSION"
install_dir="$STAGE2_TC_DIR"
repo="${LLVM_REPO:-https://github.com/llvm/llvm-project.git}"
src="$DEPS_SOURCE_DIR/$LLVM_DIR_NAME.$version"
# Why not our clang from stage1? Well musl kindly provides a wraper
# script in the bin directory that uses musl but with the compiler
# that builds it. So basically `musl-clang` would be a wrapper around
# stage one clang with musl enabled by default
stage1="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.stage1.$version"
install_dir="$STAGE2_TC_DIR"
build_dir="$DEPS_BUILD_DIR/${LLVM_DIR_NAME}_build.stage2.$version"
# # cp -v "$ME/scripts/templates/ld.musl-lld" "$stage1/bin/"
# # chmod +x "$stage1/bin/ld.musl-lld"
# # sed -i "s'@CC@'$stage1/bin/clang'" "$stage1/bin/ld.musl-lld"
# # sed -i "s'@LIBDIR@'$install_dir/lib'" "$stage1/bin/ld.musl-lld"
# # TODO: [toolchain] Hardcoded value for dynamic linker of musl is BAAAAD
# # idea. We need a way to make sure the name is correct
# #sed -i "s'@LDSO@'/lib/ld-musl-x86_64.so.1'" "$stage1/bin/ld.musl-lld"
# # /TODO
# echo -e "#include <string.h>\nint main() {return 0;}" > "$install_dir/main.cpp"
if [ ! -d "$stage1" ]; then
error "Stage1 compiler is not there yet. Did you forget to build it?"
exit 1
fi
# $CXX -stdlib=libc++ -static "$install_dir/main.cpp" -o "$install_dir/main" -fuse-ld=lld -v
clone_dep "$repo" "$version" "$src"
# unset CC CXX LDFLAGS
info "Building the stage2 toolchain version '$version'..."
if [[ -d "$build_dir" ]]; then
warn "A build dir for stage2 'llvm' already exists at '$build_dir'"
fi
# PATH="$old_path"
# export PATH
mkdir -p "$build_dir"
mkdir -p "$install_dir"
# _pop
# info "Stage1 musl has been built at: '$install_dir'"
# }
_push "$build_dir"
old_path="$PATH"
export PATH="$STAGE2_DIR/bin:$stage1/bin:$PATH"
export CC="$stage1/bin/musl-clang"
export CXX="$stage1/bin/clang++"
export CXXFALGS="--rtlib=compiler-rt"
export LDFLAGS="-fuse-ld=musl-lld -v"
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$install_dir" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_TARGETS_TO_BUILD="$TARGET_ARCHS" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSROOT="$STAGE2_DIR" \
-DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-linux-musl" \
-DLLVM_TARGET_TRIPLE="x86_64-linux-musl" \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_STATIC_LINK_CXX_STDLIB=ON \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
"$src/llvm"
#-DLLVM_USE_LINKER="$STAGE2_DIR/bin/ld.musl-lld" \
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -P cmake_install.cmake
export PATH="$old_path"
#-DLLVM_ENABLE_LLD=ON \
unset CC
unset CXX
_pop
info_toolchain
}
function build_toolchain_stage3() {
local version repo src install_dir stage1 old_path
version="$LLVM_VERSION"
repo="${LLVM_REPO:-https://github.com/llvm/llvm-project.git}"
src="$DEPS_SOURCE_DIR/$LLVM_DIR_NAME.$version"
stage1="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.stage1.$version"
install_dir="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.stage2.$version"
if [ ! -d "$stage1" ]; then
error "Stage1 compiler is not there yet. Did you forget to build it?"
exit 1
fi
clone_dep "$repo" "$LLVM_VERSION" "$src"
info "Building the stage2 toolchain version '$version'..."
if [[ -d "$LLVM_BUILD_DIR.stage2.$version" ]]; then
warn "A build dir for 'llvm' already exists at '$LLVM_BUILD_DIR.stage2.$version'"
fi
mkdir -p "$LLVM_BUILD_DIR.stage2.$version"
mkdir -p "$install_dir"
_push "$LLVM_BUILD_DIR.stage2.$version"
old_path="$PATH"
export PATH="$stage1/bin:$PATH"
CC="$stage1/bin/clang"
CXX="$stage1/bin/clang++"
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$install_dir" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_TARGETS_TO_BUILD="$TARGET_ARCHS" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_CCACHE_BUILD=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DLLVM_ENABLE_LLD=ON \
"$src/llvm"
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -P cmake_install.cmake
export PATH="$old_path"
unset CC
unset CXX
_pop
info_toolchain
}
function build_toolchain() {
local stage
@ -568,43 +192,13 @@ function build_toolchain() {
case "$stage" in
"")
build_musl_stage1
build_toolchain_stage1
build_musl_stage2
build_libcxx_stage2
build_toolchain_stage2
build_llvm
;;
"dstage0")
run_in_container ./builder deps build toolchain stage0
;;
"stage0")
build_toolchain_stage0
;;
"stage1")
#cp -r "$STAGE0_DIR" "$STAGE1_DIR.tmp"
build_musl_stage1
build_toolchain_stage1
;;
"stage1-tc")
#cp -r "$STAGE0_DIR" "$STAGE1_DIR"
build_toolchain_stage1
;;
"stage2")
build_musl_stage2
build_libcxx_stage2
build_toolchain_stage2
;;
"stage1-musl")
build_musl_stage1
;;
"stage2-musl")
build_musl_stage2
;;
"stage2-libcxx")
build_libcxx_stage2
;;
"stage2-toolchain")
build_toolchain_stage2
# "dstage0")
# run_in_container ./builder deps build toolchain stage0
# ;;
"llvm")
build_llvm
;;
*)
error "Don't know anythings about '$1'"
@ -613,34 +207,37 @@ function build_toolchain() {
}
function package_toolchain() { ## Packages the built toolchain
local version
local version install_dir
version="$LLVM_VERSION"
install_dir="$DEPS_BUILD_DIR/llvm.$LLVM_VERSION"
if [ ! -d "$LLVM_INSTALL_DIR" ]; then
error "No installation directory is found at: '$LLVM_INSTALL_DIR'"
if [ ! -d "$install_dir" ]; then
error "No installation directory is found at: '$install_dir'"
exit 1
fi
info "Packaging the toolchain version '$version'..."
_push "$DEPS_BUILD_DIR"
local pkg
pkg="$LLVM_DIR_NAME.$version"
pkg="llvm.$version"
time tar -I "$ZSTD_CLI" -cf "$pkg.zstd" "$pkg"
_pop
}
function push_toolchain() { ## Push the toolchain to the package repository
local version
local version install_dir
version="$LLVM_VERSION"
if [ ! -f "$LLVM_INSTALL_DIR.zstd" ]; then
error "No package is found at: '$LLVM_INSTALL_DIR.zstd'"
install_dir="$DEPS_BUILD_DIR/llvm.$LLVM_VERSION"
if [ ! -f "$install_dir.zstd" ]; then
error "No package is found at: '$install_dir.zstd'"
exit 1
fi
info "Pushing the toolchain version '$version'..."
_push "$DEPS_BUILD_DIR"
http_push "$LLVM_DIR_NAME" "$version"
http_push "llvm" "$version"
echo ""
info "Done"
_pop