summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Hill <ahill@breadpudding.dev>2025-08-17 17:56:25 -0400
committerAlexander Hill <ahill@breadpudding.dev>2025-08-17 17:56:25 -0400
commit3b684928a1b6d53b49a466e109871bf8333999cf (patch)
treee68abf691e2c4f107d9578f64084059ec33ce424
parentab0fbc1aca7509d24ba07f7d066a4d29e5908054 (diff)
Attempting to bootstrap Rust
-rw-r--r--Dockerfile2
-rwxr-xr-xbuild-bootstrap.sh119
-rw-r--r--sources.list1
3 files changed, 109 insertions, 13 deletions
diff --git a/Dockerfile b/Dockerfile
index 60ecb62..4cc92c8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,5 +2,5 @@ FROM alpine:latest
RUN apk update
RUN apk upgrade
-RUN apk add clang cmake curl git libc++ linux-headers makedoas python3 rsync samurai umount
+RUN apk add cargo clang cmake curl git libc++ linux-headers makedoas python3 rsync rust samurai umount
RUN git clone https://github.com/cbpudding/maplelinux-bootstrap /maple \ No newline at end of file
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 ..
diff --git a/sources.list b/sources.list
index 02d3ad2..4a03b12 100644
--- a/sources.list
+++ b/sources.list
@@ -109,6 +109,7 @@ c2e6d193cc78f84cd6ddb72aaf6d5c6a9162f0470e5992092057f5ff518562fa,https://gigenet
61a42919e13d539f7673cf11d1c404380e28e540510860b9d242196e165709c9,https://www.python.org/ftp/python/3.9.23/Python-3.9.23.tar.xz,
70d4739585a7008f37bf4933c013fdb327b8878a5a69fcbb3316c88882f0f49b,https://files.pythonhosted.org/packages/d7/7d/60976d532519c3a0b41e06a59ad60949e2be1af937cf02738fec91bfd808/pytest-runner-6.0.1.tar.gz,
d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e,https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz,
+0c1dcbb4f762513d021e1a282c0ac58c0a423642b3a6bf581cafb5414df4193e,https://static.rust-lang.org/dist/rustc-1.88.0-src.tar.xz,
3b8cf51548dfc49b7efe035e191ff5e1963ebc4fe8f6064a5eefc5343eaf78a5,https://github.com/michaelforney/samurai/releases/download/1.2/samurai-1.2.tar.gz,
6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181,https://ftpmirror.gnu.org/gnu/sed/sed-4.9.tar.xz,
f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c,https://files.pythonhosted.org/packages/18/5d/3bf57dcd21979b887f014ea83c24ae194cfcd12b9e0fda66b957c69d1fca/setuptools-80.9.0.tar.gz,