| 1 |
# SPDX-License-Identifier: MPL-2.0 OR LGPL-3.0-or-later |
| 2 |
# |
| 3 |
# libpathrs: safe path resolution on Linux |
| 4 |
# Copyright (C) 2019-2025 SUSE LLC |
| 5 |
# Copyright (C) 2026 Aleksa Sarai <[email protected]> |
| 6 |
# |
| 7 |
# == MPL-2.0 == |
| 8 |
# |
| 9 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 10 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 11 |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 12 |
# |
| 13 |
# Alternatively, this Source Code Form may also (at your option) be used |
| 14 |
# under the terms of the GNU Lesser General Public License Version 3, as |
| 15 |
# described below: |
| 16 |
# |
| 17 |
# == LGPL-3.0-or-later == |
| 18 |
# |
| 19 |
# This program is free software: you can redistribute it and/or modify it |
| 20 |
# under the terms of the GNU Lesser General Public License as published by |
| 21 |
# the Free Software Foundation, either version 3 of the License, or (at |
| 22 |
# your option) any later version. |
| 23 |
# |
| 24 |
# This program is distributed in the hope that it will be useful, but |
| 25 |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 26 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 27 |
# for more details. |
| 28 |
# |
| 29 |
# You should have received a copy of the GNU Lesser General Public License |
| 30 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 31 |
|
| 32 |
CARGO ?= cargo |
| 33 |
CARGO_NIGHTLY ?= cargo +nightly |
| 34 |
|
| 35 |
# Unfortunately --all-features needs to be put after the subcommand, but |
| 36 |
# cargo-hack needs to be put before the subcommand. So make a function to make |
| 37 |
# this a little easier. |
| 38 |
ifneq (, $(shell which cargo-hack)) |
| 39 |
define cargo_hack |
| 40 |
$(1) hack --feature-powerset $(2) |
| 41 |
endef |
| 42 |
else |
| 43 |
define cargo_hack |
| 44 |
$(1) $(2) --all-features |
| 45 |
endef |
| 46 |
endif |
| 47 |
CARGO_CHECK := $(call cargo_hack,$(CARGO),check) |
| 48 |
CARGO_CLIPPY := $(call cargo_hack,$(CARGO),clippy) |
| 49 |
CARGO_LLVM_COV := $(call cargo_hack,$(CARGO_NIGHTLY),llvm-cov) |
| 50 |
|
| 51 |
EXTRA_RUSTC_FLAGS ?= |
| 52 |
RUSTC_FLAGS := -C panic=abort $(EXTRA_RUSTC_FLAGS) |
| 53 |
EXTRA_CARGO_FLAGS ?= |
| 54 |
CARGO_FLAGS := --features=capi $(EXTRA_CARGO_FLAGS) |
| 55 |
|
| 56 |
SRC_FILES = $(wildcard Cargo.*) $(shell find . -name '*.rs') |
| 57 |
|
| 58 |
.DEFAULT: debug |
| 59 |
.PHONY: debug |
| 60 |
debug: target/debug/libpathrs.so target/debug/libpathrs.a |
| 61 |
|
| 62 |
target/debug/libpathrs.so: LIBPATHRS_CAPI_BUILDMODE := cdylib |
| 63 |
target/debug/libpathrs.so: $(SRC_FILES) |
| 64 |
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 65 |
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 66 |
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS) |
| 67 |
# MSRV(1.64): Switch to cargo rustc --crate-type=... |
| 68 |
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS) |
| 69 |
target/debug/libpathrs.a: LIBPATHRS_CAPI_BUILDMODE := staticlib |
| 70 |
target/debug/libpathrs.a: $(SRC_FILES) |
| 71 |
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 72 |
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 73 |
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS) |
| 74 |
# MSRV(1.64): Switch to cargo rustc --crate-type=... |
| 75 |
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS) |
| 76 |
|
| 77 |
.PHONY: release |
| 78 |
release: CARGO_FLAGS += --release |
| 79 |
release: target/release/libpathrs.so target/release/libpathrs.a |
| 80 |
|
| 81 |
target/release/libpathrs.so: LIBPATHRS_CAPI_BUILDMODE := cdylib |
| 82 |
target/release/libpathrs.so: $(SRC_FILES) |
| 83 |
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 84 |
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 85 |
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS) |
| 86 |
# MSRV(1.64): Switch to cargo rustc --crate-type=... |
| 87 |
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS) |
| 88 |
target/release/libpathrs.a: LIBPATHRS_CAPI_BUILDMODE := staticlib |
| 89 |
target/release/libpathrs.a: $(SRC_FILES) |
| 90 |
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 91 |
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \ |
| 92 |
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS) |
| 93 |
# MSRV(1.64): Switch to cargo rustc --crate-type=... |
| 94 |
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS) |
| 95 |
|
| 96 |
.PHONY: smoke-test |
| 97 |
smoke-test: |
| 98 |
make -C examples smoke-test |
| 99 |
|
| 100 |
.PHONY: clean |
| 101 |
clean: |
| 102 |
-rm -rf target/ |
| 103 |
|
| 104 |
.PHONY: lint |
| 105 |
lint: validate-cbindgen lint-rust |
| 106 |
|
| 107 |
.PHONY: lint-rust |
| 108 |
lint-rust: |
| 109 |
$(CARGO_NIGHTLY) fmt --all -- --check |
| 110 |
$(CARGO_CLIPPY) --all-targets |
| 111 |
$(CARGO_CHECK) $(CARGO_FLAGS) --all-targets |
| 112 |
|
| 113 |
.PHONY: validate-cbindgen |
| 114 |
validate-cbindgen: |
| 115 |
$(eval TMPDIR := $(shell mktemp --tmpdir -d libpathrs-cbindgen-check.XXXXXXXX)) |
| 116 |
@ \ |
| 117 |
trap "rm -rf $(TMPDIR)" EXIT ; \ |
| 118 |
cbindgen -c cbindgen.toml -o $(TMPDIR)/pathrs.h ; \ |
| 119 |
if ! ( diff -u include/pathrs.h $(TMPDIR)/pathrs.h ); then \ |
| 120 |
echo -e \ |
| 121 |
"\n" \ |
| 122 |
"ERROR: include/pathrs.h is out of date.\n\n" \ |
| 123 |
"Changes to the C API in src/capi/ usually need to be paired with\n" \ |
| 124 |
"an update to include/pathrs.h using cbindgen. To fix this error,\n" \ |
| 125 |
"just run:\n\n" \ |
| 126 |
"\tcbindgen -c cbindgen.toml -o include/pathrs.h\n" ; \ |
| 127 |
exit 1 ; \ |
| 128 |
fi |
| 129 |
|
| 130 |
.PHONY: validate-elf-symbols |
| 131 |
validate-elf-symbols: release |
| 132 |
./hack/check-elf-symbols.sh ./target/release/libpathrs.so |
| 133 |
|
| 134 |
.PHONY: validate-keyring |
| 135 |
validate-keyring: |
| 136 |
./hack/keyring-validate.sh |
| 137 |
|
| 138 |
.PHONY: test-rust-doctest |
| 139 |
test-rust-doctest: |
| 140 |
$(CARGO_LLVM_COV) --no-report --branch --doc |
| 141 |
|
| 142 |
.PHONY: test-rust-unpriv |
| 143 |
test-rust-unpriv: |
| 144 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" |
| 145 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --enosys=openat2 |
| 146 |
# In order to avoid re-running the entire test suite with just statx |
| 147 |
# disabled, we re-run the key procfs tests with statx disabled. |
| 148 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --enosys=statx "test(#tests::*procfs*)" |
| 149 |
|
| 150 |
.PHONY: test-rust-root |
| 151 |
test-rust-root: |
| 152 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo |
| 153 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo --enosys=openat2 |
| 154 |
# In order to avoid re-running the entire test suite with just statx |
| 155 |
# disabled, we re-run the key procfs tests with statx disabled. |
| 156 |
./hack/rust-tests.sh --cargo="$(CARGO_NIGHTLY)" --sudo --enosys=statx "test(#tests::*procfs*)" |
| 157 |
|
| 158 |
.PHONY: test-rust |
| 159 |
test-rust: |
| 160 |
-rm -rf target/llvm-cov* |
| 161 |
make test-rust-{doctest,unpriv,root} |
| 162 |
|
| 163 |
.PHONY: test-e2e |
| 164 |
test-e2e: |
| 165 |
make -C e2e-tests test-all |
| 166 |
make -C e2e-tests RUN_AS=root test-all |
| 167 |
|
| 168 |
.PHONY: test |
| 169 |
test: test-rust test-e2e |
| 170 |
$(CARGO_NIGHTLY) llvm-cov report |
| 171 |
$(CARGO_NIGHTLY) llvm-cov report --open |
| 172 |
|
| 173 |
.PHONY: docs |
| 174 |
docs: |
| 175 |
$(CARGO) doc --all-features --document-private-items --open |
| 176 |
|
| 177 |
.PHONY: install |
| 178 |
install: release |
| 179 |
@echo "If you want to configure the install paths, use ./install.sh directly." |
| 180 |
@echo "[Sleeping for 3 seconds.]" |
| 181 |
@sleep 3s |
| 182 |
./install.sh |
| 183 |
|
| 184 |
GPG_KEYID ?= [email protected] |
| 185 |
|
| 186 |
.PHONY: dist-release |
| 187 |
dist-release: |
| 188 |
./hack/release.sh -S $(GPG_KEYID) |