-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
601 lines (525 loc) · 20.2 KB
/
Copy pathMakefile
File metadata and controls
601 lines (525 loc) · 20.2 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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# SPDX-License-Identifier: MPL-2.0
# =========================== Makefile options. ===============================
# Global build options.
OSDK_TARGET_ARCH ?= x86_64
BENCHMARK ?= none
BOOT_METHOD ?= grub-rescue-iso
BOOT_PROTOCOL ?= multiboot2
ENABLE_KVM ?= 1
KVM_EXISTS = $(shell test -c /dev/kvm && echo 1 || echo 0)
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 ?=
ENABLE_RAID_TEST ?= 0
NO_DEFAULT_FEATURES ?= 0
BASELINE_ASTERINAS ?= 0
RUSTFLAGS ?=
COVERAGE ?= 0
# 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.
CONSOLE ?= hvc0
# 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
# Whitespace-separated extra blocklist paths 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.
EXTRA_BLOCKLISTS ?= ""
# 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
NETDEV ?= user
VHOST ?= off
# The name server listed by /etc/resolv.conf inside the Asterinas VM
DNS_SERVER ?= none
# End of network settings
# Docker settings
# Name that the long-running container will use
DOCKER_CONTAINER_NAME ?= mariposa-$(shell whoami)
# End of docker settings
# Rust cache
DOCKER_RUST_CACHE_LOCATION ?= $(shell pwd)/.cache
# NixOS settings
NIXOS_DISK_SIZE_IN_MB ?= 8192
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 ?=
RELEASE_SUBSTITUTER ?=
RELEASE_TRUSTED_PUBLIC_KEY ?=
DEV_CACHIX_NAME ?=
DEV_SUBSTITUTER ?=
DEV_TRUSTED_PUBLIC_KEY ?=
# End of Cachix binary cache settings
# Python formatting settings
# Directories to search for python files
PYTHON_PROJECTS= \
kernel/comps/mariposa_data_capture/python \
kernel/comps/raid/python \
tools \
mariposa-cli
# Specific files for format which are not .py
EXTRA_PYTHON_FILES= \
tools/howdone/howdone
# End of python formatting settings
# ========================= End of Makefile options. ==========================
SHELL := /bin/bash
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
# Common arguments for `cargo osdk` `build`, `run` and `test` commands.
CARGO_OSDK_COMMON_ARGS := --target-arch=$(OSDK_TARGET_ARCH)
# The build arguments also apply to the `cargo osdk run` command.
CARGO_OSDK_BUILD_ARGS := --kcmd-args="ostd.log_level=$(LOG_LEVEL)"
CARGO_OSDK_BUILD_ARGS += --kcmd-args="console=$(CONSOLE)"
CARGO_OSDK_TEST_ARGS :=
# Common arguments for all `cargo clippy` and `cargo osdk clippy` commands.
CLIPPY_COMMON_ARGS :=
# Rust Cache
CARGO_CACHE := $(DOCKER_RUST_CACHE_LOCATION)/cargo
RUSTUP_CACHE := $(DOCKER_RUST_CACHE_LOCATION)/rustup
# Persistent Bash history - .bash_history is persisted between container invocations to make
# development easier.
BASH_HISTORY := $(DOCKER_RUST_CACHE_LOCATION)/.bash_history
# Docker Configs
DOCKER_TAG := ldosproject/asterinas
DOCKER_IMAGE := $(shell cat DOCKER_IMAGE_VERSION)
DOCKER_IMAGE_TAG := $(DOCKER_TAG):$(DOCKER_IMAGE)
DOCKER_RUN_ARGS := --network=host --privileged --device=/dev/kvm
DOCKER_MOUNTS := -v $(shell pwd):/root/asterinas -v $(CARGO_CACHE):/root/.cargo -v $(RUSTUP_CACHE):/root/.rustup
DOCKER_MOUNTS += -v /dev:/dev
DOCKER_MOUNTS += -v $(BASH_HISTORY):/root/.bash_history
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="EXTRA_BLOCKLISTS=$(EXTRA_BLOCKLISTS)"
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), raid)
ENABLE_REGRESSION_TEST := true
CARGO_OSDK_BUILD_ARGS += --init-args="/test/raid1.sh"
# Only the RAID1 test depends on the userspace selection-policy server, so this stays scoped to
# `AUTO_TEST=raid` rather than being an always-applied `OSDK.toml` kcmd arg.
CARGO_OSDK_BUILD_ARGS += --kcmd-args="raid.selection=userspace"
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 ($(OSDK_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
# If INITARGS is set, it will be passed as arguments to the init process in the VM. By default it is a command to be
# launched instead of the shell.
INITARGS ?=
CARGO_OSDK_BUILD_ARGS += $(foreach ARG, $(INITARGS), --init-args="$(ARG)")
# If KCMDARGS is set, it will be passed as kernel command line args. In the kernel you can access these via KCmdlineArg.
KCMDARGS ?=
CARGO_OSDK_BUILD_ARGS += $(foreach ARG, $(KCMDARGS), --kcmd-args="$(ARG)")
ifeq ($(INTEL_TDX), 1)
BOOT_PROTOCOL = linux-efi-handover64
CARGO_OSDK_COMMON_ARGS += --scheme tdx
endif
ifeq ($(BOOT_PROTOCOL), multiboot)
BOOT_METHOD = qemu-direct
endif
ifeq ($(SCHEME), microvm)
BOOT_METHOD = qemu-direct
endif
ifeq ($(SCHEME), "")
ifeq ($(OSDK_TARGET_ARCH), riscv64)
SCHEME = riscv
else ifeq ($(OSDK_TARGET_ARCH), loongarch64)
SCHEME = loongarch
endif
endif
ifneq ($(SCHEME), "")
CARGO_OSDK_COMMON_ARGS += --scheme $(SCHEME)
else
CARGO_OSDK_COMMON_ARGS += --boot-method="$(BOOT_METHOD)"
endif
# Feature for RAID test.
ifeq ($(ENABLE_RAID_TEST),1)
FEATURES := $(strip $(FEATURES) raid_test)
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
ifeq ($(BASELINE_ASTERINAS), 1)
RUSTFLAGS += --cfg=baseline_asterinas
CLIPPY_COMMON_ARGS += --cfg=baseline_asterinas -A unused-imports -A dead-code -A unfulfilled-lint-expectations
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.
ifeq ($(BOOT_PROTOCOL), linux-efi-handover64)
CARGO_OSDK_COMMON_ARGS += --grub-mkrescue=/usr/bin/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"
else
CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol=$(BOOT_PROTOCOL)
endif
ifeq ($(ENABLE_KVM), 1)
ifeq ($(KVM_EXISTS), 1)
ifeq ($(OSDK_TARGET_ARCH), x86_64)
CARGO_OSDK_COMMON_ARGS += --qemu-args="-accel kvm"
endif
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)
CARGO_OSDK_COMMON_ARGS += $(CARGO_OSDK_INITRAMFS_OPTION)
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 -- $(CLIPPY_COMMON_ARGS)
.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
# Build the kernel with an initramfs
.PHONY: kernel
kernel: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk build $(CARGO_OSDK_BUILD_ARGS)
# Build the kernel with an initramfs and then run it
.PHONY: run_kernel
run_kernel: initramfs $(CARGO_OSDK)
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS)
# Check the running status of auto tests from the QEMU log
# TODO(arthurp, https://github.com/ldos-project/asterinas/issues/237): Using `^` to anchor to the
# beginning of the line is probably better. But the dataloss bug makes that spuriously fail.
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), raid)
@tail --lines 100 qemu.log | grep -q "All raid1 test passed" \
|| (echo "RAID 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:
kill_qemu:
pkill qemu-system-x86
.PHONY: gdb_server
gdb_server: initramfs $(CARGO_OSDK)
@[ $(ENABLE_KVM) -eq 1 ] && \
([ $(KVM_EXISTS) -eq 1 ] || \
echo Warning: KVM not present on your system)
@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)
@[ $(ENABLE_KVM) -eq 1 ] && \
([ $(KVM_EXISTS) -eq 1 ] || \
echo Warning: KVM not present on your system)
@cd kernel && cargo osdk debug $(CARGO_OSDK_BUILD_ARGS) --remote :$(GDB_TCP_PORT)
.PHONY: profile_server
profile_server: initramfs $(CARGO_OSDK)
@[ $(ENABLE_KVM) -eq 1 ] && \
([ $(KVM_EXISTS) -eq 1 ] || \
echo Warning: KVM not present on your system)
@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: early_boot_test
early_boot_test: initramfs $(CARGO_OSDK)
@dir=ostd/tests/early-boot-test-kernel; \
echo "cd $$dir && cargo osdk run"; \
(cd $$dir && cargo osdk run) || exit 1;
.PHONY: docs
docs: private DEFAULT_PACKAGE_NAMES = \
$(shell ./tools/print_workspace_members.sh --default-ones --package-names)
docs: private DEFAULT_NON_KERNEL_PACKAGE_NAMES = \
$(filter-out aster-kernel,$(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_KERNEL_PACKAGE_NAMES)" ]; then \
RUSTDOCFLAGS="-Dwarnings" cargo osdk doc $(addprefix -p ,$(DEFAULT_NON_KERNEL_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 kernel 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-kernel --no-deps
@if [ "$(OSDK_TARGET_ARCH)" = "x86_64" ]; then \
cd ostd/libs/linux-bzimage/setup && RUSTDOCFLAGS="-Dwarnings" cargo osdk doc --no-deps; \
fi
.PHONY: book
book: book/mermaid.min.js book/mermaid-init.js
@cd book && mdbook build
book/mermaid.min.js book/mermaid-init.js:
@mdbook-mermaid install book/
.PHONY: format
format:
@./tools/format_all.sh
@nixfmt ./distro
@$(MAKE) --no-print-directory -C test/initramfs format
@$(MAKE) --no-print-directory -C test/nixos format
@black $(PYTHON_PROJECTS) $(EXTRA_PYTHON_FILES)
.PHONY: check
check: private WORKSPACE_MEMBER_DIRS = \
$(shell ./tools/print_workspace_members.sh)
check: $(CARGO_OSDK)
@# Check formatting issues of the Rust code
@./tools/format_all.sh --check
@
@# 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 compilation of the Rust code
@OSDK_TARGET_ARCH="$(OSDK_TARGET_ARCH)" ./tools/clippy_check.sh workspace -- $(CLIPPY_COMMON_ARGS)
@
@# 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
@# Check formatting issues of Nix files under distro directory
@nixfmt --check ./distro
@# Check python
@black --check $(PYTHON_PROJECTS) $(EXTRA_PYTHON_FILES)
# Here we build our mount cache
# TODO make this rule depend on the dockerfile version see #34
${DOCKER_RUST_CACHE_LOCATION}/generated:
mkdir -p ${DOCKER_RUST_CACHE_LOCATION}
docker create --name dummy $(DOCKER_IMAGE_TAG)
docker cp dummy:/root/.cargo ${CARGO_CACHE}
docker cp dummy:/root/.rustup ${RUSTUP_CACHE}
# Persistent bash history
touch ${BASH_HISTORY}
# Clean up dummy container
docker rm dummy
# Touch a file at the end to create some degree of "atomicity". If the cache
# location exists but hasn't been initialized yet, we still need to run this
# rule to initialize it.
touch $@
.PHONY: docker
docker: | ${DOCKER_RUST_CACHE_LOCATION}/generated
docker run --rm -it $(DOCKER_RUN_ARGS) $(DOCKER_MOUNTS) $(DOCKER_IMAGE_TAG)
.PHONY: docker_start
docker_start: | ${DOCKER_RUST_CACHE_LOCATION}/generated
docker ps -a | grep $(DOCKER_CONTAINER_NAME) || \
docker run -d --name $(DOCKER_CONTAINER_NAME) $(DOCKER_RUN_ARGS) $(DOCKER_MOUNTS) $(DOCKER_IMAGE_TAG) sleep infinity
.PHONY: docker_attach
docker_attach: docker_start
docker exec -it $(DOCKER_CONTAINER_NAME) /bin/bash -i
.PHONY: docker_rm
docker_rm:
docker stop $(DOCKER_CONTAINER_NAME)
docker rm $(DOCKER_CONTAINER_NAME)
.PHONY: clean
clean:
@if find target test osdk/target docs '!' -writable 2>/dev/null | grep -q .; then \
echo "ERROR: Found unwritable files in build directories"; \
echo "ERROR: This must be run from the same environment as the build (generally inside the container)."; \
echo "ERROR: You may be running it in the host environment after a build in docker. Run it in docker instead."; \
echo "ERROR: (Note: Using "sudo make clean" will not work as the host environment may not have the correct tools.)"; \
false; \
else \
true; \
fi
@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)
.PHONY: clean_cache
clean_cache:
@[ '!' -f /.dockerenv ] || ( \
echo "ERROR: Cleaning the Cargo and rustup caches from within the container is not allowed. Run it from the host environment."; \
false \
)
@if find $(DOCKER_RUST_CACHE_LOCATION) '!' -writable 2>/dev/null | grep -q .; then \
echo "ERROR: Found unwritable files in cache directory."; \
echo "ERROR: The container has probably created root owned files in cache. To fix that, run this as root: sudo make clean_cache"; \
false; \
else \
true; \
fi
rm -rf $(DOCKER_RUST_CACHE_LOCATION)
.PHONY: clean_all
clean_all: clean clean_cache