Skip to content
Alternative rust compiler (re-implementation)
Branch: master
Clone or download
thepowersgang Merge pull request #116 from notriddle/master
Allow square brackets in macro definitions
Latest commit ebd8ede May 29, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Notes Merge branch 'master' of Jun 3, 2018
bnf No more tears! Dec 25, 2016
docs Docs - Rough documentation on invoking minicargo/mrustc Jun 3, 2018
lib/libproc_macro libproc_macro - Minor bugfix Jul 8, 2018
run_rustc Makefiles - tweaking Nov 27, 2017
samples Allow square brackets in macro definitions May 28, 2019
script-overrides Script overrides - Include macos libc, add note about origin Jun 3, 2018
scripts Scripts - Make the MIR->DOT script more useful Feb 25, 2018
src Allow square brackets in macro definitions May 28, 2019
tools minicargo - Fix infinite printing in build script error reporting if … Feb 23, 2019
vsproject vsproject scripts - Add libproc_macro Feb 23, 2019
.gitignore gitignore - Update a bit Apr 1, 2018
.lvimrc lvimrc - Bump comment width Nov 25, 2017
.travis.yml Travis - Set compiler for generated code Feb 24, 2019
LICENCE-MIT Add licence (MIT) Jun 13, 2016
Makefile Makefile - Add libcore-test Feb 9, 2019 Add Travis/Appveyor badges, tweak appveyor config Dec 22, 2018 TestRustcBootstrap - Enable vendoring (avoids libgit2 problems on ubu… Dec 16, 2017
appveyor.yml Appveyor - twiddling Dec 22, 2018
disabled_tests_run-pass.txt Merge branch 'master' of Jun 3, 2018 - Random test target Sep 15, 2018
mrustc.cbp Move source files to src/ folder Dec 23, 2014
rust-nightly-date Update target version to known-good Sep 2, 2017
rust-version Makefile - Switch to 1.19 by default Sep 30, 2017
rust_src.patch Makefile - Switch to 1.19 by default Sep 30, 2017 Standalone MIRI - Fix parse errors from mrustc changes, add recursion… Jun 3, 2018

Mutabah's Rust Compiler

In-progress alternative rust compiler. Capable of building a fully-working copy of rustc, but not yet suitable for everyday use.

Build Status: windows Build Status: Linux/OSX


This project is an attempt at creating a simple rust compiler in C++, with the ultimate goal of being a separate re-implementation.

mrustc works by compiling assumed-valid rust code (i.e. without borrow checking) into a high-level assembly (currently using C, but LLVM/cretonne or even direct machine code could work) and getting an external code generator to turn that into optimised machine code. This works because the borrow checker doesn't have any impact on the generated code, just in checking that the code would be valid.


  • Supported Targets:
    • x86-64 linux
    • (incomplete) x86 windows
    • (incomplete) x86-64 windows
  • Builds working copies of rustc and cargo from a release source tarball
  • rustc bootstrap tested and validated
    • See the script for how this was done.

Getting Started


  • C++14-compatible compiler (tested with gcc 5.4 and gcc 6)
  • C11 compatible C compiler (for output, see above)
  • make (for the mrustc makefiles)
  • patch (For doing minor edits to the rustc source)
  • libz-dev (used to reduce size of bytecode files, linux only - windows uses vcpkg to download it)
  • curl (for downloading the rust source, linux only)
  • cmake (at least 3.4.3, required for building llvm in rustc)


  • make RUSTCSRC - Downloads the rustc source tarball (1.19.0 by default)
  • make -f - Builds mrustc and minicargo, then builds libstd, libtest, finally rustc and cargo
  • make -C run_rustc - Build libstd and a "hello, world" using the above-built rustc


Similar to Linux, but you might need to

  • specify the rustc default target explicitly
  • specify the compiler
  • use gmake to run GNU make

e.g. gmake CC=cc RUSTC_TARGET=x86_64-unknown-freebsd -f


(NOTE: Incomplete, doesn't yet compile executables and missing helper scripts)

  • Download and extract rustc-1.19.0-src.tar.gz to the repository root (such that the rustc-1.19.0-src directory is present)
    • NOTE: I am open to suggestions for how to automate that step
  • Open vsproject/mrustc.sln and build minicargo
  • Run vsproject/build_rustc_minicargo.cmd to attempt to build libstd

Building non-rustc code

To build your own code with mrustc, first you need to build at least libcore (and probably the full standard library). This can be done on linux by running make -f LIBS, or on windows with build_std.cmd.

Next, run

  • minicargo -L <path_to_libstd> <crate_path> to build a cargo project.
  • or, mrustc -L <path_to_libstd> --out-dir <output_directory> <> to directly invoke mrustc.

For additional options, both programs have a --help option.

Diagnosing Issues and Reporting Bugs


Both the makefiles and minicargo write the compiler's stdout to a file in the output directory, e.g. when building output/libcore.hir it'll save to output/libcore.hir_dbg.txt. To get full debug output for a compilation run, set the environemnt variable MRUSTC_DEBUG to the pass you want to debug (pass names are printed in every log line). E.g. MRUSTC_DEBUG=Expand make -f

Bug Reports

Please try to include the following when submitting a bug report:

  • What you're trying to build
  • Your host system version (e.g. Ubuntu 17.10)
  • C/C++ compiler version
  • Revison of the mrustc repo that you're running

Support and Discussion

For problems that don't warrant opening an issue, join the IRC channel -

Current Features

  • Full compilation chain including HIR and MIR stages (outputting to C)
  • MIR optimisations (to take some load off the C compiler)
  • Optionally-enablable exhaustive MIR validation (set the MRUSTC_FULL_VALIDATE environment variable)
  • Functional cargo clone (minicargo)
    • Includes build script support
  • Procedural macros (custom derive)
  • Custom target specifications
    • See docs/



  • Fix currently-failing tests (mostly in type inferrence)
  • Fix all known TODOs in MIR generation (still some possible leaks)


  • Propagate lifetime annotations so that MIR can include a borrow checker
  • Emit C code that is (more) human readable (uses names from the orignal source, reduced/no gotos)
  • Add alternate backends (e.g. LLVM IR, cretonne, ...)

Note: All progress is against the source of rustc 1.19.0

You can’t perform that action at this time.