Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A small make file to handle Rust compilation something like rustpkg.
Branch: master

Merge pull request #3 from mcarpenter/opt-level

"--opt-level=" becomes "-C opt-level="
latest commit 1c4923b94c
@KokaKiwi authored
Failed to load latest commit information. Modify 'Usage' section of


This make script intend to help Rusties to compile Rust programs with a Makefile.


Get source

git submodule add git://

Or, if you don't work in a local Git repository:

git clone git://

Basic usage

This Makefile will compile a crate located in src/mycrate/{,}

RUSTCRATES          =   mycrate

include             rust-mk/

Advanced usage

RUSTCRATES          =   mycrate mydep

mycrate_TYPE        =   bin        # Automatically detected if not specified.
mycrate_CRATE_DEPS  +=  mydep      # mydep will be build before mycrate.
mycrate_BUILD_DEPS  +=  libtest.a  # Raw dependency of libtest.a for mycrate.
mycrate_RUSTCFLAGS  +=  -g         # Add some custom flags as you want.

include             rust-mk/

Disable auto crate rules


include             rust-mk/

$(eval $(call RUST_CRATES_RULES))

Import external crates (using rust-mk)

RUSTCRATES          =   extcrate

extcrate_ROOTDIR    =   deps/extcrate

include             rust-mk/

Import external crates (not using rust-mk)

RUSTCRATES          =   extcrate

extcrate_ROOT       =   deps/extcrate/src/
extcrate_TYPE       =   lib # Only if the crate root filename is not or

include             rust-mk/

Add a LLVM-passe rules on targets

RUSTCRATES          =   mycrate

$(1)_LLVM_NAME      = $(1).ll

_llvm_$(1):         $$($(1)_LLVM_NAME)
.PHONY llvm:        _llvm_$(1)

    rm -f $$($(1)_LLVM_NAME)
.PHONY clean:       _clean_llvm_$(1)

$(1).ll:            $$($(1)_NAME) $$($(1)_ROOT)
    $$(RUSTC) $$(RUSTCFLAGS) $$($(1)_RUSTCFLAGS_BUILD) $$($(1)_RUSTCFLAGS) --emit ir -o $(1).ll $$($(1)_ROOT)

include rust-mk/

.PHONY:             llvm


$ make help
 Common rules:
  make all                 - Build all crates (alias of 'build' target).
  make build               - Build all crates.
  make clean               - Clean crates targets.
  make fclean              - Clean crates targets and build directories.
  make rebuild             - Rebuild all crates.
  make test                - Build and run tests.
  make bench               - Build and run benchs.
  make doc                 - Generate crates documentation.
  make install             - Install crates targets in ~/.rust
  make uninstall           - Uninstall crates targets.
  make crates              - Print available crates.
  make help                - Print this help.

 Crates rules:
  make build_<crate>       - Build <crate>.
  make clean_<crate>       - Clean <crate> targets.
  make rebuild_<crate>     - Rebuild <crate>.
  make test_<crate>        - Build and run <crate> tests.
  make bench_<crate>       - Build and run <crate> benchs.
  make doc_<crate>         - Generate <crate> documentation.
  make install_<crate>     - Install <crate> targets in ~/.rust
  make uninstall_<crate>   - Uninstall <crate> targets.

 Available crates:         [...]

Special variables

These special variables can be set, either by setting them in env or by passing them to make:

make <varname>=<varvalue>


Default: rustc

Path to rustc executable.


Default: rustdoc

Path to rustdoc executable.


Default: depending on others vars

Flags used to compile crates.


Default: nothing

Flags used to generate docs.


Default: 0

If set to 1, activate debug flags (-g) else optimization flags will be activated (--opt-level=3)


Default: .rust

This directory will be used to store build files (like test binaries).


Default: src

This directory is where crates must be find.


Default: .

This directory is where runnable crates' binaries will be stored.


Default: lib

This directory is where library crates will be stored.


Default: doc

This directory is where crate docs will be stored.


Default: ~/.rust

This directory is where all crates will be installed.


Default: Not defined

You can define this variable to add some rules for all crates.

Crate variables


Default: .

Directory where rust-mk will search for source directory containing the crate (usually src/<crate>).

Useful when compiling an external crate.


Default: Determined with existing file ( or in crate dir.

Specify the crate root file (entry file when compiling the crate).


Default: Crate root file

Specify the crate root file used for tests.


Default: 1

Specify if you want to test the Rust code in your doc comments.

In fact, it add --test to rustdoc


Default: 0

  • 0 if you want to test <crate>
  • 1 if you don't want to test <crate>


Default: Value of <crate>_DONT_TEST variable

Same as <crate>_DONT_TEST variable, but for bench.


Default: 0

  • 0 if you want to generate doc for <crate>
  • 1 if you don't want to generate doc for <crate>


Default: Determined with crate root ( or

Values: bin or lib

Specify the crate type of <crate> (indicate if it cannot be automatically determined or if you want to force the value).


Default: nothing

Indicate other crate names on which <crate> depends.

These crates will be built before <crate>


Default: nothing

Indicate raw make rule dependencies on which <crate> depends.

These rules will be built before <crate>


Default: nothing

Add crate-specific flags at build-time.


Default: 0

  • 0 if you want to extends this crate with RUST_CRATE_RULES_ADD variable.
  • 0 if you don't want to extends this crate with RUST_CRATE_RULES_ADD variable.


rust-mk is licensed under MIT license.

Something went wrong with that request. Please try again.