Skip to content

Commit

Permalink
have make use its own build directory
Browse files Browse the repository at this point in the history
This speeds up builds `make` builds that are interleaved with other
builds with different `RUSTFLAGS` because the cache can be reused.
  • Loading branch information
jan-ferdinand committed Aug 9, 2023
2 parents 82f81f3 + dd05647 commit 3b4522c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Added by Makefile configuration
/makefile-target

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
Expand Down
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,42 @@ CLIPPY_ARGS = --all-targets -- -D warnings
# Fail if `cargo fmt` changes anything.
FMT_ARGS = --all -- --check

# Primary targets
# Treat all warnings as errors
export RUSTFLAGS = -Dwarnings

# Set another target dir than default to avoid builds from `make`
# to invalidate cache from barebones use of `cargo` commands.
# The cache is cleared when a new `RUSTFLAGS` value is encountered,
# so to prevent the two builds from interfering, we use two dirs.
export CARGO_TARGET_DIR=./makefile-target

# By first building tests, and consequently building constraints, before
# running `fmt` and `clippy`, the auto-generated constraints are exposed
# to `fmt` and `clippy`.
default: build-constraints build-tests build-bench fmt-only clippy-only clean-constraints

# Run `make all` when the constraints are already in place.
all: test build-bench fmt-only clippy-only

# Alternative to `cargo build --all-targets`
build: build-constraints
cargo build --all-targets
make clean-constraints

# Alternative to `cargo test --all-targets`
test: build-constraints
test:
cargo test --all-targets
make clean-constraints

# Alternative to `cargo bench --all-targets`
bench: build-constraints
cargo bench --all-targets
make clean-constraints

# Alternative to `cargo clippy ...`
clippy: build-constraints
cargo clippy $(CLIPPY_ARGS)
make clean-constraints

# Alternative to `cargo fmt ...`
fmt-check: build-constraints
cargo fmt $(FMT_ARGS)
make clean-constraints

# Alternative to `cargo clean`
clean:
Expand Down

0 comments on commit 3b4522c

Please sign in to comment.