diff options
| author | Alexander Hill <ahill@breadpudding.dev> | 2025-05-06 23:37:40 -0400 |
|---|---|---|
| committer | Alexander Hill <ahill@breadpudding.dev> | 2025-05-06 23:37:40 -0400 |
| commit | c971eb2f31746e5e6c84c12baa4009e7b2764ba8 (patch) | |
| tree | 29254e2bc5b47512fd0c24102da6e627ca4f9fbc | |
| parent | 2aeb13e7ee3f70e85f85bae9e77c2d3e1a10f94a (diff) | |
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>
| -rwxr-xr-x | build-bootstrap.sh | 1 | ||||
| -rwxr-xr-x | build-chroot.sh | 23 | ||||
| -rwxr-xr-x | chroot-bootstrap.sh | 9 | ||||
| -rw-r--r-- | patches/mrustc-maple.patch | 399 |
4 files changed, 415 insertions, 17 deletions
diff --git a/build-bootstrap.sh b/build-bootstrap.sh index 8abc50a..3c7611e 100755 --- a/build-bootstrap.sh +++ b/build-bootstrap.sh @@ -19,6 +19,7 @@ mkdir -p $MAPLE/lib # libc++ fails to link without it, but this should be fixed via a # configuration change in LLVM. ~ahill ln -s . $MAPLE/lib/$HOST +mkdir -p $MAPLE/maple/patches mkdir -p $MAPLE/maple/sources mkdir -p $MAPLE/mnt mkdir -p $MAPLE/proc diff --git a/build-chroot.sh b/build-chroot.sh index 8d401fa..a365b69 100755 --- a/build-chroot.sh +++ b/build-chroot.sh @@ -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 diff --git a/chroot-bootstrap.sh b/chroot-bootstrap.sh index 5fe43d0..f23e0b2 100755 --- a/chroot-bootstrap.sh +++ b/chroot-bootstrap.sh @@ -16,7 +16,14 @@ if mount --rbind /dev $MAPLE/dev && mount --make-rslave $MAPLE/dev; then if mount --bind /run $MAPLE/run; then if [ -d $MAPLE/maple/sources ]; then if mount --bind ./sources $MAPLE/maple/sources; then - run_chroot + if [ -d $MAPLE/maple/patches ]; then + if mount --bind ./patches $MAPLE/maple/patches; then + run_chroot + umount $MAPLE/maple/patches + fi + else + run_chroot + fi umount $MAPLE/maple/sources fi else diff --git a/patches/mrustc-maple.patch b/patches/mrustc-maple.patch new file mode 100644 index 0000000..37f4a82 --- /dev/null +++ b/patches/mrustc-maple.patch @@ -0,0 +1,399 @@ +diff -ruN mrustc-0.11.2.orig/src/ast/ast.cpp mrustc-0.11.2/src/ast/ast.cpp +--- mrustc-0.11.2.orig/src/ast/ast.cpp 2025-05-05 19:48:49.015447489 -0400 ++++ mrustc-0.11.2/src/ast/ast.cpp 2025-05-06 21:59:55.063318921 -0400 +@@ -243,9 +243,9 @@ + + Function::Function(Span sp, ::std::string abi, Flags flags, GenericParams params, TypeRef ret_type, Arglist args, bool is_variadic): + m_span(sp), +- m_params( move(params) ), +- m_rettype( move(ret_type) ), +- m_args( move(args) ), ++ m_params( std::move(params) ), ++ m_rettype( std::move(ret_type) ), ++ m_args( std::move(args) ), + m_is_variadic(is_variadic), + m_abi( mv$(abi) ), + m_flags(flags) +diff -ruN mrustc-0.11.2.orig/src/ast/ast.hpp mrustc-0.11.2/src/ast/ast.hpp +--- mrustc-0.11.2.orig/src/ast/ast.hpp 2025-05-05 19:48:49.015447489 -0400 ++++ mrustc-0.11.2/src/ast/ast.hpp 2025-05-06 22:00:48.786212819 -0400 +@@ -101,8 +101,8 @@ + + //TypeAlias() {} + TypeAlias(GenericParams params, TypeRef type): +- m_params( move(params) ), +- m_type( move(type) ) ++ m_params( std::move(params) ), ++ m_type( std::move(type) ) + {} + static TypeAlias new_associated_type(GenericParams params, GenericParams type_bounds, TypeRef default_type) { + TypeAlias rv { std::move(params), std::move(default_type) }; +@@ -164,8 +164,8 @@ + + Static(Class s_class, TypeRef type, Expr value): + m_class(s_class), +- m_type( move(type) ), +- m_value( move(value) ) ++ m_type( std::move(type) ), ++ m_value( std::move(value) ) + {} + + const Class& s_class() const { return m_class; } +@@ -421,8 +421,8 @@ + + Enum() {} + Enum( GenericParams params, ::std::vector<EnumVariant> variants ): +- m_params( move(params) ), +- m_variants( move(variants) ) ++ m_params( std::move(params) ), ++ m_variants( std::move(variants) ) + {} + + const GenericParams& params() const { return m_params; } +@@ -483,11 +483,11 @@ + { + } + Struct( GenericParams params, ::std::vector<StructItem> fields ): +- m_params( move(params) ), ++ m_params( std::move(params) ), + m_data( StructData::make_Struct({mv$(fields)}) ) + {} + Struct( GenericParams params, ::std::vector<TupleItem> fields ): +- m_params( move(params) ), ++ m_params( std::move(params) ), + m_data( StructData::make_Tuple({mv$(fields)}) ) + {} + +@@ -511,7 +511,7 @@ + } m_markings; + + Union( GenericParams params, ::std::vector<StructItem> fields ): +- m_params( move(params) ), ++ m_params( std::move(params) ), + m_variants( mv$(fields) ) + {} + +diff -ruN mrustc-0.11.2.orig/src/ast/expr.hpp mrustc-0.11.2/src/ast/expr.hpp +--- mrustc-0.11.2.orig/src/ast/expr.hpp 2025-05-05 19:48:49.015447489 -0400 ++++ mrustc-0.11.2/src/ast/expr.hpp 2025-05-06 22:01:28.556431607 -0400 +@@ -76,8 +76,8 @@ + m_block_type(type), + m_yields_final_value(yields_final_value), + m_label(""), +- m_local_mod( move(local_mod) ), +- m_nodes( move(nodes) ) ++ m_local_mod( std::move(local_mod) ), ++ m_nodes( std::move(nodes) ) + { + } + +@@ -106,9 +106,9 @@ + bool m_is_braced; + + ExprNode_Macro(AST::Path name, RcString ident, ::TokenTree&& tokens, bool is_braced=false): +- m_path( move(name) ), ++ m_path( std::move(name) ), + m_ident(ident), +- m_tokens( move(tokens) ) ++ m_tokens( std::move(tokens) ) + , m_is_braced(is_braced) + {} + +@@ -132,11 +132,11 @@ + ::std::vector<::std::string> m_flags; + + ExprNode_Asm(::std::string text, ::std::vector<ValRef> output, ::std::vector<ValRef> input, ::std::vector<::std::string> clobbers, ::std::vector<::std::string> flags): +- m_text( move(text) ), +- m_output( move(output) ), +- m_input( move(input) ), +- m_clobbers( move(clobbers) ), +- m_flags( move(flags) ) ++ m_text( std::move(text) ), ++ m_output( std::move(output) ), ++ m_input( std::move(input) ), ++ m_clobbers( std::move(clobbers) ), ++ m_flags( std::move(flags) ) + { + } + +@@ -169,8 +169,8 @@ + + ExprNode_Asm2(AsmCommon::Options options, std::vector<AsmCommon::Line> lines, std::vector<Param> params) + : m_options(options) +- , m_lines( move(lines) ) +- , m_params( move(params) ) ++ , m_lines( std::move(lines) ) ++ , m_params( std::move(params) ) + { + } + +@@ -194,8 +194,8 @@ + + ExprNode_Flow(Type type, Ident target, ExprNodeP value): + m_type(type), +- m_target( move(target) ), +- m_value( move(value) ) ++ m_target( std::move(target) ), ++ m_value( std::move(value) ) + { + } + +@@ -212,10 +212,10 @@ + ::std::pair<unsigned,unsigned> m_letelse_slots; + + ExprNode_LetBinding(Pattern pat, TypeRef type, ExprNodeP value, ExprNodeP else_arm={}) +- : m_pat( move(pat) ) +- , m_type( move(type) ) +- , m_value( move(value) ) +- , m_else( move(else_arm) ) ++ : m_pat( std::move(pat) ) ++ , m_type( std::move(type) ) ++ , m_value( std::move(value) ) ++ , m_else( std::move(else_arm) ) + { + } + +@@ -237,8 +237,8 @@ + ExprNode_Assign(): m_op(NONE) {} + ExprNode_Assign(Operation op, ExprNodeP slot, ExprNodeP value): + m_op(op), +- m_slot( move(slot) ), +- m_value( move(value) ) ++ m_slot( std::move(slot) ), ++ m_value( std::move(value) ) + { + } + +@@ -251,8 +251,8 @@ + ::std::vector<ExprNodeP> m_args; + + ExprNode_CallPath(Path&& path, ::std::vector<ExprNodeP>&& args): +- m_path( move(path) ), +- m_args( move(args) ) ++ m_path( std::move(path) ), ++ m_args( std::move(args) ) + { + } + +@@ -266,9 +266,9 @@ + ::std::vector<ExprNodeP> m_args; + + ExprNode_CallMethod(ExprNodeP obj, PathNode method, ::std::vector<ExprNodeP> args): +- m_val( move(obj) ), +- m_method( move(method) ), +- m_args( move(args) ) ++ m_val( std::move(obj) ), ++ m_method( std::move(method) ), ++ m_args( std::move(args) ) + { + } + +@@ -282,8 +282,8 @@ + ::std::vector<ExprNodeP> m_args; + + ExprNode_CallObject(ExprNodeP val, ::std::vector< ExprNodeP >&& args): +- m_val( move(val) ), +- m_args( move(args) ) ++ m_val( std::move(val) ), ++ m_args( std::move(args) ) + { + } + NODE_METHODS(); +@@ -531,9 +531,9 @@ + t_values m_values; + + ExprNode_StructLiteral(Path path, ExprNodeP base_value, t_values&& values ): +- m_path( move(path) ), +- m_base_value( move(base_value) ), +- m_values( move(values) ) ++ m_path( std::move(path) ), ++ m_base_value( std::move(base_value) ), ++ m_values( std::move(values) ) + {} + + NODE_METHODS(); +@@ -548,8 +548,8 @@ + t_values m_values; + + ExprNode_StructLiteralPattern(Path path, t_values&& values) +- : m_path( move(path) ) +- , m_values( move(values) ) ++ : m_path( std::move(path) ) ++ , m_values( std::move(values) ) + {} + + NODE_METHODS(); +@@ -646,8 +646,8 @@ + TypeRef m_type; + + ExprNode_Cast(ExprNodeP value, TypeRef&& dst_type): +- m_value( move(value) ), +- m_type( move(dst_type) ) ++ m_value( std::move(value) ), ++ m_type( std::move(dst_type) ) + { + } + NODE_METHODS(); +@@ -661,8 +661,8 @@ + TypeRef m_type; + + ExprNode_TypeAnnotation(ExprNodeP value, TypeRef&& dst_type): +- m_value( move(value) ), +- m_type( move(dst_type) ) ++ m_value( std::move(value) ), ++ m_type( std::move(dst_type) ) + { + } + NODE_METHODS(); +diff -ruN mrustc-0.11.2.orig/src/ast/lifetime_ref.hpp mrustc-0.11.2/src/ast/lifetime_ref.hpp +--- mrustc-0.11.2.orig/src/ast/lifetime_ref.hpp 2025-05-05 20:46:46.568398964 -0400 ++++ mrustc-0.11.2/src/ast/lifetime_ref.hpp 2025-05-05 19:59:44.934652489 -0400 +@@ -6,6 +6,7 @@ + * - AST Lifetime reference + */ + #pragma once ++#include <cstdint> + #include "../common.hpp" + #include "ident.hpp" + +diff -ruN mrustc-0.11.2.orig/src/debug.cpp mrustc-0.11.2/src/debug.cpp +--- mrustc-0.11.2.orig/src/debug.cpp 2025-05-05 20:46:46.568562659 -0400 ++++ mrustc-0.11.2/src/debug.cpp 2025-05-05 19:57:59.149549205 -0400 +@@ -5,6 +5,7 @@ + * debug.cpp + * - Debug printing (with indenting) + */ ++#include <cstdint> + #include <debug_inner.hpp> + #include <debug.hpp> + #include <set> +diff -ruN mrustc-0.11.2.orig/src/hir/expr.hpp mrustc-0.11.2/src/hir/expr.hpp +--- mrustc-0.11.2.orig/src/hir/expr.hpp 2025-05-05 19:48:49.017523096 -0400 ++++ mrustc-0.11.2/src/hir/expr.hpp 2025-05-06 22:02:51.568333466 -0400 +@@ -156,8 +156,8 @@ + ExprNode_Asm2(Span sp, AsmCommon::Options options, std::vector<AsmCommon::Line> lines, std::vector<Param> params) + : ExprNode(mv$(sp)) + , m_options(options) +- , m_lines( move(lines) ) +- , m_params( move(params) ) ++ , m_lines( std::move(lines) ) ++ , m_params( std::move(params) ) + { + } + +diff -ruN mrustc-0.11.2.orig/src/hir/generic_ref.hpp mrustc-0.11.2/src/hir/generic_ref.hpp +--- mrustc-0.11.2.orig/src/hir/generic_ref.hpp 2025-05-05 20:46:46.568679102 -0400 ++++ mrustc-0.11.2/src/hir/generic_ref.hpp 2025-05-05 19:59:36.463727568 -0400 +@@ -6,6 +6,7 @@ + * - Reference to a generic + */ + #pragma once ++#include <cstdint> + #include <rc_string.hpp> + + /// Binding index for a Generic that indicates "Self" +diff -ruN mrustc-0.11.2.orig/src/hir/type_ref.hpp mrustc-0.11.2/src/hir/type_ref.hpp +--- mrustc-0.11.2.orig/src/hir/type_ref.hpp 2025-05-05 20:46:46.568770980 -0400 ++++ mrustc-0.11.2/src/hir/type_ref.hpp 2025-05-05 19:59:57.743537961 -0400 +@@ -7,6 +7,7 @@ + */ + #pragma once + ++#include <cstdint> + #include <rc_string.hpp> + #include <span.hpp> + +diff -ruN mrustc-0.11.2.orig/src/macro_rules/macro_rules.hpp mrustc-0.11.2/src/macro_rules/macro_rules.hpp +--- mrustc-0.11.2.orig/src/macro_rules/macro_rules.hpp 2025-05-05 19:48:49.012008507 -0400 ++++ mrustc-0.11.2/src/macro_rules/macro_rules.hpp 2025-05-06 22:02:05.491732403 -0400 +@@ -102,7 +102,7 @@ + name( op ), + name_index(index), + tok( mv$(sep) ), +- subpats( move(ents) ), ++ subpats( std::move(ents) ), + type(PAT_LOOP) + { + } +diff -ruN mrustc-0.11.2.orig/src/trans/codegen_c.cpp mrustc-0.11.2/src/trans/codegen_c.cpp +--- mrustc-0.11.2.orig/src/trans/codegen_c.cpp 2025-05-05 19:48:49.014366958 -0400 ++++ mrustc-0.11.2/src/trans/codegen_c.cpp 2025-05-06 22:09:34.173707709 -0400 +@@ -1287,10 +1287,11 @@ + break; + } + // HACK: Work around [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117423] by disabling an optimisation stage +- if( opt.opt_level > 0 ) ++ // Disabled for Maple Linux. See build-chroot.sh for details. ~ahill ++ /* if( opt.opt_level > 0 ) + { + args.push_back("-fno-tree-sra"); +- } ++ } */ + if( opt.emit_debug_info ) + { + args.push_back("-g"); +@@ -4785,7 +4786,8 @@ + switch (v.first[0]) + { + case '=': m_of << "="; break; +- case '+': m_of << "+"; break; ++ // Patched for Maple Linux. See build-chroot.sh for details. ~ahill ++ case '+': m_of << "="; break; + default: MIR_TODO(mir_res, "Handle asm! output leader '" << v.first[0] << "'"); + } + m_of << H::convert_reg(v.first.c_str() + 1); +@@ -5428,12 +5430,14 @@ + if(i != 0) m_of << ","; + m_of << " "; + m_of << "\""; +- if( !p.output && !p.input ) { ++ // Patched for Maple Linux. See build-chroot.sh for details. ~ahill ++ m_of << "="; ++ /*if( !p.output && !p.input ) { + m_of << "+"; + } + else { + m_of << (p.input ? "+" : "="); +- } ++ }*/ + TU_MATCH_HDRA((p.spec), {) + TU_ARMA(Class, c) + // https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html +diff -ruN mrustc-0.11.2.orig/src/trans/target.cpp mrustc-0.11.2/src/trans/target.cpp +--- mrustc-0.11.2.orig/src/trans/target.cpp 2025-05-05 19:48:49.014366958 -0400 ++++ mrustc-0.11.2/src/trans/target.cpp 2025-05-06 22:07:39.775297252 -0400 +@@ -405,7 +405,8 @@ + TargetSpec init_from_spec_name(const ::std::string& target_name) + { + // Options for all the fully-GNU environments +- #define BACKEND_C_OPTS_GNU {"-ffunction-sections", "-pthread"}, {"-Wl,--start-group"}, {"-Wl,--end-group", "-Wl,--gc-sections", "-l", "atomic"} ++ // Patched for Maple Linux. See build-chroot.sh for details. ~ahill ++ #define BACKEND_C_OPTS_GNU {"-ffunction-sections", "-pthread"}, {"-Wl,--start-group"}, {"-Wl,--end-group", "-Wl,--gc-sections"} + // If there's a '/' or a '\' in the filename, open it as a path, otherwise assume it's a triple. + if( target_name.find('/') != ::std::string::npos || target_name.find('\\') != ::std::string::npos ) + { +diff -ruN mrustc-0.11.2.orig/tools/minicargo/build.cpp mrustc-0.11.2/tools/minicargo/build.cpp +--- mrustc-0.11.2.orig/tools/minicargo/build.cpp 2025-05-05 20:46:46.568933202 -0400 ++++ mrustc-0.11.2/tools/minicargo/build.cpp 2025-05-06 22:49:13.710034817 -0400 +@@ -19,6 +19,7 @@ + #include "os.hpp" + #include <fstream> + #include <cassert> ++#include <cstdint> + + #include <unordered_map> + #include <algorithm> // sort/find_if +@@ -823,9 +824,10 @@ + if( true ) { + args.push_back("--cfg"); args.push_back("debug_assertions"); + } +- if( true /*parent.m_opts.enable_optimise*/ ) { +- args.push_back("-O"); +- } ++ // Patched for Maple Linux. See build-chroot.sh for details. ~ahill ++ //if( true /*parent.m_opts.enable_optimise*/ ) { ++ // args.push_back("-O"); ++ //} + if( parent.m_opts.emit_mmir ) { + args.push_back("-C"); args.push_back("codegen-type=monomir"); + } |
