CARGO ?= cargo
CARGO_NIGHTLY ?= cargo +nightly
ifneq (, $(shell which cargo-hack))
define cargo_hack
$(1) hack --feature-powerset $(2)
endef
else
define cargo_hack
$(1) $(2) --all-features
endef
endif
CARGO_CHECK := $(call cargo_hack,$(CARGO),check)
CARGO_CLIPPY := $(call cargo_hack,$(CARGO),clippy)
CARGO_LLVM_COV := $(call cargo_hack,$(CARGO_NIGHTLY),llvm-cov)
RUSTC_FLAGS := -C panic=abort
CARGO_FLAGS ?= --features=capi
SRC_FILES = $(wildcard Cargo.*) $(shell find . -name '*.rs')
.DEFAULT: debug
.PHONY: debug
debug: target/debug
target/debug: $(SRC_FILES)
RUSTFLAGS="$(RUSTC_FLAGS)" ./hack/with-crate-type.sh $(CARGO) build $(CARGO_FLAGS)
.PHONY: release
release: target/release
target/release: CARGO_FLAGS += --release
target/release: $(SRC_FILES)
RUSTFLAGS="$(RUSTC_FLAGS)" ./hack/with-crate-type.sh $(CARGO) build $(CARGO_FLAGS)
.PHONY: smoke-test
smoke-test:
make -C examples smoke-test
.PHONY: clean
clean:
-rm -rf target/
.PHONY: lint
lint: validate-cbindgen lint-rust
.PHONY: lint-rust
lint-rust:
$(CARGO_NIGHTLY) fmt --all -- --check
$(CARGO_CLIPPY) --all-targets
$(CARGO_CHECK) $(CARGO_FLAGS) --all-targets
.PHONY: validate-cbindgen
validate-cbindgen:
$(eval TMPDIR := $(shell mktemp --tmpdir -d libpathrs-cbindgen-check.XXXXXXXX))
@ \
trap "rm -rf $(TMPDIR)" EXIT ; \
cbindgen -c cbindgen.toml -o $(TMPDIR)/pathrs.h ; \
if ! ( diff -u include/pathrs.h $(TMPDIR)/pathrs.h ); then \
echo -e \
"\n" \
"ERROR: include/pathrs.h is out of date.\n\n" \
"Changes to the C API in src/capi/ usually need to be paired with\n" \
"an update to include/pathrs.h using cbindgen. To fix this error,\n" \
"just run:\n\n" \
"\tcbindgen -c cbindgen.toml -o include/pathrs.h\n" ; \
exit 1 ; \
fi
.PHONY: validate-elf-symbols
validate-elf-symbols: release
./hack/check-elf-symbols.sh ./target/release/libpathrs.so
.PHONY: test-rust-doctest
test-rust-doctest:
$(CARGO_LLVM_COV) --no-report --branch --doc
.PHONY: test-rust-unpriv
test-rust-unpriv:
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)"
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --enosys=openat2
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --enosys=statx "test(#tests::*procfs*)"
.PHONY: test-rust-root
test-rust-root:
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo --enosys=openat2
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo --enosys=statx "test(#tests::*procfs*)"
.PHONY: test-rust
test-rust:
-rm -rf target/llvm-cov*
make test-rust-{doctest,unpriv,root}
.PHONY: test-e2e
test-e2e:
make -C e2e-tests test-all
make -C e2e-tests RUN_AS=root test-all
.PHONY: test
test: test-rust test-e2e
$(CARGO_NIGHTLY) llvm-cov report
$(CARGO_NIGHTLY) llvm-cov report --open
.PHONY: docs
docs:
$(CARGO) doc --all-features --document-private-items --open
.PHONY: install
install: release
@echo "If you want to configure the install paths, use ./install.sh directly."
@echo "[Sleeping for 3 seconds.]"
@sleep 3s
./install.sh