Skip to content

Commit f83338a

Browse files
committed
Add FORCE phony and conditional artifact copy
Add a FORCE phony target and make the library build pattern depend on it so the rule can be triggered reliably. Only copy the built artifact when the cargo output path differs from the Make target to avoid installing a file onto itself and to skip redundant installs, reducing unnecessary work and potential errors.
1 parent 4cf4215 commit f83338a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help all clean test build release lint fmt check-fmt markdownlint nixie check python-test-deps publish-check
1+
.PHONY: help all clean test build release lint fmt check-fmt markdownlint nixie check python-test-deps publish-check FORCE
22

33
CRATE ?= ortho_config
44
CARGO ?= cargo
@@ -42,14 +42,17 @@ python-test-deps: ## Ensure Python test dependencies are provisioned
4242
$(PYTEST) --version > $(NULL_DEVICE)
4343

4444
# will match target/debug/libmy_library.rlib and target/release/libmy_library.rlib
45-
target/%/lib$(CRATE).rlib: ## Build library in debug or release
45+
target/%/lib$(CRATE).rlib: FORCE ## Build library in debug or release
4646
$(CARGO) build $(BUILD_JOBS) \
4747
$(if $(findstring release,$(@)),--release) \
4848
--lib
49-
@# copy the .rlib into your own target tree
50-
install -Dm644 \
51-
target/$(if $(findstring release,$(@)),release,debug)/lib$(CRATE).rlib \
52-
$@
49+
@# Copy artefacts only when the cargo output and make target differ.
50+
src=target/$(if $(findstring release,$(@)),release,debug)/lib$(CRATE).rlib; \
51+
if [ "$$src" != "$@" ]; then \
52+
install -Dm644 "$$src" "$@"; \
53+
fi
54+
55+
FORCE:
5356

5457
lint: ## Run Clippy with warnings denied
5558
RUSTDOCFLAGS="$(RUSTDOC_FLAGS)" $(CARGO) doc --workspace --no-deps

0 commit comments

Comments
 (0)