summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach van Rijn <me@zv.io>2024-12-17 15:45:18 +0000
committerZach van Rijn <me@zv.io>2024-12-17 20:21:36 -0600
commit803c617fc610d5872e32c08f362586d550d87701 (patch)
tree6a800eb1d37d86595dd597924be8f924b918b5c6
parente84bcca8de8fc62b5bf0067072c0d4e81346e11d (diff)
downloadpackages-803c617fc610d5872e32c08f362586d550d87701.tar.gz
packages-803c617fc610d5872e32c08f362586d550d87701.tar.bz2
packages-803c617fc610d5872e32c08f362586d550d87701.tar.xz
packages-803c617fc610d5872e32c08f362586d550d87701.zip
re-work target logic
-rw-r--r--experimental/mrustc/APKBUILD39
-rw-r--r--experimental/mrustc/add-adelie-targets.patch68
-rw-r--r--experimental/mrustc/adelie-targets.patch309
-rw-r--r--experimental/mrustc/mrustc-flags.patch20
-rw-r--r--experimental/mrustc/nuke-autodetection-logic.patch151
-rw-r--r--experimental/mrustc/ppc32-default-target-detect.patch16
-rw-r--r--experimental/mrustc/unified-outdir.patch11
7 files changed, 541 insertions, 73 deletions
diff --git a/experimental/mrustc/APKBUILD b/experimental/mrustc/APKBUILD
index 69891f37e..ebbe7b07d 100644
--- a/experimental/mrustc/APKBUILD
+++ b/experimental/mrustc/APKBUILD
@@ -24,12 +24,27 @@ source="mrustc-$pkgver.tar.gz::https://github.com/thepowersgang/mrustc/archive/r
0006-Codegen-C-Turn-down-gcc-optimisation-level-to-work-a.patch
0007-HIR-Typecheck-Properly-pass-type-params-to-const-eva.patch
- add-adelie-targets.patch
+ `#ppc32-default-target-detect.patch`
+ nuke-autodetection-logic.patch
+
+ unified-outdir.patch
+ mrustc-flags.patch
+
+ adelie-targets.patch
"
prepare() {
default_prepare
+ # force consistent default (only available) target
+ # after we nuke all the auto-detection logic, and
+ # note that "unknown" is required to avoid patching
+ # a ton of crates (though that is a better solution)
+ sed -i tools/common/target_detect.h \
+ -e "s/__DEFAULT_TARGET_NAME__/${CHOST}/g" \
+ -e "s/foxkit/unknown/g" \
+ ;
+
# use our cached copy and do not download during build
mv "${srcdir}"/rustc-${_rustcver}-src "${builddir}"/rustc-${_minorver}-src
}
@@ -38,11 +53,24 @@ build() {
# experimental but do you really want to build llvm with -j1?
export PARLEVEL="${JOBS}"
- export RUSTC_VERSION=${_minorver} MRUSTC_TARGET_VER=${_rustcver%.*} OUTDIR_SUF=-${_minorver}
+ # see 'adelie-targets.patch'
+ # the problem is that '--target' is not consistently applied to
+ # all stages of the bootstrap process, so things break
+# export MRUSTC_TARGET="${CHOST}"
+
+ export RUSTC_VERSION=${_minorver} MRUSTC_TARGET_VER=${_rustcver%.*}
make
make RUSTCSRC
+
+ # FIXME: this generates all the right code but does not execute 'gcc'
+ # (to generate the required objects) when '--target' is given (which
+ # is added due to explicit 'MRUSTC_TARGET' above). Run it manually if
+ # you use 'MRUSTC_TARGET' or comment it out if not. It appears that
+ # this happens due to the aforementioned inconsistent '--target' issue.
make -f minicargo.mk LIBS
+# _fix="$(find output-${_minorver} -name 'lib*_cmd.txt' | sort) output-${_minorver}/dump_cmd.txt"
+# for k in ${_fix}; do gcc @"${k}"; done
make test
make local_tests
@@ -53,8 +81,6 @@ build() {
}
check() {
- cd "${builddir}"
-
./output-${_minorver}/rustc --version
./output-${_minorver}/cargo --version
./output-${_minorver}/rustc samples/no_core.rs
@@ -79,4 +105,7 @@ debbc9d9a2d2398cd66987904ea62f26a64be078b97cbfa159e10b63c5fd2e1fbdf600a1326c9f6a
11fed26ae226c810b2f06f983f665639e146c3ef2da1b68d64586a35555de0b0e58e3e8765b5bc45085b237dfe74ca6c33e864bdf9d2e89f1be75050f63aa922 0005-Patches-Fix-it-this-time.patch
7e879056bf3debdaf469ef0b17cf91b6e61d8802094521b8df1d0c07f9d889897009e2987e3654c3560d03e3fa775b26ec11543c5ba630bc059c50f6bbc8145e 0006-Codegen-C-Turn-down-gcc-optimisation-level-to-work-a.patch
52a42716b73f13852c5507a9566250f174b6a87de0aed3752f5f54bdf25887930620b3c0ea597bdb86c33b8be00724fa94e5c38e156a7edadb3776e4c4a5fb39 0007-HIR-Typecheck-Properly-pass-type-params-to-const-eva.patch
-ef161a48c432c4338d48cf52ef45085aa8479ff13102af924a9f35d5786db90953163d79129f004eddc1dd67f41f7946228d211147d8b310a928548705079442 add-adelie-targets.patch"
+529e2dbd51f48f749e489fcf228c2ca56f7f1675f96d203f5447ac53cd6b9d0b2ec01af4f607f64f784a0cbeca6551cfba1434fe05e8d19165b674ecbe60c91f nuke-autodetection-logic.patch
+09cd2bd0329269ee4eaf656f1a367d51bc679f0a118035b38805a07520df48447a04518d0b6963039f3aa3cceab83b9914bb4f4ac15bac86bb124b8b36e70444 unified-outdir.patch
+ff49e3f096ff13018c7451e5770422388826a99b3e82b1d616ae0a8cf8383daf99faaf161e37c5d27160119039d318e20202a8a5a4893b7346fc4883fe2c9c3d mrustc-flags.patch
+1effb16522f9959f2d47aca885c7919a56fd0e3abd33212d242468ec25d21d949d298eb0c17ca65ed4542c33c9520d19bc6d92049a24f897d45318f1df305850 adelie-targets.patch"
diff --git a/experimental/mrustc/add-adelie-targets.patch b/experimental/mrustc/add-adelie-targets.patch
deleted file mode 100644
index e37171945..000000000
--- a/experimental/mrustc/add-adelie-targets.patch
+++ /dev/null
@@ -1,68 +0,0 @@
-diff -ur a/src/trans/target.cpp b/src/trans/target.cpp
---- a/src/trans/target.cpp 2024-12-16 21:41:45.380039459 +0000
-+++ b/src/trans/target.cpp 2024-12-16 21:49:00.640039666 +0000
-@@ -411,7 +411,9 @@
- {
- return load_spec_from_file(target_name);
- }
-- else if(target_name == "i586-linux-gnu" || target_name == "i586-unknown-linux-gnu")
-+ else if(target_name == "i586-linux-gnu" || target_name == "i586-unknown-linux-gnu"
-+ || target_name == "i586-linux-musl" || target_name == "i586-unknown-linux-musl"
-+ || target_name == "i686-linux-musl" || target_name == "i686-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "i586-linux-gnu", BACKEND_C_OPTS_GNU},
-@@ -439,42 +441,47 @@
- ARCH_X32
- };
- }
-- else if(target_name == "arm-linux-gnu" || target_name == "arm-unknown-linux-gnu")
-+ else if(target_name == "arm-linux-gnu" || target_name == "arm-unknown-linux-gnu"
-+ || target_name == "arm-linux-musl" || target_name == "arm-unknown-linux-musl"
-+ || target_name == "armv7l-linux-musl" || target_name == "armv7l-unknown-linux-musl"
-+ || target_name == "armv7-linux-musl" || target_name == "armv7-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "arm-elf-eabi", BACKEND_C_OPTS_GNU},
- ARCH_ARM32
- };
- }
-- else if(target_name == "aarch64-linux-gnu" || target_name == "aarch64-unknown-linux-gnu")
-+ else if(target_name == "aarch64-linux-gnu" || target_name == "aarch64-unknown-linux-gnu"
-+ || target_name == "aarch64-linux-musl" || target_name == "aarch64-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "aarch64-linux-gnu", BACKEND_C_OPTS_GNU},
- ARCH_ARM64
- };
- }
-- else if(target_name == "m68k-linux-gnu" || target_name == "m68k-unknown-linux-gnu")
-+ else if(target_name == "m68k-linux-gnu" || target_name == "m68k-unknown-linux-gnu"
-+ || target_name == "m68k-linux-musl" || target_name == "m68k-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "m68k-linux-gnu", BACKEND_C_OPTS_GNU},
- ARCH_M68K
- };
- }
-- else if(target_name == "powerpc64-unknown-linux-gnu")
-+ else if(target_name == "powerpc64-unknown-linux-gnu" || target_name == "powerpc64-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "powerpc64-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
- ARCH_POWERPC64
- };
- }
-- else if(target_name == "powerpc64le-unknown-linux-gnu")
-+ else if(target_name == "powerpc64le-unknown-linux-gnu" || target_name == "powerpc64le-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "powerpc64le-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
- ARCH_POWERPC64LE
- };
- }
-- else if(target_name == "riscv64-unknown-linux-gnu")
-+ else if(target_name == "riscv64-unknown-linux-gnu" || target_name == "riscv64-unknown-linux-musl")
- {
- return TargetSpec {
- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "riscv64-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
diff --git a/experimental/mrustc/adelie-targets.patch b/experimental/mrustc/adelie-targets.patch
new file mode 100644
index 000000000..c084538f7
--- /dev/null
+++ b/experimental/mrustc/adelie-targets.patch
@@ -0,0 +1,309 @@
+This two-step patch is for ease of patch maintenance only.
+
+diff -ur a/src/trans/target.cpp b/src/trans/target.cpp
+--- a/src/trans/target.cpp 2024-12-17 15:23:24.990000000 +0000
++++ b/src/trans/target.cpp 2024-12-17 15:23:59.900000000 +0000
+@@ -411,231 +411,6 @@
+ {
+ return load_spec_from_file(target_name);
+ }
+- else if(target_name == "i586-linux-gnu" || target_name == "i586-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "i586-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_X86
+- };
+- }
+- else if(target_name == "x86_64-linux-gnu" || target_name == "x86_64-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, true /*false*/, "x86_64-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "x86_64-linux-musl" || target_name == "x86_64-unknown-linux-musl")
+- {
+- return TargetSpec {
+- "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "x86_64-linux-musl", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "x86_64-unknown-linux-gnux32")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "x86_64-unknown-linux-gnux32", BACKEND_C_OPTS_GNU},
+- ARCH_X32
+- };
+- }
+- else if(target_name == "arm-linux-gnu" || target_name == "arm-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "arm-elf-eabi", BACKEND_C_OPTS_GNU},
+- ARCH_ARM32
+- };
+- }
+- else if(target_name == "aarch64-linux-gnu" || target_name == "aarch64-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "aarch64-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_ARM64
+- };
+- }
+- else if(target_name == "m68k-linux-gnu" || target_name == "m68k-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "m68k-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_M68K
+- };
+- }
+- else if(target_name == "powerpc64-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "powerpc64-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_POWERPC64
+- };
+- }
+- else if(target_name == "powerpc64le-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "powerpc64le-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_POWERPC64LE
+- };
+- }
+- else if(target_name == "riscv64-unknown-linux-gnu")
+- {
+- return TargetSpec {
+- "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "riscv64-unknown-linux-gnu", BACKEND_C_OPTS_GNU},
+- ARCH_RISCV64
+- };
+- }
+- else if(target_name == "i586-pc-windows-gnu")
+- {
+- return TargetSpec {
+- "windows", "windows", "gnu", {CodegenMode::Gnu11, true, "mingw32", BACKEND_C_OPTS_GNU},
+- ARCH_X86
+- };
+- }
+- else if(target_name == "x86_64-pc-windows-gnu")
+- {
+- return TargetSpec {
+- "windows", "windows", "gnu", {CodegenMode::Gnu11, false, "x86_64-w64-mingw32", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if (target_name == "x86-pc-windows-msvc")
+- {
+- // TODO: Should this include the "kernel32.lib" inclusion?
+- return TargetSpec {
+- "windows", "windows", "msvc", {CodegenMode::Msvc, true, "x86", {}, {}},
+- ARCH_X86
+- };
+- }
+- else if (target_name == "x86_64-pc-windows-msvc")
+- {
+- return TargetSpec {
+- "windows", "windows", "msvc", {CodegenMode::Msvc, true, "amd64", {}, {}},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "i686-unknown-freebsd")
+- {
+- return TargetSpec {
+- "unix", "freebsd", "gnu", {CodegenMode::Gnu11, true, "i686-unknown-freebsd", BACKEND_C_OPTS_GNU},
+- ARCH_X86
+- };
+- }
+- else if(target_name == "x86_64-unknown-freebsd")
+- {
+- return TargetSpec {
+- "unix", "freebsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-freebsd", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "arm-unknown-freebsd")
+- {
+- return TargetSpec {
+- "unix", "freebsd", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-freebsd", BACKEND_C_OPTS_GNU},
+- ARCH_ARM32
+- };
+- }
+- else if(target_name == "aarch64-unknown-freebsd")
+- {
+- return TargetSpec {
+- "unix", "freebsd", "gnu", {CodegenMode::Gnu11, false, "aarch64-unknown-freebsd", BACKEND_C_OPTS_GNU},
+- ARCH_ARM64
+- };
+- }
+- else if(target_name == "x86_64-unknown-netbsd")
+- {
+- return TargetSpec {
+- "unix", "netbsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-netbsd", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "i686-unknown-openbsd")
+- {
+- return TargetSpec {
+- "unix", "openbsd", "gnu", {CodegenMode::Gnu11, true, "i686-unknown-openbsd", BACKEND_C_OPTS_GNU},
+- ARCH_X86
+- };
+- }
+- else if(target_name == "x86_64-unknown-openbsd")
+- {
+- return TargetSpec {
+- "unix", "openbsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-openbsd", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "arm-unknown-openbsd")
+- {
+- return TargetSpec {
+- "unix", "openbsd", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-openbsd", BACKEND_C_OPTS_GNU},
+- ARCH_ARM32
+- };
+- }
+- else if(target_name == "aarch64-unknown-openbsd")
+- {
+- return TargetSpec {
+- "unix", "openbsd", "gnu", {CodegenMode::Gnu11, false, "aarch64-unknown-openbsd", BACKEND_C_OPTS_GNU},
+- ARCH_ARM64
+- };
+- }
+- else if(target_name == "x86_64-unknown-dragonfly")
+- {
+- return TargetSpec {
+- "unix", "dragonfly", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-dragonfly", BACKEND_C_OPTS_GNU},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "i686-apple-darwin")
+- {
+- // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets
+- // The first 32bit Intel Mac was Core Solo aka yonah. It allows to use `-march=yonah` like Rust.
+- return TargetSpec {
+- "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "x86_64-apple-darwin", {"-march=yonah"}, {}},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "x86_64-apple-darwin")
+- {
+- // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets
+- // The first 64bit Intel Mac was Core Duo. It allows to use `-march=core2` like Rust.
+- return TargetSpec {
+- "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "x86_64-apple-darwin", {"-march=core2"}, {}},
+- ARCH_X86_64
+- };
+- }
+- else if(target_name == "aarch64-apple-darwin")
+- {
+- // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets
+- return TargetSpec {
+- "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "aarch64-apple-darwin", {}, {}},
+- ARCH_ARM64
+- };
+- }
+- else if(target_name == "powerpc-apple-darwin")
+- {
+- // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets
+- return TargetSpec {
+- "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "powerpc-apple-darwin", {}, {}},
+- ARCH_POWERPC32
+- };
+- }
+- else if(target_name == "powerpc64-apple-darwin")
+- {
+- // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets
+- return TargetSpec {
+- "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "powerpc64-apple-darwin", {}, {}},
+- ARCH_POWERPC64
+- };
+- }
+- else if(target_name == "arm-unknown-haiku")
+- {
+- return TargetSpec {
+- "unix", "haiku", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-haiku", {}, {}},
+- ARCH_ARM32
+- };
+- }
+- else if(target_name == "x86_64-unknown-haiku")
+- {
+- return TargetSpec {
+- "unix", "haiku", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-haiku", {}, {}},
+- ARCH_X86_64
+- };
+- }
+ else
+ {
+ ::std::cerr << "Unknown target name '" << target_name << "'" << ::std::endl;
+--- a/src/trans/target.cpp 2024-12-17 15:27:49.410000000 +0000
++++ b/src/trans/target.cpp 2024-12-17 15:26:13.600000000 +0000
+@@ -411,6 +411,69 @@
+ {
+ return load_spec_from_file(target_name);
+ }
++ else if(target_name == "x86_64-foxkit-linux-musl" || target_name == "x86_64-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "x86_64-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_X86_64
++ };
++ }
++ else if(target_name == "i586-foxkit-linux-musl" || target_name == "i586-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "i586-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_X86
++ };
++ }
++ else if(target_name == "aarch64-foxkit-linux-musl" || target_name == "aarch64-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "aarch64-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_ARM64
++ };
++ }
++ else if(target_name == "armv7-foxkit-linux-musleabihf" || target_name == "armv7-unknown-linux-musleabihf")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "arm-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_ARM32
++ };
++ }
++ else if(target_name == "m68k-foxkit-linux-musl" || target_name == "m68k-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "m68k-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_M68K
++ };
++ }
++ else if(target_name == "powerpc64-foxkit-linux-musl" || target_name == "powerpc64-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "powerpc64-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_POWERPC64
++ };
++ }
++ else if(target_name == "powerpc64le-foxkit-linux-musl" || target_name == "powerpc64le-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "powerpc64le-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_POWERPC64LE
++ };
++ }
++ else if(target_name == "powerpc-foxkit-linux-musl" || target_name == "powerpc-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "powerpc-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_POWERPC32
++ };
++ }
++ else if(target_name == "riscv64-foxkit-linux-musl" || target_name == "riscv64-unknown-linux-musl")
++ {
++ return TargetSpec {
++ "unix", "linux", "musl", {CodegenMode::Gnu11, true /*false*/, "riscv64-linux-musl", BACKEND_C_OPTS_GNU},
++ ARCH_RISCV64
++ };
++ }
+ else
+ {
+ ::std::cerr << "Unknown target name '" << target_name << "'" << ::std::endl;
diff --git a/experimental/mrustc/mrustc-flags.patch b/experimental/mrustc/mrustc-flags.patch
new file mode 100644
index 000000000..3e159fa2b
--- /dev/null
+++ b/experimental/mrustc/mrustc-flags.patch
@@ -0,0 +1,20 @@
+diff -ur a/minicargo.mk b/minicargo.mk
+--- a/minicargo.mk 2024-12-17 17:08:13.022785295 +0000
++++ b/minicargo.mk 2024-12-17 17:09:23.464691993 +0000
+@@ -64,6 +64,7 @@
+ ifeq ($(MRUSTC_TARGET),)
+ else
+ MINICARGO_FLAGS += --target $(MRUSTC_TARGET)
++ MRUSTC_FLAGS += --target $(MRUSTC_TARGET)
+ endif
+
+ OUTDIR := output$(OUTDIR_SUF)/
+@@ -322,7 +323,7 @@
+ $(OUTDIR)rust/test_run-pass_hello: $(SRCDIR_RUST_TESTS)$(HELLO_TEST) LIBS
+ @mkdir -p $(dir $@)
+ @echo "--- [MRUSTC] -o $@"
+- $(DBG) $(MRUSTC) $< -o $@ --cfg debug_assertions -g -O -L $(OUTDIR) > $@_dbg.txt
++ $(DBG) $(MRUSTC) $< -o $@ --cfg debug_assertions -g -O -L $(OUTDIR) $(MRUSTC_FLAGS) > $@_dbg.txt
+ $(OUTDIR)rust/test_run-pass_hello_out.txt: $(OUTDIR)rust/test_run-pass_hello
+ @echo "--- [$<]"
+ @./$< | tee $@
diff --git a/experimental/mrustc/nuke-autodetection-logic.patch b/experimental/mrustc/nuke-autodetection-logic.patch
new file mode 100644
index 000000000..f346354dd
--- /dev/null
+++ b/experimental/mrustc/nuke-autodetection-logic.patch
@@ -0,0 +1,151 @@
+diff -ur a/tools/common/target_detect.h b/tools/common/target_detect.h
+--- a/tools/common/target_detect.h 2024-12-17 16:28:39.125914049 +0000
++++ b/tools/common/target_detect.h 2024-12-17 16:31:53.023716535 +0000
+@@ -7,146 +7,4 @@
+ */
+ #pragma once
+
+-// - Windows (MSVC)
+-#ifdef _MSC_VER
+-# if defined(_WIN64)
+-# define DEFAULT_TARGET_NAME "x86_64-pc-windows-msvc"
+-# else
+-# define DEFAULT_TARGET_NAME "x86-pc-windows-msvc"
+-# endif
+-// - Linux
+-#elif defined(__linux__)
+-# ifndef _GNU_SOURCE
+-# define _GNU_SOURCE
+-# endif
+-# include <features.h>
+-# if defined(__amd64__)
+-# if defined(_ILP32)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-linux-gnux32"
+-# elif defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-linux-musl"
+-# endif
+-# elif defined(__aarch64__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "aarch64-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "aarch64-unknown-linux-musl"
+-# endif
+-# elif defined(__arm__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "arm-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "arm-unknown-linux-musl"
+-# endif
+-# elif defined(__i386__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "i586-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "i586-unknown-linux-musl"
+-# endif
+-# elif defined(__m68k__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "m68k-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "m68k-unknown-linux-musl"
+-# endif
+-# elif defined(__powerpc64__) && defined(__BIG_ENDIAN__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "powerpc64-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "powerpc64-unknown-linux-musl"
+-# endif
+-# elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "powerpc64le-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "powerpc64le-unknown-linux-musl"
+-# endif
+-# elif defined(__riscv) && __riscv_xlen == 64
+-# if defined(__USE_GNU)
+-# define DEFAULT_TARGET_NAME "riscv64-unknown-linux-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "riscv64-unknown-linux-musl"
+-# endif
+-# else
+-# warning "Unable to detect a suitable default target (linux-gnu)"
+-# endif
+-// - msys/cygwin
+-#elif defined(__CYGWIN__)
+-# if defined(__x86_64__)
+-# define DEFAULT_TARGET_NAME "x86_64-pc-windows-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "i586-pc-windows-gnu"
+-# endif
+-// - MinGW
+-#elif defined(__MINGW32__)
+-# if defined(_WIN64)
+-# define DEFAULT_TARGET_NAME "x86_64-pc-windows-gnu"
+-# else
+-# define DEFAULT_TARGET_NAME "i586-pc-windows-gnu"
+-# endif
+-// - FreeBSD
+-#elif defined(__FreeBSD__)
+-# if defined(__amd64__)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-freebsd"
+-# elif defined(__aarch64__)
+-# define DEFAULT_TARGET_NAME "aarch64-unknown-freebsd"
+-# elif defined(__arm__)
+-# define DEFAULT_TARGET_NAME "arm-unknown-freebsd"
+-# elif defined(__i386__)
+-# define DEFAULT_TARGET_NAME "i686-unknown-freebsd"
+-# else
+-# warning "Unable to detect a suitable default target (FreeBSD)"
+-# endif
+-// - NetBSD
+-#elif defined(__NetBSD__)
+-# if defined(__amd64__)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-netbsd"
+-# else
+-# warning "Unable to detect a suitable default target (NetBSD)"
+-# endif
+-// - OpenBSD
+-#elif defined(__OpenBSD__)
+-# if defined(__amd64__)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-openbsd"
+-# elif defined(__aarch64__)
+-# define DEFAULT_TARGET_NAME "aarch64-unknown-openbsd"
+-# elif defined(__arm__)
+-# define DEFAULT_TARGET_NAME "arm-unknown-openbsd"
+-# elif defined(__i386__)
+-# define DEFAULT_TARGET_NAME "i686-unknown-openbsd"
+-# else
+-# warning "Unable to detect a suitable default target (OpenBSD)"
+-# endif
+-// - DragonFly
+-#elif defined(__DragonFly__)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-dragonfly"
+-// - Apple devices
+-#elif defined(__APPLE__)
+-# if defined(__aarch64__)
+-# define DEFAULT_TARGET_NAME "aarch64-apple-darwin"
+-# elif defined(__ppc64__)
+-# define DEFAULT_TARGET_NAME "powerpc64-apple-darwin"
+-# elif defined(__ppc__)
+-# define DEFAULT_TARGET_NAME "powerpc-apple-darwin"
+-# else
+-# define DEFAULT_TARGET_NAME "x86_64-apple-darwin"
+-#endif
+-// - Haiku
+-#elif defined(__HAIKU__)
+-# if defined(__x86_64__)
+-# define DEFAULT_TARGET_NAME "x86_64-unknown-haiku"
+-# elif defined(__arm__)
+-# define DEFAULT_TARGET_NAME "arm-unknown-haiku"
+-# else
+-# warning "Unable to detect a suitable default target (Haiku)"
+-# endif
+-// - Unknown
+-#else
+-# warning "Unable to detect a suitable default target"
+-#endif
+-#ifndef DEFAULT_TARGET_NAME
+-# define DEFAULT_TARGET_NAME ""
+-#endif
++#define DEFAULT_TARGET_NAME "__DEFAULT_TARGET_NAME__"
diff --git a/experimental/mrustc/ppc32-default-target-detect.patch b/experimental/mrustc/ppc32-default-target-detect.patch
new file mode 100644
index 000000000..a138c442d
--- /dev/null
+++ b/experimental/mrustc/ppc32-default-target-detect.patch
@@ -0,0 +1,16 @@
+diff -ur a/tools/common/target_detect.h b/tools/common/target_detect.h
+--- a/tools/common/target_detect.h 2024-12-17 14:27:52.560000000 +0000
++++ b/tools/common/target_detect.h 2024-12-17 14:37:17.320000000 +0000
+@@ -64,6 +64,12 @@
+ # else
+ # define DEFAULT_TARGET_NAME "powerpc64le-unknown-linux-musl"
+ # endif
++# elif defined(__powerpc__) && defined(__BIG_ENDIAN__)
++# if defined(__USE_GNU)
++# define DEFAULT_TARGET_NAME "powerpc-unknown-linux-gnu"
++# else
++# define DEFAULT_TARGET_NAME "powerpc-unknown-linux-musl"
++# endif
+ # elif defined(__riscv) && __riscv_xlen == 64
+ # if defined(__USE_GNU)
+ # define DEFAULT_TARGET_NAME "riscv64-unknown-linux-gnu"
diff --git a/experimental/mrustc/unified-outdir.patch b/experimental/mrustc/unified-outdir.patch
new file mode 100644
index 000000000..ce9deb43d
--- /dev/null
+++ b/experimental/mrustc/unified-outdir.patch
@@ -0,0 +1,11 @@
+diff -ur a/minicargo.mk b/minicargo.mk
+--- a/minicargo.mk 2024-12-17 17:03:27.123139037 +0000
++++ b/minicargo.mk 2024-12-17 17:03:58.331964813 +0000
+@@ -64,7 +64,6 @@
+ ifeq ($(MRUSTC_TARGET),)
+ else
+ MINICARGO_FLAGS += --target $(MRUSTC_TARGET)
+- OUTDIR_SUF := $(OUTDIR_SUF)-$(MRUSTC_TARGET)
+ endif
+
+ OUTDIR := output$(OUTDIR_SUF)/