This make script intend to help Rusties to compile Rust programs with a Makefile.
git submodule add git://github.com/KokaKiwi/rust-mk.git
Or, if you don't work in a local Git repository:
git clone git://github.com/KokaKiwi/rust-mk.git
This Makefile will compile a crate located in src/mycrate/{lib.rs,main.rs}
RUSTCRATES = mycrate
include rust-mk/rust.mk
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/rust.mk
RUSTAUTORULES = 0
include rust-mk/rust.mk
$(eval $(call RUST_CRATES_RULES))
RUSTCRATES = extcrate
extcrate_ROOTDIR = deps/extcrate
include rust-mk/rust.mk
RUSTCRATES = extcrate
extcrate_ROOT = deps/extcrate/src/lib.rs
extcrate_TYPE = lib # Only if the crate root filename is not lib.rs or main.rs
include rust-mk/rust.mk
RUSTCRATES = mycrate
# LLVM
define RUST_CRATE_RULES_ADD
$(1)_LLVM_NAME = $(1).ll
_llvm_$(1): $$($(1)_LLVM_NAME)
.PHONY llvm: _llvm_$(1)
_clean_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)
endef
include rust-mk/rust.mk
llvm:
.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: [...]
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.
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 (main.rs
or lib.rs
) 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 (main.rs
or lib.rs
).
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 withRUST_CRATE_RULES_ADD
variable.0
if you don't want to extends this crate withRUST_CRATE_RULES_ADD
variable.
rust-mk
is licensed under MIT license.