Built a version of cargo and rustc that won't crash

Co-authored-by: Alexander Hill <ahill@breadpudding.dev>
Co-authored-by: Nicholas McDaniel <nickmcdaniel00@gmail.com>
This commit is contained in:
Alexander Hill
2025-05-06 23:37:40 -04:00
parent 2aeb13e7ee
commit c971eb2f31
4 changed files with 415 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
#!/bin/sh -e
CFLAGS="-O3 -march=skylake -pipe"
CXXFLAGS="$CFLAGS"
export CC=clang
export CXX=clang++
export CFLAGS="-O3 -march=skylake -pipe"
export CXXFLAGS="$CFLAGS"
THREADS=$(nproc)
mkdir -p build
@@ -743,32 +745,21 @@ cd ..
tar xf ../sources/mrustc-*.tar*
cd mrustc-*/
# NOTE: Using types such as uint8_t without stdint.h is not portable. ~ahill
sed -i "1i #include <cstdint>" src/debug.cpp
sed -i "1i #include <cstdint>" src/ast/lifetime_ref.hpp
sed -i "1i #include <cstdint>" src/hir/generic_ref.hpp
sed -i "1i #include <cstdint>" src/hir/type_ref.hpp
sed -i "1i #include <cstdint>" tools/minicargo/build.cpp
# NOTE: LLVM loves yelling about unqualified std calls, so we'll just fix them
# so we can properly troubleshoot why this doesn't work. ~ahill
sed -i -r "s/ move\(([a-z_]+)\)/ std::move\(\1\)/g" src/ast/ast.cpp
sed -i -r "s/ move\(([a-z_]+)\)/ std::move\(\1\)/g" src/ast/ast.hpp
sed -i -r "s/ move\(([a-z_]+)\)/ std::move\(\1\)/g" src/ast/expr.hpp
sed -i -r "s/ move\(([a-z_]+)\)/ std::move\(\1\)/g" src/macro_rules/macro_rules.hpp
sed -i -r "s/ move\(([a-z_]+)\)/ std::move\(\1\)/g" src/hir/expr.hpp
# NOTE: mrustc passes -fno-tree-sra to the GCC to work around a bug that is
# present when it comes to linking, however clang has no idea what that
# means. ~ahill
sed -i "s/-fno-tree-sra//" src/trans/codegen_c.cpp
# NOTE: mrustc converts Rust's asm! macro into inline Assembly in C, which seems
# to work on GCC, but is broken on LLVM. Using the input constraint "0"
# with the output constraint prefix "+" causes an error. Substituting "+"
# with "=" seems to fix this problem. ~ahill
sed -i "s/m_of << \"+\";/m_of << \"=\";/" src/trans/codegen_c.cpp
sed -i "s/m_of << \(p\.input \? \"+\" : \"=\"\);/m_of << \"=\";/" src/trans/codegen_c.cpp
# NOTE: mrustc forces the system to link with libatomic because it's assuming
# that libgcc exists, even though it doesn't in this case. compiler-rt
# supplies the functionality we need, so this is not required. ~ahill
sed -i "/#define BACKEND_C_OPTS_GNU/s/, \"-l\", \"atomic\"//" src/trans/target.cpp
# FIXME: The optimize(-O) flag has been patched out of minicargo because clang
# optimizes essential parts of code generated by mrustc. ~ahill
patch -p1 < /maple/patches/mrustc-maple.patch
# NOTE: Rust's unwind crate attempts to link with libgcc_s, even on a musl-based
# system. Enabling the "system-llvm-unwind" feature fixes this. ~ahill
echo "[add.'library/panic_unwind'.dependencies.unwind]" >> rustc-$RUST_VERSION-overrides.toml