-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMakefile
More file actions
303 lines (276 loc) · 11.7 KB
/
Copy pathMakefile
File metadata and controls
303 lines (276 loc) · 11.7 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
LINDFS_ROOT ?= lindfs
BUILD_DIR ?= build
SYSROOT_DIR ?= $(BUILD_DIR)/sysroot
# Prebuilt libc++ headers/libs; merged into $(SYSROOT_DIR) by sync-sysroot when present.
ARTIFACTS_DIR ?= artifacts
LINDBOOT_BIN ?= $(BUILD_DIR)/lind-boot
LINDBOOT_DEBUG_BIN ?= $(BUILD_DIR)/lind-boot-debug
LINDFS_DIRS := \
bin \
dev \
etc \
grates \
lib \
sbin \
tmp \
usr/bin \
usr/lib \
usr/lib/locale \
usr/local/bin \
usr/share/zoneinfo \
var \
var/log \
var/run
WITH_FPCAST ?=
.PHONY: build
build: lindfs lind-boot sysroot
@echo "Build complete"
.PHONY: all
all: build
.PHONY: fpcast
fpcast:
$(MAKE) build WITH_FPCAST=1
.PHONY: sysroot
sysroot: build-dir
./scripts/build/make_glibc_and_sysroot.sh $(if $(WITH_FPCAST),--with-fpcast)
$(MAKE) sync-sysroot
# fdtables backend selector. One of: dashmaparray (default), dashmapvec,
# muthashmax, vanilla. Threaded through lind-boot -> rawposix -> fdtables
# via Cargo features.
#
# Examples:
# make # default (dashmaparray, EH setjmp)
# make build FDTABLES_IMPL=muthashmax # full build with muthashmax
# make lind-boot FDTABLES_IMPL=vanilla # rebuild only lind-boot with vanilla
# make fpcast FDTABLES_IMPL=dashmapvec # fpcast variant with dashmapvec
# make lind-debug FDTABLES_IMPL=muthashmax # debug build with muthashmax
# FDTABLES_IMPL=muthashmax make # also works via env var
# LIND_ASYNCIFY_SETJMP=1 make lind-boot # asyncify-based setjmp/longjmp
FDTABLES_IMPL ?= dashmaparray
# When LIND_ASYNCIFY_SETJMP=1, build lind-boot with the asyncify-setjmp Cargo feature so the
# runtime uses asyncify-unwind/rewind based setjmp/longjmp instead of the wasm-EH based one.
LIND_BOOT_EXTRA_FEATURES ?= $(if $(filter 1,$(LIND_ASYNCIFY_SETJMP)),asyncify-setjmp,)
# When NO_LOGGING=1, omit the lind-logging feature (e.g. make lind-boot NO_LOGGING=1).
LIND_LOGGING_FEATURE ?= $(if $(filter 1,$(NO_LOGGING)),,lind-logging)
.PHONY: lind-boot
lind-boot: build-dir
# Build lind-boot with `--release` flag for faster runtime (e.g. for tests)
cargo build --manifest-path src/lind-boot/Cargo.toml --release \
--no-default-features --features "$(LIND_LOGGING_FEATURE) fdtables-$(FDTABLES_IMPL) $(LIND_BOOT_EXTRA_FEATURES)"
cp src/lind-boot/target/release/lind-boot $(LINDBOOT_BIN)
.PHONY: lindfs
lindfs:
@for d in $(LINDFS_DIRS); do \
mkdir -p $(LINDFS_ROOT)/$$d; \
done
touch $(LINDFS_ROOT)/dev/null
cp -rT scripts/config/lindfs-conf/etc $(LINDFS_ROOT)/etc
cp -rT scripts/config/lindfs-conf/usr/lib/locale $(LINDFS_ROOT)/usr/lib/locale
cp -rT scripts/config/lindfs-conf/usr/share/zoneinfo $(LINDFS_ROOT)/usr/share/zoneinfo
@if [ -d /usr/share/zoneinfo ]; then \
cp -r /usr/share/zoneinfo/* $(LINDFS_ROOT)/usr/share/zoneinfo/; \
fi
.PHONY: clean-lindfs
clean-lindfs:
@# Remove user files from lindfs while preserving preloaded system files.
@# Keeps: lib/ (shared libs), etc/, usr/, dev/null, directory structure
find $(LINDFS_ROOT) -maxdepth 1 -type f -delete
rm -rf $(LINDFS_ROOT)/bin/* $(LINDFS_ROOT)/sbin/* $(LINDFS_ROOT)/tmp/*
rm -rf $(LINDFS_ROOT)/home $(LINDFS_ROOT)/testfiles
.PHONY: lind-debug
lind-debug: lindfs build-dir
# Build lind-boot with the lind_debug feature enabled
cargo build --manifest-path src/lind-boot/Cargo.toml \
--no-default-features --features "lind_debug $(LIND_LOGGING_FEATURE) fdtables-$(FDTABLES_IMPL)"
cp src/lind-boot/target/debug/lind-boot $(LINDBOOT_BIN)
# Build glibc with LIND_DEBUG enabled (by setting the LIND_DEBUG variable)
$(MAKE) build_glibc LIND_DEBUG=1
build_glibc:
# build sysroot passing -DLIND_DEBUG if LIND_DEBUG is set
if [ "$(LIND_DEBUG)" = "1" ]; then \
echo "Building glibc with LIND_DEBUG enabled"; \
./scripts/build/make_glibc_and_sysroot.sh; \
$(MAKE) sync-sysroot; \
fi
.PHONY: build-dir
build-dir:
mkdir -p $(BUILD_DIR)
# After copying src/glibc/sysroot → $(SYSROOT_DIR), optionally merge libc++ from
# $(ARTIFACTS_DIR) when that tree is present (same layout as Docker E2E).
# Remove any existing c++ tree first: it may be a symlink into src/glibc/sysroot
# (e.g. read-only in Docker), and cp -r into that path would hit EROFS.
.PHONY: sync-sysroot
sync-sysroot:
$(RM) -r $(SYSROOT_DIR)
cp -R src/glibc/sysroot $(SYSROOT_DIR)
@if [ -d "$(ARTIFACTS_DIR)/include/wasm32-wasi/c++" ] \
&& [ -f "$(ARTIFACTS_DIR)/lib/wasm32-wasi/libc++.a" ] \
&& [ -f "$(ARTIFACTS_DIR)/lib/wasm32-wasi/libc++abi.a" ]; then \
echo "Merging libc++ from $(ARTIFACTS_DIR) into $(SYSROOT_DIR)"; \
mkdir -p $(SYSROOT_DIR)/include/wasm32-wasi; \
mkdir -p $(SYSROOT_DIR)/lib/wasm32-wasi; \
$(RM) -r $(SYSROOT_DIR)/include/wasm32-wasi/c++; \
cp -r $(ARTIFACTS_DIR)/include/wasm32-wasi/c++ $(SYSROOT_DIR)/include/wasm32-wasi/; \
$(RM) -f $(SYSROOT_DIR)/lib/wasm32-wasi/libc++.a $(SYSROOT_DIR)/lib/wasm32-wasi/libc++abi.a; \
cp $(ARTIFACTS_DIR)/lib/wasm32-wasi/libc++.a $(ARTIFACTS_DIR)/lib/wasm32-wasi/libc++abi.a $(SYSROOT_DIR)/lib/wasm32-wasi/; \
fi
.PHONY: test
test: lindfs
# Unified harness entry point (run all discovered harnesses for e2e signal)
alias_path='$(LIND_RUNTIME_LINDFS_ALIAS)'; \
prebuilt_lindfs_root='$(PREBUILT_LINDFS_ROOT)'; \
cleanup() { \
if [ -n "$$alias_path" ]; then \
alias_parent="$$(dirname "$$alias_path")"; \
rm -f "$$alias_path"; \
rmdir "$$alias_parent" 2>/dev/null || true; \
rmdir "$$(dirname "$$alias_parent")" 2>/dev/null || true; \
fi; \
}; \
if [ -n "$$alias_path" ]; then \
mkdir -p "$$(dirname "$$alias_path")"; \
rm -f "$$alias_path"; \
case '$(LINDFS_ROOT)' in \
/*) lindfs_root='$(LINDFS_ROOT)' ;; \
*) lindfs_root="$$PWD/$(LINDFS_ROOT)" ;; \
esac; \
ln -s "$$lindfs_root" "$$alias_path"; \
trap cleanup EXIT; \
fi; \
if [ -n "$$prebuilt_lindfs_root" ] && [ -d "$$prebuilt_lindfs_root/lib" ]; then \
mkdir -p "$(LINDFS_ROOT)/lib"; \
cp -a "$$prebuilt_lindfs_root/lib/." "$(LINDFS_ROOT)/lib/"; \
fi; \
if LIND_WASM_BASE=. LINDFS_ROOT=$(LINDFS_ROOT) \
python3 ./scripts/test/test_runner.py --export-report report.html && \
find reports -maxdepth 1 -name '*.json' -print -exec cat {} \; && \
if [ "$(LIND_DEBUG)" = "1" ]; then \
python3 ./scripts/test/check_reports.py --debug; \
else \
python3 ./scripts/test/check_reports.py; \
fi; then \
echo "E2E_STATUS=pass" > e2e_status; \
else \
echo "E2E_STATUS=fail" > e2e_status; \
mkdir -p reports; \
if [ ! -f report.html ]; then \
printf '%s\n' '<!DOCTYPE html><html><body><h1>E2E failed before report generation</h1></body></html>' > report.html; \
fi; \
if [ ! -f reports/report.html ]; then cp report.html reports/report.html; fi; \
if [ ! -f reports/wasm.json ]; then printf '%s\n' '{"number_of_failures":1,"results":[],"error":"missing wasm report"}' > reports/wasm.json; fi; \
if [ ! -f reports/grates.json ]; then printf '%s\n' '{"number_of_failures":1,"results":[],"error":"missing grate report"}' > reports/grates.json; fi; \
fi; \
exit 0
# Run wasmtestreport with a grate prefix.
# Single-grate examples:
# make test-grate GRATE=ipc-grate
# make test-grate GRATE=chroot-grate GRATE_ARGS="--chroot-dir /tmp"
# make test-grate GRATE=ipc-grate RUN=process_tests
# make test-grate GRATE=ipc-grate TESTFILES=tests/unit-tests/process_tests/deterministic/hello.c
# Grate chain (mutually exclusive with GRATE / GRATE_ARGS — the string is passed
# verbatim before the test wasm, so any grate-side group syntax goes here too):
# make test-grate GRATE_PREFIX="grates/fs-routing-clamp.cwasm --prefix /tmp grates/imfs-grate.cwasm"
# Build the grate(s) first: cd ../lind-wasm-example-grates && make rust/<name>
# Run timeout defaults to 90s under any grate (vs 30s without), override with TIMEOUT=N.
.PHONY: test-grate
GRATE ?=
GRATE_ARGS ?=
GRATE_PREFIX ?=
TESTFILES ?=
RUN ?=
TIMEOUT ?=
test-grate:
@if [ -z "$(GRATE)" ] && [ -z "$(GRATE_PREFIX)" ]; then \
echo "Usage: make test-grate GRATE=<name> [GRATE_ARGS='...'] [RUN=folder | TESTFILES=path/to/test.c]"; \
echo " or: make test-grate GRATE_PREFIX='<raw chain>' [RUN=...]"; \
echo ""; \
echo "Examples:"; \
echo " make test-grate GRATE=ipc-grate"; \
echo " make test-grate GRATE=chroot-grate GRATE_ARGS=\"--chroot-dir /tmp\""; \
echo " make test-grate GRATE=ipc-grate RUN=process_tests"; \
echo " make test-grate GRATE=ipc-grate TESTFILES=tests/unit-tests/process_tests/deterministic/hello.c"; \
echo " make test-grate GRATE_PREFIX=\"grates/fs-routing-clamp.cwasm --prefix /tmp grates/imfs-grate.cwasm\""; \
echo ""; \
echo "Build the grate(s) first: cd ../lind-wasm-example-grates && make rust/<name>"; \
exit 1; \
fi
@if [ -n "$(GRATE)" ] && [ -n "$(GRATE_PREFIX)" ]; then \
echo "GRATE and GRATE_PREFIX are mutually exclusive"; exit 1; \
fi
LIND_WASM_BASE=. LINDFS_ROOT=$(LINDFS_ROOT) \
python3 ./scripts/test/harnesses/wasmtestreport.py \
--allow-pre-compiled \
$(if $(GRATE),--grate grates/$(GRATE).cwasm) \
$(if $(GRATE_ARGS),--grate-args "$(GRATE_ARGS)") \
$(if $(GRATE_PREFIX),--grate-prefix "$(GRATE_PREFIX)") \
$(if $(TIMEOUT),--timeout $(TIMEOUT)) \
$(if $(TESTFILES),--testfiles $(TESTFILES)) \
$(if $(RUN),--run $(RUN))
.PHONY: md_generation
OUT ?= .
REPORT ?= report.html
md_generation:
python3 -m pip install --quiet jinja2
REPORT_PATH=$(REPORT) OUT_DIR=$(OUT) python3 scripts/generate/render_e2e_templates.py
@echo "Wrote $(OUT)/e2e_comment.md"
.PHONY: lint
lint:
cargo fmt --check --all --manifest-path src/wasmtime/Cargo.toml
cargo fmt --check --all --manifest-path src/lind-boot/Cargo.toml
rustfmt --check src/fdtables/src/dashmaparrayglobal.rs \
src/fdtables/src/dashmapvecglobal.rs \
src/fdtables/src/muthashmaxglobal.rs \
src/fdtables/src/vanillaglobal.rs
# Note: --all-features can't be used here because it enables every
# fdtables-* impl simultaneously, which trips the fdtables impl-mutex
# compile_error guard. Enumerate the non-fdtables features explicitly
# and pin to the default fdtables impl.
cargo clippy \
--manifest-path src/lind-boot/Cargo.toml \
--features "disable_signals secure lind_debug lind-logging debug-grate-calls fdtables-dashmaparray" \
--keep-going \
-- \
-A warnings \
-A clippy::not_unsafe_ptr_arg_deref \
-A clippy::absurd_extreme_comparisons
.PHONY: format
format:
cargo fmt --all --manifest-path src/wasmtime/Cargo.toml
cargo fmt --all --manifest-path src/lind-boot/Cargo.toml
rustfmt src/fdtables/src/dashmaparrayglobal.rs \
src/fdtables/src/dashmapvecglobal.rs \
src/fdtables/src/muthashmaxglobal.rs \
src/fdtables/src/vanillaglobal.rs
.PHONY: docs-serve
docs-serve:
mkdocs serve
.PHONY: clean
clean:
@echo "cleaning glibc artifacts"
# Remove only generated sysroot and intermediate .o files,
# but KEEP required objects used by subsequent builds.
$(RM) -r src/glibc/sysroot
@echo "removing build artifacts"
$(RM) -r $(BUILD_DIR)
@echo "removing lindfs root"
$(RM) -r $(LINDFS_ROOT)
@find src/glibc -type f -name '*.o' \
! -path 'src/glibc/csu/wasm32/wasi_thread_start.o' \
! -path 'src/glibc/target/lib/Mcrt1.o' \
! -path 'src/glibc/target/lib/Scrt1.o' \
! -path 'src/glibc/target/lib/crt1.o' \
! -path 'src/glibc/target/lib/crti.o' \
! -path 'src/glibc/target/lib/crtn.o' \
! -path 'src/glibc/target/lib/gcrt1.o' \
! -path 'src/glibc/target/lib/grcrt1.o' \
! -path 'src/glibc/target/lib/rcrt1.o' \
-exec rm -f {} +
@echo "cargo clean (lind-boot)"
cargo clean --manifest-path src/lind-boot/Cargo.toml
.PHONY: distclean
distclean: clean
@echo "removing test outputs & temp files"
$(RM) -f results.json report.html e2e_status
$(RM) -r reports || true
$(RM) -r $(LINDFS_ROOT)/testfiles || true
find tests -type f \( -name '*.wasm' -o -name '*.cwasm' -o -name '*.o' \) -delete