Compare commits

..
1 Commits
Author SHA1 Message Date
cat 37b07b121f mrustc: init
This bootstraps rustc via the mrustc alternative compiler. The build
process is extraordinarily ugly because rustc maintainers cargo culted
target triple strings without understanding what they are, and
completely mishandles them. They also appear to lack fundamental system
understanding and assume musl can only be used for static linking. The
build process also fails to populate their so called self-contained
library directory, so it is manually put together here.

This setup uses the vendored LLVM for multiple reasons: the fact that
rustc maintainers manage to fuck up so badly they simultaneously pass
GCC-only and Clang-only flags when using an LLVM configured to use
libc++ instead of GNU slop, and the immense maintenance burden to keep
this up to date enough to use Rosa OS LLVM. For now, time and effort
saved from trying to mutilate this pile of garbage into working with a
proper LLVM build more than compensates for the wasted CPU time.

GCC libraries are included in the output because despite the utter
reluctance to do dynamic linking correctly on musl, it seems that rustc
is also incapable of passing the correct linker flags to produce static
executables, and the miserable mrustc Makefiles make it impossible to
specify custom linker flags. From my previous experience producing a
static virtiofsd build, it would require multiple arguments per library,
all of them in rustc's fucked up custom syntax, and I am not ready to
deal with that. To avoid contaminating future stages with gcc, this
package includes only libraries required at runtime.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-07-21 17:57:10 +09:00
2 changed files with 3 additions and 108 deletions
-54
View File
@@ -1,54 +0,0 @@
diff --git a/run_rustc/Makefile b/run_rustc/Makefile
index e78d8c51..cc9f785e 100644
--- a/run_rustc/Makefile
+++ b/run_rustc/Makefile
@@ -150,14 +150,23 @@ $(CARGO_HOME)config: Makefile
$Vecho "[source.vendored-sources]" >> $@
$Vecho "directory = \"$(abspath $(VENDOR_DIR))\"" >> $@
+self-contained:
+ mkdir -p $@
+ (set -o braceexpand && ln -s \
+ /system/lib/{'rcrt1.o','crti.o','crtn.o'} \
+ /system/lib/gcc/"$(ROSA_TRIPLE)"/"$(shell gcc -dumpfullversion)"/{'crtbeginS.o','crtendS.o'} \
+ /system/lib/"$(ROSA_TRIPLE)"/* \
+ $@)
+
# -------------------------------------
# Stage 1: Build standard library (using minicargo with rustc)
# - Can't use `cargo` because there isn't a rustc-compatible std yet
# - _could_ use it if mrustc accepted all the arguments rustc does (via the proxy)
# -------------------------------------
-$(LIBDIR_S)libstd.rlib: $(BINDIR_S)rustc $(MINICARGO) Makefile
+$(LIBDIR_S)libstd.rlib: self-contained $(BINDIR_S)rustc $(MINICARGO) Makefile
@echo "[MINICARGO] $(RUST_SRC_LIBS)std > $(LIBDIR_S)"
- mkdir -p $(LIBDIR_S)
+ @mkdir -p $(LIBDIR_S)
+ @ln -sf ../../../../../../self-contained $(LIBDIR_S)
ifneq ($(TARGETVER_LEAST_1_74),)
$V+STD_ENV_ARCH=$(RUSTC_ARCH) MRUSTC_PATH=$(abspath $(BINDIR_S)rustc) $(MINICARGO) --vendor-dir $(VENDOR_DIR) --script-overrides ../script-overrides/stable-$(RUSTC_VERSION)-$(PLATFORM)/ --output-dir $(LIBDIR_S) $(RUST_SRC_LIBS)sysroot
else
@@ -178,6 +187,7 @@ CARGO_OUTDIR_STAGE2_STD := $(OUTDIR)build-std2/$(RUSTC_TARGET)/release/
CARGO_ENV_STAGE2_STD := CARGO_TARGET_DIR=$(OUTDIR)build-std2 RUSTC=$(abspath rustc_proxy.sh) PROXY_RUSTC=$(abspath $(BINDIR_2)rustc) PROXY_MRUSTC=$(abspath $(BINDIR_S)rustc) $(CARGO_ENV)
$(LIBDIR_2)libtest.rlib: $(LIBDIR_S)libstd.rlib $(BINDIR_2)rustc $(BINDIR_S)rustc $(BINDIR_S)cargo $(CARGO_HOME)config Makefile
@mkdir -p $(LIBDIR_2)
+ @ln -sf ../../../../../../self-contained $(LIBDIR_2)
@echo [CARGO] $(RUST_SRC_LIBS)test/Cargo.toml '>' $(OUTDIR)build-std2
ifneq ($(TARGETVER_LEAST_1_74),)
$V$(CARGO_ENV_STAGE2_STD) $(BINDIR_S)cargo build $(CARGO_FLAGS) --manifest-path $(RUST_SRC_LIBS)sysroot/Cargo.toml --features panic-unwind
@@ -215,6 +225,7 @@ else
@echo "[CP] libraries and results ($@)"
endif
@mkdir -p $(LIBDIR)
+ @ln -sf ../../../../../../self-contained $(LIBDIR)
$Vcp $(LIBDIR_2)*.$(DYLIB_EXT) $(PREFIX)lib
$Vcp $(CARGO_OUTDIR_RUSTC)deps/*.rlib $(LIBDIR)
$Vcp $(CARGO_OUTDIR_RUSTC)deps/*.$(DYLIB_EXT) $(LIBDIR)
@@ -243,6 +254,7 @@ CARGO_OUTDIR_STAGE3_STD := $(OUTDIR)build-std/$(RUSTC_TARGET)/release/
CARGO_ENV_STAGE3_STD := CARGO_TARGET_DIR=$(OUTDIR)build-std RUSTC=$(abspath rustc_proxy.sh) PROXY_RUSTC=$(abspath $(BINDIR)rustc) PROXY_MRUSTC=$(abspath $(BINDIR_2)rustc) $(CARGO_ENV)
$(LIBDIR)libstd.rlib: $(BINDIR)rustc
@mkdir -p $(LIBDIR)
+ @ln -sf ../../../../../../self-contained $(LIBDIR)
@echo [CARGO] $(RUST_SRC_LIBS)test/Cargo.toml '>' $(OUTDIR)build-std2
ifneq ($(TARGETVER_LEAST_1_74),)
$V$(CARGO_ENV_STAGE3_STD) $(BINDIR_S)cargo build $(CARGO_FLAGS) --manifest-path $(RUST_SRC_LIBS)sysroot/Cargo.toml --features panic-unwind
+3 -54
View File
@@ -117,15 +117,13 @@ package rustc-mrustc {
skipConfigure = true; skipConfigure = true;
preMake = ` preMake = `
LLVM='../rustc-bootstrap-llvm/system/bin/llvm-config' LLVM='../rustc-bootstrap-llvm/system/bin/llvm-config'
RUSTC_SOURCE='../../rustc-mrustc'
export CC=gcc CXX=g++ export CC=gcc CXX=g++
export PARLEVEL=`+jobsE+` export PARLEVEL=`+jobsE+`
export RUSTC_TARGET="$(uname -m)-unknown-linux-musl" export RUSTC_TARGET="$(uname -m)-unknown-linux-musl"
export RUSTC_SOURCE='../../rustc-mrustc'
export RUSTC_VERSION="$(cut -d ' ' -f 1 "$RUSTC_SOURCE/version")" export RUSTC_VERSION="$(cut -d ' ' -f 1 "$RUSTC_SOURCE/version")"
export MRUSTC_TARGET_VER="$(cut -d '.' -f 1,2 <<< "$RUSTC_VERSION")" export MRUSTC_TARGET_VER="$(cut -d '.' -f 1,2 <<< "$RUSTC_VERSION")"
export OUTDIR_SUF="-$RUSTC_VERSION" export OUTDIR_SUF="-$RUSTC_VERSION"
patch -d "$RUSTC_SOURCE" -p0 < "rustc-$RUSTC_VERSION-src.patch" patch -d "$RUSTC_SOURCE" -p0 < "rustc-$RUSTC_VERSION-src.patch"
touch "$RUSTC_SOURCE/dl-version" touch "$RUSTC_SOURCE/dl-version"
@@ -158,7 +156,7 @@ OUTDIR="output-$RUSTC_VERSION"
make -f minicargo.mk LLVM_CONFIG="$LLVM" "$OUTDIR/rustc" make -f minicargo.mk LLVM_CONFIG="$LLVM" "$OUTDIR/rustc"
make -f minicargo.mk LLVM_CONFIG="$LLVM" "$OUTDIR/cargo" make -f minicargo.mk LLVM_CONFIG="$LLVM" "$OUTDIR/cargo"
mkdir -p /work/system/bin/ mkdir -p /work/system/bin/
(set -o braceexpand && cp "$OUTDIR"/{rustc,cargo} bin/minicargo /work/system/bin/) (set -o braceexpand && cp "$OUTDIR"/{rustc,cargo} /work/system/bin/)
`; `;
}; };
@@ -170,54 +168,5 @@ mkdir -p /work/system/bin/
llvm, llvm,
]; ];
runtime = [ gcc, llvm, mrustc ]; runtime = [ gcc, llvm ];
}
package rustc-bootstrap {
description = "early rustc bootstrapped by rustc-mrustc";
exclude = true;
source = rustc-bootstrap-source;
extra = [ mrustc-source ];
files = {
"b00-link-self-contained.patch";
};
writable = true;
early = "cd ../extra/mrustc-source";
minimal = true;
exec = make {
inPlace = true;
skipConfigure = true;
preMake = `
RUSTC_SOURCE='../../rustc-bootstrap'
export RUSTC_TARGET="$(uname -m)-unknown-linux-musl"
export RUSTC_VERSION="$(cut -d ' ' -f 1 "$RUSTC_SOURCE/version")"
patch -d "$RUSTC_SOURCE" -p0 < "rustc-$RUSTC_VERSION-src.patch"
cat /usr/src/*.patch | patch -p1
ln -s "$RUSTC_SOURCE" "rustc-$RUSTC_VERSION-src"
mkdir bin "output-$RUSTC_VERSION"
(set -o braceexpand && \
ln -s /system/bin/{mrustc,minicargo} bin/ && \
ln -s /system/bin/{rustc,cargo} "output-$RUSTC_VERSION")
ln -sf gcc /system/bin/cc
ln -sf g++ /system/bin/c++
`;
make = [
"-C", "run_rustc",
"CC=gcc",
"PARLEVEL="+jobsE,
];
};
inputs = [
bash,
patch,
rustc-mrustc,
];
} }