-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
188 lines (163 loc) · 6.75 KB
/
Makefile
File metadata and controls
188 lines (163 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# SPDX-License-Identifier: MPL-2.0 OR LGPL-3.0-or-later
#
# libpathrs: safe path resolution on Linux
# Copyright (C) 2019-2025 SUSE LLC
# Copyright (C) 2026 Aleksa Sarai <cyphar@cyphar.com>
#
# == MPL-2.0 ==
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Alternatively, this Source Code Form may also (at your option) be used
# under the terms of the GNU Lesser General Public License Version 3, as
# described below:
#
# == LGPL-3.0-or-later ==
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
CARGO ?= cargo
CARGO_NIGHTLY ?= cargo +nightly
# Unfortunately --all-features needs to be put after the subcommand, but
# cargo-hack needs to be put before the subcommand. So make a function to make
# this a little easier.
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)
EXTRA_RUSTC_FLAGS ?=
RUSTC_FLAGS := -C panic=abort $(EXTRA_RUSTC_FLAGS)
EXTRA_CARGO_FLAGS ?=
CARGO_FLAGS := --features=capi $(EXTRA_CARGO_FLAGS)
SRC_FILES = $(wildcard Cargo.*) $(shell find . -name '*.rs')
.DEFAULT: debug
.PHONY: debug
debug: target/debug/libpathrs.so target/debug/libpathrs.a
target/debug/libpathrs.so: LIBPATHRS_CAPI_BUILDMODE := cdylib
target/debug/libpathrs.so: $(SRC_FILES)
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS)
# MSRV(1.64): Switch to cargo rustc --crate-type=...
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS)
target/debug/libpathrs.a: LIBPATHRS_CAPI_BUILDMODE := staticlib
target/debug/libpathrs.a: $(SRC_FILES)
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS)
# MSRV(1.64): Switch to cargo rustc --crate-type=...
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS)
.PHONY: release
release: CARGO_FLAGS += --release
release: target/release/libpathrs.so target/release/libpathrs.a
target/release/libpathrs.so: LIBPATHRS_CAPI_BUILDMODE := cdylib
target/release/libpathrs.so: $(SRC_FILES)
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS)
# MSRV(1.64): Switch to cargo rustc --crate-type=...
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_FLAGS)
target/release/libpathrs.a: LIBPATHRS_CAPI_BUILDMODE := staticlib
target/release/libpathrs.a: $(SRC_FILES)
LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) \
hack/with-crate-type.sh --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) \
env RUSTFLAGS="$(RUSTC_FLAGS)" $(CARGO) build $(CARGO_FLAGS)
# MSRV(1.64): Switch to cargo rustc --crate-type=...
#LIBPATHRS_CAPI_BUILDMODE=$(LIBPATHRS_CAPI_BUILDMODE) $(CARGO) rustc $(CARGO_FLAGS) --crate-type=$(LIBPATHRS_CAPI_BUILDMODE) -- $(RUSTC_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: validate-keyring
validate-keyring:
./hack/keyring-validate.sh
.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
# In order to avoid re-running the entire test suite with just statx
# disabled, we re-run the key procfs tests with statx disabled.
./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
# In order to avoid re-running the entire test suite with just statx
# disabled, we re-run the key procfs tests with statx disabled.
./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
GPG_KEYID ?= cyphar@cyphar.com
.PHONY: dist-release
dist-release:
./hack/release.sh -S $(GPG_KEYID)