diff options
Diffstat (limited to 'build-bootstrap.sh')
| -rwxr-xr-x | build-bootstrap.sh | 119 |
1 files changed, 107 insertions, 12 deletions
diff --git a/build-bootstrap.sh b/build-bootstrap.sh index e453520..bdee7a1 100755 --- a/build-bootstrap.sh +++ b/build-bootstrap.sh @@ -1,12 +1,14 @@ #!/bin/sh -e +export MAPLE=$(pwd)/maple + +export BUILD=$(clang -dumpmachine) export CC=clang -export CFLAGS="-O3 -march=skylake -pipe --sysroot=$MAPLE" +export CFLAGS="-O3 -march=skylake -pipe" export CXX=clang++ export CXXFLAGS="$CFLAGS" +export HOST=x86_64-maple-linux-musl export LD=ld.lld -export MAPLE=$(pwd)/maple export THREADS=$(nproc) -export HOST=x86_64-unknown-linux-musl # A simplified FHS variant with symlinks for backwards compatibility ~ahill # TODO: Where does /usr/com fit into all of this (shared state directory)? ~ahill @@ -31,6 +33,7 @@ mkdir -p $MAPLE/tmp mkdir -p $MAPLE/usr ln -sf ../bin $MAPLE/usr/bin mkdir -p $MAPLE/usr/include +ln -sf . $MAPLE/usr/include/$HOST ln -sf ../lib $MAPLE/usr/lib ln -sf ../lib $MAPLE/usr/libexec ln -sf ../bin $MAPLE/usr/sbin @@ -56,13 +59,13 @@ cd llvm-project-*/ # ~ahill # See also: https://peps.python.org/pep-0644/ cmake -B stage1 -G Ninja -S llvm \ - -DCMAKE_BUILD_PARALLEL_LEVEL=$THREADS \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=$MAPLE/maple/tools \ -DCLANG_DEFAULT_CXX_STDLIB=libc++ \ -DCLANG_DEFAULT_RTLIB=compiler-rt \ -DCLANG_DEFAULT_UNWINDLIB=libunwind \ -DCLANG_VENDOR=Maple \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCMAKE_INSTALL_PREFIX=$MAPLE/maple/tools \ -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \ -DLIBCXX_CXX_ABI=libcxxabi \ -DLIBCXX_HAS_MUSL_LIBC=ON \ @@ -72,23 +75,26 @@ cmake -B stage1 -G Ninja -S llvm \ -DLIBUNWIND_ENABLE_ASSERTIONS=OFF \ -DLIBUNWIND_USE_COMPILER_RT=ON \ -DLLVM_BUILD_LLVM_DYLIB=ON \ + -DLLVM_DEFAULT_TARGET_TRIPLE=$HOST \ -DLLVM_ENABLE_LIBCXX=ON \ -DLLVM_ENABLE_PROJECTS="clang;lld;llvm" \ -DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind;libcxxabi;libcxx" \ - -DLLVM_HOST_TRIPLE=$HOST \ + -DLLVM_HOST_TRIPLE=$BUILD \ -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \ -DLLVM_INSTALL_UTILS=ON \ -DLLVM_LINK_LLVM_DYLIB=ON \ - -DLLVM_TARGETS_TO_BUILD=X86 \ - -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON + -DLLVM_TARGETS_TO_BUILD=X86 cmake --build stage1 cmake --install stage1 cd .. export CC="$MAPLE/maple/tools/bin/clang" +export CFLAGS="-O3 -march=skylake -pipe --sysroot=$MAPLE" export CXX="$MAPLE/maple/tools/bin/clang++" +export CXXFLAGS="$CFLAGS" export LD=$MAPLE/maple/tools/bin/ld.lld export PATH="$MAPLE/maple/tools/bin:$PATH" +export RUSTFLAGS="-C target-feature=-crt-static" # Linux Headers tar xf ../sources/linux-*.tar* @@ -102,9 +108,9 @@ cd .. # FIXME: CVE-2025-26519 tar xf ../sources/musl-*.tar* cd musl-*/ -./configure --disable-static --includedir=/usr/include --prefix="" -make -j $THREADS -make -j $THREADS install DESTDIR=$MAPLE +./configure --includedir=/usr/include --prefix="" +make -O -j $THREADS +make -O -j $THREADS install DESTDIR=$MAPLE # NOTE: musl provides static libraries for POSIX libraries such as libm, but # fails to provide shared versions which will breaks builds later on. # Granted, they are useless since libc.so contains all the functionality @@ -366,6 +372,95 @@ cmake --install stage2 ln -sf clang $MAPLE/bin/cc ln -sf clang++ $MAPLE/bin/c++ ln -sf ld.lld $MAPLE/bin/ld +# NOTE: Temporary workaround because builds that require __config fail +# otherwise. Is there a better solution for this? ~ahill +mv $MAPLE/maple/tools/include/$HOST/c++/v1/__config_site $MAPLE/maple/tools/include/c++/v1/ +cd .. + +# Rust Build +tar xf ../sources/rustc-*.tar* +cd rustc-*/ +./configure \ + --build=$BUILD \ + --enable-clang \ + --enable-extended \ + --enable-lld \ + --enable-local-rust \ + --enable-profiler \ + --enable-sanitizers \ + --enable-use-libcxx \ + --host=$HOST.json \ + --llvm-root=$MAPLE/maple/tools +# NOTE: The target for Alpine is missing musl-root, so we define it here. ~ahill +sed -i "/\[target.$BUILD\]/a musl-root='/usr'" bootstrap.toml +# NOTE: Next, we tell Rust to use our custom LLVM toolchain. ~ahill +sed -i "/\[target.'$HOST.json'\]/a ar = '$MAPLE/maple/tools/bin/llvm-ar'" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a cc = '$CC'" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a crt-static = false" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a cxx = '$CXX'" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a musl-root = '$MAPLE'" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a linker = '$CC'" bootstrap.toml +sed -i "/\[target.'$HOST.json'\]/a llvm-config = '$MAPLE/maple/tools/bin/llvm-config'" bootstrap.toml +# TODO: Do we need to define llvm-has-rust-patches here? ~ahill +sed -i "/\[target.'$HOST.json'\]/a ranlib = '$MAPLE/maple/tools/bin/llvm-ranlib'" bootstrap.toml +# NOTE: Setting change-id to "ignore" doesn't really have any special +# significance here. I just got tired of it complaining about the lack of +# a change-id. ~ahill +sed -i "1i change-id = 'ignore'" bootstrap.toml +# NOTE: Rust requires a JSON specification in addition to the TOML specified +# above. Since we're using x86_64-unknown-linux-musl as a template, we'll +# use compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs +# as a reference. ~ahill +# See also: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.Target.html +echo "{" > $HOST.json +echo "\"arch\": \"$(echo $HOST | cut -d"-" -f0)\"," >> $HOST.json +# FIXME: How would we even automatically detect this one? ~ahill +echo "\"data-layout\": \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"," >> $HOST.json +echo "\"llvm-target\": \"$HOST\"," >> $HOST.json +echo "\"metadata\": {}," >> $HOST.json +echo "\"options\": {" >> $HOST.json +# TARGET OPTIONS BEGINS HERE +echo "\"crt-static-respected\": true," >> $HOST.json +echo "\"dynamic-linking\": true," >> $HOST.json +echo "\"env\": \"musl\"," >> $HOST.json +echo "\"families\": [\"unix\"]," >> $HOST.json +echo "\"has-rpath\": true," >> $HOST.json +echo "\"has-thread-local\": true," >> $HOST.json +echo "\"link-self-contained\": \"musl\"," >> $HOST.json +echo "\"os\": \"linux\"," >> $HOST.json +echo "\"position-independent-executables\": true," >> $HOST.json +echo "\"post-link-objects-self-contained\": {" >> $HOST.json +echo "\"dynamic-no-pic-exe\": [\"crt1.o\", \"crti.o\", \"crtbegin.o\"]," >> $HOST.json +echo "\"dynamic-pic-exe\": [\"Scrt1.o\", \"crti.o\", \"crtbeginS.o\"]," >> $HOST.json +echo "\"static-no-pic-exe\": [\"crt1.o\", \"crti.o\", \"crtbegin.o\"]," >> $HOST.json +echo "\"static-pic-exe\": [\"rcrt1.o\", \"crti.o\", \"crtbeginS.o\"]," >> $HOST.json +echo "\"dynamic-dylib\": [\"crti.o\", \"crtbeginS.o\"]," >> $HOST.json +echo "\"static-dylib\": [\"crti.o\", \"crtbeginS.o\"]" >> $HOST.json +echo "}," >> $HOST.json +echo "\"pre-link-objects-self-contained\": {" >> $HOST.json +echo "\"dynamic-no-pic-exe\": [\"crtend.o\", \"crtn.o\"]," >> $HOST.json +echo "\"dynamic-pic-exe\": [\"crtendS.o\", \"crtn.o\"]," >> $HOST.json +echo "\"static-no-pic-exe\": [\"crtend.o\", \"crtn.o\"]," >> $HOST.json +echo "\"static-pic-exe\": [\"crtendS.o\", \"crtn.o\"]," >> $HOST.json +echo "\"dynamic-dylib\": [\"crtendS.o\", \"crtn.o\"]," >> $HOST.json +echo "\"static-dylib\": [\"crtendS.o\", \"crtn.o\"]" >> $HOST.json +echo "}," >> $HOST.json +echo "\"relro-level\": \"full\"," >> $HOST.json +echo "\"supported-split-debuginfo\": [\"packed\", \"unpacked\", \"off\"]" >> $HOST.json +# END OF TARGET OPTIONS +echo "}," >> $HOST.json +# FIXME: How do we automatically detect the pointer width? ~ahill +echo "\"pointer-width\": 64" >> $HOST.json +echo "}" >> $HOST.json +# NOTE: Make sure we revert to Alpine's compiler because we're bootstrapping a +# compiler again. ~ahill +export CC=clang +export CXX=clang++ +./x.py build --stage 0 +./x.py build --stage 1 +./x.py build --stage 2 +# ... +# DESTDIR on ./x.py install? cd .. cd .. |
