Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drop-in makefile for Cargo projects
CARGO = cargo
CARGO_OPTS =
all:
$(MAKE) build
$(MAKE) doc
build:
$(CARGO) $(CARGO_OPTS) build
clean:
$(CARGO) $(CARGO_OPTS) clean
check:
$(MAKE) build
$(MAKE) test
test:
$(CARGO) $(CARGO_OPTS) test
bench:
$(CARGO) $(CARGO_OPTS) bench
doc:
$(CARGO) $(CARGO_OPTS) doc
.PHONY: all build clean check test bench doc
@mzabaluev

This comment has been minimized.

Copy link
Owner Author

mzabaluev commented Jan 10, 2015

Cargo is, by itself, a good build system for Rust-only projects.
However, integration with make is sometimes needed. Possible reasons include:

  • The Rust code is a part of a larger project built with a build system that can integrate makefiles, such as automake.
  • Development tools such as editors and IDEs have support for makefiles, but not (yet) for Cargo.
  • People see a makefile and immediately know how to build the project and where to look in order to figure out how it is built and what individual targets can be built.
@NichtJens

This comment has been minimized.

Copy link

NichtJens commented Nov 22, 2016

Hi Mikhail!
First off: Thanks for the cargo Makefile! Very helpful!

Mind having a look at my modified version?

I'm wondering whether it is safe to turn the calls to $(MAKE) into dependences considering a potential make -j call. I suspect it is a good choice for make all, where one does not care about the order the two calls are executed. Could it be a problem for make check? I.e., could the test be run while the build is in progress?

Also is there a reason to have CARGO_OPTS?

@mqudsi

This comment has been minimized.

Copy link

mqudsi commented Aug 17, 2017

I believe @NichtJens is correct, cargo obtains a lock to build a project, and so the parallelization will be lost. No harm done though, since they'll still execute, just out of order - and cargo has proper dependency resolution so they'll end up actually building in the correct order on that end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.