Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
539 lines (479 loc) · 18.4 KB
/
Copy pathMakefile
File metadata and controls
539 lines (479 loc) · 18.4 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# SPDX-License-Identifier: MPL-2.0
# =========================== Makefile options. ===============================
# Global build options.
TARGET_ARCH ?= x86_64
BENCHMARK ?= none
BOOT_METHOD ?= grub-rescue-iso
BOOT_PROTOCOL ?= multiboot2
ENABLE_KVM ?= 1
INTEL_TDX ?= 0
MEM ?= 8G
OVMF ?= on
RELEASE ?= 0
RELEASE_LTO ?= 0
LOG_LEVEL ?= error
SCHEME ?= ""
SMP ?= 1
OSTD_TASK_STACK_SIZE_IN_PAGES ?= 64
FEATURES ?=
NO_DEFAULT_FEATURES ?= 0
COVERAGE ?= 0
INITRAMFS ?= on
CMDLINE ?=
# Specify the primary system console (supported: tty0, ttyS0, hvc0).
# - tty0: The active virtual terminal (VT).
# - ttyS0: The serial (UART) terminal.
# - hvc0: The virtio-console terminal.
# Asterinas will automatically fall back to tty0 if hvc0 is not available.
# Note that currently the virtual terminal (tty0) can only work with
# linux-efi-handover64 and linux-efi-pe64 boot protocol.
ifeq ($(SCHEME), sifive_u)
CONSOLE ?= ttyS0
else
CONSOLE ?= hvc0
endif
# End of global build options.
# GDB debugging and profiling options.
GDB_TCP_PORT ?= 1234
GDB_PROFILE_FORMAT ?= flame-graph
GDB_PROFILE_COUNT ?= 200
GDB_PROFILE_INTERVAL ?= 0.1
# End of GDB options.
# The Makefile provides a way to run arbitrary tests in the kernel
# mode using the kernel command line.
# Here are the options for the auto test feature.
AUTO_TEST ?= none
# Specify whether to build conformance tests under `test/initramfs/src/conformance`.
ENABLE_CONFORMANCE_TEST ?= false
CONFORMANCE_TEST_SUITE ?= ltp
CONFORMANCE_TEST_WORKDIR ?= /tmp
# Comma-separated extra blocklists for conformance runners.
# - `gvisor` treats each entry as a directory relative to its runner directory,
# and loads a per-test blocklist file from that directory.
# - `kselftest` treats each entry as a blocklist file relative to its runner
# directory, and appends that file directly.
CONFORMANCE_TEST_EXTRA_BLOCKLISTS ?= ""
# Comma-separated tests to run within the selected conformance suite.
#
# This variable allows one to select one or multiple tests to run.
# When this environment variable is present,
# the blocklist of a conformance test will be ignored.
#
# - gvisor: a test *binary* name, e.g. `epoll_test` (narrow the cases inside
# it with `CONFORMANCE_TEST_GVISOR_FILTER`).
# - kselftest: a `<collection>:<case>` entry, e.g. `timers:posix_timers`.
# - ltp: a syscall testcase id, e.g. `rename01`.
# - xfstests: a test id, e.g. `generic/001`.
CONFORMANCE_TEST_SELECTOR ?= ""
# gVisor-only positive gtest filter, applied inside one selected gVisor test
# binary, e.g. `EpollTest.CloseFile:EpollTest.Oneshot`.
CONFORMANCE_TEST_GVISOR_FILTER ?= ""
# Parameters for xfstests.
XFSTESTS_FS_TYPE ?= ext2
XFSTESTS_RUNLIST ?= short.list
XFSTESTS_DISK_SIZE ?= 12G
# Specify whether to build regression tests under `test/initramfs/src/regression`.
ENABLE_REGRESSION_TEST ?= false
# End of auto test features.
# Network settings
# NETDEV possible values are user, tap, and none. SCHEME=microvm does not support none.
NETDEV ?= user
VHOST ?= off
# The name server listed by /etc/resolv.conf inside the Asterinas VM
DNS_SERVER ?= none
# End of network settings
# Virtio-fs settings. Set VIRTIOFS=on to attach a virtio-fs device. Set
# VIRTIOFS_SCRATCH=on to attach a second device (requires VIRTIOFS=on).
# VIRTIOFS_CACHE accepts auto, always, never, or metadata.
VIRTIOFS ?= off
VIRTIOFS_SCRATCH ?= off
VIRTIOFS_CACHE ?= auto
# End of Virtio-fs settings.
# NixOS settings
NIXOS_DISK_SIZE_IN_MB ?= 16384
NIXOS_DISABLE_SYSTEMD ?= false
# The following option is only effective when NIXOS_DISABLE_SYSTEMD is set to 'true'.
# Use a login shell to ensure that environment variables are initialized correctly.
NIXOS_STAGE_2_INIT ?= /bin/sh -l
# End of NixOS settings
# ISO installer settings
AUTO_INSTALL ?= true
# End of ISO installer settings
# Cachix binary cache settings
CACHIX_AUTH_TOKEN ?=
RELEASE_CACHIX_NAME ?= "aster-nixos-release"
RELEASE_SUBSTITUTER ?= https://aster-nixos-release.cachix.org
RELEASE_TRUSTED_PUBLIC_KEY ?= aster-nixos-release.cachix.org-1:xB6U/f5ck5vGDJZ04kPp3zGpZ4Nro9X4+TSSMAETVFE=
DEV_CACHIX_NAME ?= "aster-nixos-dev"
DEV_SUBSTITUTER ?= https://aster-nixos-dev.cachix.org
DEV_TRUSTED_PUBLIC_KEY ?= aster-nixos-dev.cachix.org-1:xrCbE2flfliFTQCY/2HeJoT2tCO+5kMTZeLIUH9lnIA=
# End of Cachix binary cache settings
# ========================= End of Makefile options. ==========================
export OSDK_TARGET_ARCH=$(TARGET_ARCH)
SHELL := /bin/bash
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
# Common arguments for `cargo osdk` `build`, `run` and `test` commands.
CARGO_OSDK_COMMON_ARGS :=
# The build arguments also apply to the `cargo osdk run` command.
CARGO_OSDK_BUILD_ARGS := --kcmd-args="loglevel=$(LOG_LEVEL)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="earlycon"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="console=$(CONSOLE)"
ifneq ($(strip $(CMDLINE)),)
CARGO_OSDK_BUILD_ARGS += $(foreach arg,$(CMDLINE),--kcmd-args="$(arg)")
endif
CARGO_OSDK_TEST_ARGS :=
ifeq ($(AUTO_TEST), conformance)
ENABLE_CONFORMANCE_TEST := true
CARGO_OSDK_BUILD_ARGS += --kcmd-args="CONFORMANCE_TEST_SUITE=$(CONFORMANCE_TEST_SUITE)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="CONFORMANCE_TEST_WORKDIR=$(CONFORMANCE_TEST_WORKDIR)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="CONFORMANCE_TEST_EXTRA_BLOCKLISTS=$(CONFORMANCE_TEST_EXTRA_BLOCKLISTS)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="CONFORMANCE_TEST_SELECTOR=$(CONFORMANCE_TEST_SELECTOR)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="CONFORMANCE_TEST_GVISOR_FILTER=$(CONFORMANCE_TEST_GVISOR_FILTER)"
ifeq ($(CONFORMANCE_TEST_SUITE), xfstests)
include test/initramfs/src/conformance/xfstests/build_config.mk
CARGO_OSDK_BUILD_ARGS += --kcmd-args="XFSTESTS_FS_TYPE=$(XFSTESTS_FS_TYPE)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="XFSTESTS_RUNLIST=$(XFSTESTS_RUNLIST)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="XFSTESTS_TEST_DEV=$(XFSTESTS_TEST_DEV)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="XFSTESTS_SCRATCH_DEV=$(XFSTESTS_SCRATCH_DEV)"
endif
CARGO_OSDK_BUILD_ARGS += --init-args="/opt/run_conformance_test.sh"
else ifeq ($(AUTO_TEST), regression)
ENABLE_REGRESSION_TEST := true
CARGO_OSDK_BUILD_ARGS += --kcmd-args="INTEL_TDX=$(INTEL_TDX)"
CARGO_OSDK_BUILD_ARGS += --init-args="/test/run_regression_test.sh"
else ifeq ($(AUTO_TEST), boot)
CARGO_OSDK_BUILD_ARGS += --init-args="/test/boot_hello.sh"
else ifeq ($(AUTO_TEST), vsock)
ENABLE_REGRESSION_TEST := true
export VSOCK=on
CARGO_OSDK_BUILD_ARGS += --init-args="/test/run_vsock_test.sh"
endif
ifeq ($(RELEASE_LTO), 1)
CARGO_OSDK_COMMON_ARGS += --profile release-lto
OSTD_TASK_STACK_SIZE_IN_PAGES = 8
else ifeq ($(RELEASE), 1)
CARGO_OSDK_COMMON_ARGS += --release
ifeq ($(TARGET_ARCH), riscv64)
# FIXME: Unwinding in RISC-V seems to cost more stack space, so we increase
# the stack size for it. This may need further investigation.
# See https://github.com/asterinas/asterinas/pull/2383#discussion_r2307673156
OSTD_TASK_STACK_SIZE_IN_PAGES = 16
else
OSTD_TASK_STACK_SIZE_IN_PAGES = 8
endif
endif
# If the BENCHMARK is set, we will run the benchmark in the kernel mode.
ifneq ($(BENCHMARK), none)
CARGO_OSDK_BUILD_ARGS += --init-args="/benchmark/common/bench_runner.sh $(BENCHMARK) asterinas"
endif
ifeq ($(INTEL_TDX), 1)
BOOT_PROTOCOL = linux-efi-handover64
CARGO_OSDK_COMMON_ARGS += --scheme tdx
endif
ifneq (,$(filter multiboot pvh,$(BOOT_PROTOCOL)))
BOOT_METHOD = vmm-direct
endif
ifeq ($(BOOT_PROTOCOL), pvh)
override FEATURES += pvh_boot
endif
ifeq ($(SCHEME), microvm)
BOOT_METHOD = vmm-direct
endif
ifeq ($(SCHEME), "")
ifeq ($(TARGET_ARCH), riscv64)
SCHEME = riscv
else ifeq ($(TARGET_ARCH), loongarch64)
SCHEME = loongarch
else ifeq ($(TARGET_ARCH), aarch64)
SCHEME = aarch64
endif
endif
ifneq ($(SCHEME), "")
CARGO_OSDK_COMMON_ARGS += --scheme $(SCHEME)
else
CARGO_OSDK_COMMON_ARGS += --boot-method="$(BOOT_METHOD)"
endif
ifeq ($(COVERAGE), 1)
CARGO_OSDK_COMMON_ARGS += --coverage
endif
ifdef FEATURES
CARGO_OSDK_COMMON_ARGS += --features="$(FEATURES)"
endif
ifeq ($(NO_DEFAULT_FEATURES), 1)
CARGO_OSDK_COMMON_ARGS += --no-default-features
endif
# To test the linux-efi-handover64 boot protocol, we need to use Debian's
# GRUB release, which is installed in /usr/bin in our Docker image.
GRUB_MKRESCUE ?= /usr/bin/grub-mkrescue
ifeq ($(BOOT_PROTOCOL), linux-efi-handover64)
CARGO_OSDK_COMMON_ARGS += --grub-mkrescue="$(GRUB_MKRESCUE)" --grub-boot-protocol="linux"
else ifeq ($(BOOT_PROTOCOL), linux-efi-pe64)
CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol="linux"
else ifeq ($(BOOT_PROTOCOL), linux-legacy32)
CARGO_OSDK_COMMON_ARGS += --linux-x86-legacy-boot --grub-boot-protocol="linux" --strip-elf
else ifeq ($(BOOT_PROTOCOL), pvh)
# PVH uses the vmm-direct boot method, so there is no GRUB boot protocol to pass.
else
CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol=$(BOOT_PROTOCOL)
endif
ifeq ($(ENABLE_KVM), 1)
ifeq ($(shell [ -e /dev/kvm ] && [ "$$(uname -m)" = "$(TARGET_ARCH)" ] && echo yes),yes)
CARGO_OSDK_COMMON_ARGS += --qemu-args="-accel kvm"
endif
endif
# Skip GZIP to make encoding and decoding of initramfs faster
ifeq ($(INITRAMFS_SKIP_GZIP),1)
CARGO_OSDK_INITRAMFS_OPTION := --initramfs=$(abspath test/initramfs/build/initramfs.cpio)
else
CARGO_OSDK_INITRAMFS_OPTION := --initramfs=$(abspath test/initramfs/build/initramfs.cpio.gz)
endif
ifeq ($(INITRAMFS),on)
CARGO_OSDK_COMMON_ARGS += $(CARGO_OSDK_INITRAMFS_OPTION)
endif
CARGO_OSDK_VIRTIOFSD := ./tools/run_virtiofsd.sh --cache-mode $(VIRTIOFS_CACHE) --work-dir
ifeq ($(VIRTIOFS),on)
# Each Make invocation gets an isolated virtio-fs work directory under /tmp.
VIRTIOFS_WORK_DIR := $(shell mktemp -d -p /tmp asterinas-virtiofs-XXXXXX)
CARGO_OSDK_COMMON_ARGS += --qemu-with-daemon="$(CARGO_OSDK_VIRTIOFSD) $(VIRTIOFS_WORK_DIR)"
endif
ifeq ($(VIRTIOFS_SCRATCH),on)
CARGO_OSDK_COMMON_ARGS += --qemu-with-daemon="$(CARGO_OSDK_VIRTIOFSD) $(VIRTIOFS_WORK_DIR)/scratch"
endif
CARGO_OSDK_BUILD_ARGS += $(CARGO_OSDK_COMMON_ARGS)
CARGO_OSDK_TEST_ARGS += $(CARGO_OSDK_COMMON_ARGS)
# Pass make variables to all subdirectory makes
export
# OSDK dependencies
OSDK_SRC_FILES := \
$(shell find osdk/Cargo.toml osdk/Cargo.lock osdk/src -type f)
.PHONY: all
all: kernel
# Install or update OSDK from source
# To uninstall, do `cargo uninstall cargo-osdk`
.PHONY: install_osdk
install_osdk:
@# The `OSDK_LOCAL_DEV` environment variable is used for local development
@# without the need to publish the changes of OSDK's self-hosted
@# dependencies to `crates.io`.
@OSDK_LOCAL_DEV=1 cargo install cargo-osdk --path osdk
# This will install and update OSDK automatically
$(CARGO_OSDK): $(OSDK_SRC_FILES)
@$(MAKE) --no-print-directory install_osdk
.PHONY: check_osdk
check_osdk:
@./tools/clippy_check.sh osdk
.PHONY: test_osdk
test_osdk:
@cd osdk && \
OSDK_LOCAL_DEV=1 cargo build && \
OSDK_LOCAL_DEV=1 cargo test
.PHONY: check_vdso
check_vdso:
@# Checking `VDSO_LIBRARY_DIR` environment variable
@if [ -z "$(VDSO_LIBRARY_DIR)" ]; then \
echo "Error: the VDSO_LIBRARY_DIR environment variable must be given."; \
echo " This variable points to a directory that provides Linux's vDSO files,"; \
echo " which is required to build Asterinas. Search for VDSO_LIBRARY_DIR"; \
echo " in Asterinas's Dockerfile for more information."; \
exit 1; \
fi
.PHONY: initramfs
initramfs: check_vdso
@$(MAKE) --no-print-directory -C test/initramfs initramfs-boot-images
.PHONY: rootfs
rootfs: check_vdso
@$(MAKE) --no-print-directory -C test/initramfs rootfs-boot-images
# Build the kernel with an initramfs
.PHONY: kernel
kernel: $(CARGO_OSDK)
ifeq ($(INITRAMFS),on)
kernel: initramfs
else
kernel: rootfs
endif
kernel:
@cd kernel && cargo osdk build $(CARGO_OSDK_BUILD_ARGS)
# Build the kernel with an initramfs and then run it
.PHONY: run_kernel
run_kernel: $(CARGO_OSDK)
ifeq ($(INITRAMFS),on)
run_kernel: initramfs
else
run_kernel: rootfs
endif
run_kernel:
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS)
# Check the running status of auto tests from the QEMU log
ifeq ($(AUTO_TEST), conformance)
@tail --lines 100 qemu.log | grep -q "^All conformance tests passed." \
|| (echo "Conformance test failed" && exit 1)
else ifeq ($(AUTO_TEST), regression)
@tail --lines 100 qemu.log | grep -q "^All regression tests passed." \
|| (echo "Regression test failed" && exit 1)
else ifeq ($(AUTO_TEST), boot)
@tail --lines 100 qemu.log | grep -q "^Successfully booted." \
|| (echo "Boot test failed" && exit 1)
else ifeq ($(AUTO_TEST), vsock)
@tail --lines 100 qemu.log | grep -q "^Vsock test passed." \
|| (echo "Vsock test failed" && exit 1)
endif
# Build the Asterinas NixOS ISO installer image
iso: BOOT_PROTOCOL = linux-efi-handover64
iso:
@make kernel
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
$(MAKE) --no-print-directory -C test/nixos iso; \
else \
./tools/nixos/build_iso.sh; \
fi
# Build the Asterinas NixOS ISO installer image and then do installation
run_iso: OVMF = off
run_iso:
@./tools/nixos/run.sh iso
# Create an Asterinas NixOS installation on host
nixos: BOOT_PROTOCOL = linux-efi-handover64
nixos:
@make kernel
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
$(MAKE) --no-print-directory -C test/nixos nixos; \
else \
./tools/nixos/build_nixos.sh; \
fi
# After creating a Asterinas NixOS installation (via either the `run_iso` or `nixos` target),
# run the NixOS
run_nixos: OVMF = off
run_nixos:
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
$(MAKE) --no-print-directory -C test/nixos run_nixos; \
else \
./tools/nixos/run.sh nixos; \
fi
# Build the Asterinas NixOS patched packages
cachix:
@nix-build distro/cachix \
--option extra-substituters "${RELEASE_SUBSTITUTER} ${DEV_SUBSTITUTER}" \
--option extra-trusted-public-keys "${RELEASE_TRUSTED_PUBLIC_KEY} ${DEV_TRUSTED_PUBLIC_KEY}" \
--out-link cachix.list
# Push the Asterinas NixOS patched packages to Cachix
.PHONY: push_cachix
push_cachix: USE_RELEASE_CACHE ?= 0
push_cachix: cachix
ifeq ($(USE_RELEASE_CACHE), 1)
@cachix push $(RELEASE_CACHIX_NAME) < cachix.list
else
@cachix push $(DEV_CACHIX_NAME) < cachix.list
endif
.PHONY: gdb_server
gdb_server: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS) --gdb-server wait-client,vscode,addr=:$(GDB_TCP_PORT)
.PHONY: gdb_client
gdb_client: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk debug $(CARGO_OSDK_BUILD_ARGS) --remote :$(GDB_TCP_PORT)
.PHONY: profile_server
profile_server: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS) --gdb-server addr=:$(GDB_TCP_PORT)
.PHONY: profile_client
profile_client: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk profile $(CARGO_OSDK_BUILD_ARGS) --remote :$(GDB_TCP_PORT) \
--samples $(GDB_PROFILE_COUNT) --interval $(GDB_PROFILE_INTERVAL) --format $(GDB_PROFILE_FORMAT)
.PHONY: test
test: NON_DEFAULT_PACKAGE_NAMES = \
$(shell ./tools/print_workspace_members.sh --non-default-ones --package-names)
test: TEST_PACKAGE_NAMES = \
$(filter-out linux-bzimage-setup,$(NON_DEFAULT_PACKAGE_NAMES))
test:
@if [ -n "$(TEST_PACKAGE_NAMES)" ]; then \
cargo test $(addprefix -p ,$(TEST_PACKAGE_NAMES)); \
fi
.PHONY: ktest
ktest: CONSOLE = ttyS0
ktest: initramfs $(CARGO_OSDK)
@# cargo-osdk tests default workspace members.
@# `linux-bzimage-setup` is left out of `default-members`
@# because it is hard to unit test.
@cargo osdk test $(CARGO_OSDK_TEST_ARGS)
.PHONY: docs
docs: private DEFAULT_PACKAGE_NAMES = \
$(shell ./tools/print_workspace_members.sh --default-ones --package-names)
docs: private DEFAULT_NON_CORE_PACKAGE_NAMES = \
$(filter-out aster-core,$(DEFAULT_PACKAGE_NAMES))
docs: private NON_DEFAULT_PACKAGE_NAMES = \
$(shell ./tools/print_workspace_members.sh --non-default-ones --package-names)
docs: private DOC_NON_DEFAULT_PACKAGE_NAMES = \
$(filter-out linux-bzimage-setup,$(NON_DEFAULT_PACKAGE_NAMES))
docs: $(CARGO_OSDK)
@if [ -n "$(DEFAULT_NON_CORE_PACKAGE_NAMES)" ]; then \
RUSTDOCFLAGS="-Dwarnings" cargo osdk doc $(addprefix -p ,$(DEFAULT_NON_CORE_PACKAGE_NAMES)) --no-deps; \
fi
@if [ -n "$(DOC_NON_DEFAULT_PACKAGE_NAMES)" ]; then \
RUSTDOCFLAGS="-Dwarnings" cargo doc $(addprefix -p ,$(DOC_NON_DEFAULT_PACKAGE_NAMES)) --no-deps; \
fi
@# The aster-core crate is primarily composed of private items.
@# Include --document-private-items to fully check internal documentation.
@RUSTDOCFLAGS="-Dwarnings --document-private-items -Arustdoc::private_intra_doc_links" \
cargo osdk doc -p aster-core --no-deps
@if [ "$(TARGET_ARCH)" = "x86_64" ]; then \
cd ostd/libs/linux-bzimage/setup && RUSTDOCFLAGS="-Dwarnings" cargo osdk doc --no-deps; \
fi
.PHONY: format
format:
@# Trim trailing whitespace from all git-tracked, non-patch files
@# NOTE: `--git-dir` will suppress "detected dubious ownership in repository" errors
@git --git-dir=$$PWD/.git ls-files --no-directory | \
grep -v '[.]patch$$' | \
grep -v '^.claude/skills/aster-code-review$$' `# This is a symbolic link` | \
xargs sed -i 's/ *$$//'
@
@# Format the code using various tools
@./tools/format_all.sh
@./tools/nixfmt.sh flake.nix distro tools/dev_env/nix
@$(MAKE) --no-print-directory -C test/initramfs format
@$(MAKE) --no-print-directory -C test/nixos format
.PHONY: check
check: private WORKSPACE_MEMBER_DIRS = \
$(shell ./tools/print_workspace_members.sh)
check: $(CARGO_OSDK)
@# Check if any git-tracked, non-patch files contain trailing whitespace
@# NOTE: `--git-dir` will suppress "detected dubious ownership in repository" errors
@if git --git-dir=$$PWD/.git grep -n ' $$' -- ':!*.patch' ; then \
echo "Error: Files (as listed above) contain trailing whitespaces"; \
exit 1; \
fi
@
@# Check if all workspace members enable workspace lints
@for dir in $(WORKSPACE_MEMBER_DIRS); do \
if [[ "$$(tail -2 $$dir/Cargo.toml)" != "[lints]"$$'\n'"workspace = true" ]]; then \
echo "Error: Workspace lints in $$dir are not enabled"; \
exit 1; \
fi; \
done
@
@# Check formatting issues of the Rust code
@./tools/format_all.sh --check
@
@# Check compilation of the Rust code
@./tools/clippy_check.sh workspace
@
@# Check Nix formatting
@./tools/nixfmt.sh --check flake.nix distro tools/dev_env/nix
@
@# Check formatting issues of the C code and Nix files (regression tests)
@$(MAKE) --no-print-directory -C test/initramfs check
@
@# Check formatting issues of the Rust code in NixOS tests
@$(MAKE) --no-print-directory -C test/nixos check
@
@# Check typos
@typos
.PHONY: clean
clean:
@echo "Cleaning up Asterinas workspace target files"
@cargo clean
@echo "Cleaning up OSDK workspace target files"
@cd osdk && cargo clean
@echo "Cleaning up mdBook output files"
@cd book && mdbook clean
@echo "Cleaning up test target files"
@$(MAKE) --no-print-directory -C test/initramfs clean
@echo "Uninstalling OSDK"
@rm -f $(CARGO_OSDK)