asterinas/Makefile

226 lines
6.5 KiB
Makefile
Raw Normal View History

# SPDX-License-Identifier: MPL-2.0
2024-04-12 17:08:36 +00:00
# Global options.
ARCH ?= x86_64
2024-04-12 17:08:36 +00:00
BOOT_METHOD ?= grub-rescue-iso
BOOT_PROTOCOL ?= multiboot2
BUILD_SYSCALL_TEST ?= 0
ENABLE_KVM ?= 1
GDB_TCP_PORT ?= 1234
2024-04-12 17:08:36 +00:00
INTEL_TDX ?= 0
2024-05-06 09:36:31 +00:00
RELEASE ?= 0
RELEASE_LTO ?= 0
2024-04-12 17:08:36 +00:00
SCHEME ?= ""
# End of global 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
EXTRA_BLOCKLISTS_DIRS ?= ""
2023-11-28 04:17:42 +00:00
SYSCALL_TEST_DIR ?= /tmp
# End of auto test features.
2024-03-01 07:42:06 +00:00
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
2024-04-12 17:08:36 +00:00
CARGO_OSDK_ARGS := --target-arch=$(ARCH)
ifeq ($(AUTO_TEST), syscall)
BUILD_SYSCALL_TEST := 1
2024-04-12 17:08:36 +00:00
CARGO_OSDK_ARGS += --kcmd-args="SYSCALL_TEST_DIR=$(SYSCALL_TEST_DIR)"
CARGO_OSDK_ARGS += --kcmd-args="EXTRA_BLOCKLISTS_DIRS=$(EXTRA_BLOCKLISTS_DIRS)"
CARGO_OSDK_ARGS += --init-args="/opt/syscall_test/run_syscall_test.sh"
else ifeq ($(AUTO_TEST), regression)
2024-04-12 17:08:36 +00:00
CARGO_OSDK_ARGS += --init-args="/regression/run_regression_test.sh"
else ifeq ($(AUTO_TEST), boot)
2024-05-06 15:00:48 +00:00
CARGO_OSDK_ARGS += --init-args="/regression/boot_hello.sh"
2024-04-07 15:08:18 +00:00
else ifeq ($(AUTO_TEST), vsock)
export VSOCK=1
2024-05-06 15:00:48 +00:00
CARGO_OSDK_ARGS += --init-args="/regression/run_vsock_test.sh"
endif
2024-05-06 09:36:31 +00:00
ifeq ($(RELEASE_LTO), 1)
CARGO_OSDK_ARGS += --profile release-lto
else ifeq ($(RELEASE), 1)
CARGO_OSDK_ARGS += --release
endif
ifeq ($(INTEL_TDX), 1)
2024-05-08 07:58:56 +00:00
BOOT_PROTOCOL = linux-efi-handover64
CARGO_OSDK_ARGS += --scheme tdx
CARGO_OSDK_ARGS += --features intel_tdx
endif
2024-04-12 17:08:36 +00:00
ifneq ($(SCHEME), "")
CARGO_OSDK_ARGS += --scheme $(SCHEME)
else
CARGO_OSDK_ARGS += --boot-method="$(BOOT_METHOD)"
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)
2024-03-22 05:50:45 +00:00
CARGO_OSDK_ARGS += --grub-mkrescue=/usr/bin/grub-mkrescue
2024-04-12 17:08:36 +00:00
CARGO_OSDK_ARGS += --grub-boot-protocol="linux"
else ifeq ($(BOOT_PROTOCOL), linux-legacy32)
CARGO_OSDK_ARGS += --linux-x86-legacy-boot
CARGO_OSDK_ARGS += --grub-boot-protocol="linux"
else
CARGO_OSDK_ARGS += --grub-boot-protocol=$(BOOT_PROTOCOL)
2023-11-04 08:41:30 +00:00
endif
ifeq ($(ENABLE_KVM), 1)
2024-04-12 17:08:36 +00:00
CARGO_OSDK_ARGS += --qemu-args="--enable-kvm"
endif
# Pass make variables to all subdirectory makes
export
2024-02-27 16:44:55 +00:00
# Basically, non-OSDK crates do not depend on Aster Frame and can be checked
# or tested without OSDK.
NON_OSDK_CRATES := \
framework/libs/align_ext \
framework/libs/aster-main \
framework/libs/id-alloc \
2023-12-29 07:32:06 +00:00
framework/libs/linux-bzimage/builder \
framework/libs/linux-bzimage/boot-params \
2024-02-27 16:44:55 +00:00
framework/libs/ktest \
framework/libs/ktest-proc-macro \
kernel/libs/cpio-decoder \
kernel/libs/int-to-c-enum \
kernel/libs/int-to-c-enum/derive \
kernel/libs/aster-rights \
kernel/libs/aster-rights-proc \
kernel/libs/keyable-arc \
kernel/libs/typeflags \
kernel/libs/typeflags-util
# In contrast, OSDK crates depend on Aster Frame (or being aster-frame itself)
# and need to be built or tested with OSDK.
OSDK_CRATES := \
framework/aster-frame \
framework/libs/linux-bzimage/setup \
kernel \
kernel/aster-nix \
kernel/comps/block \
kernel/comps/console \
kernel/comps/framebuffer \
kernel/comps/input \
kernel/comps/network \
kernel/comps/time \
kernel/comps/virtio \
kernel/libs/aster-util
2024-02-23 03:50:27 +00:00
.PHONY: all
2023-04-10 03:12:42 +00:00
all: build
2022-08-08 22:43:47 +00:00
2024-02-28 05:11:45 +00:00
# Install or update OSDK from source
# To uninstall, do `cargo uninstall cargo-osdk`
2024-02-23 03:50:27 +00:00
.PHONY: install_osdk
2024-03-01 07:42:06 +00:00
install_osdk:
@cargo install cargo-osdk --path osdk
2022-08-17 03:22:49 +00:00
2024-03-01 07:42:06 +00:00
# This will install OSDK if it is not already installed
# To update OSDK, we need to run `install_osdk` manually
$(CARGO_OSDK):
@make --no-print-directory install_osdk
2024-02-28 05:11:45 +00:00
2024-02-29 15:44:41 +00:00
.PHONY: initramfs
initramfs:
2023-05-29 05:29:53 +00:00
@make --no-print-directory -C regression
2024-02-29 15:44:41 +00:00
.PHONY: build
build: initramfs $(CARGO_OSDK)
@cargo osdk build $(CARGO_OSDK_ARGS)
2023-08-07 02:56:03 +00:00
2024-02-23 03:50:27 +00:00
.PHONY: tools
2023-02-07 08:05:21 +00:00
tools:
2024-02-27 08:40:16 +00:00
@cd kernel/libs/comp-sys && cargo install --path cargo-component
2023-02-07 08:05:21 +00:00
2024-02-23 03:50:27 +00:00
.PHONY: run
2022-08-17 03:22:49 +00:00
run: build
@cargo osdk run $(CARGO_OSDK_ARGS)
# Check the running status of auto tests from the QEMU log
ifeq ($(AUTO_TEST), syscall)
@tail --lines 100 qemu.log | grep -q "^.* of .* test cases passed." \
|| (echo "Syscall 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)
2024-04-07 15:08:18 +00:00
else ifeq ($(AUTO_TEST), vsock)
@tail --lines 100 qemu.log | grep -q "^Vsock test passed." \
|| (echo "Vsock test failed" && exit 1)
endif
gdb_server: initramfs $(CARGO_OSDK)
@cargo osdk run $(CARGO_OSDK_ARGS) -G --vsc --gdb-server-addr :$(GDB_TCP_PORT)
2024-03-20 21:52:55 +00:00
.PHONY: gdb_client
gdb_client: $(CARGO_OSDK)
@cd kernel && cargo osdk debug $(CARGO_OSDK_ARGS) --remote :$(GDB_TCP_PORT)
2024-03-20 21:52:55 +00:00
2024-02-23 03:50:27 +00:00
.PHONY: test
2023-11-04 08:41:30 +00:00
test:
2024-02-27 16:44:55 +00:00
@for dir in $(NON_OSDK_CRATES); do \
(cd $$dir && cargo test) || exit 1; \
done
2022-08-08 22:43:47 +00:00
2024-02-23 03:50:27 +00:00
.PHONY: ktest
2024-02-29 15:44:41 +00:00
ktest: initramfs $(CARGO_OSDK)
2024-02-27 16:44:55 +00:00
@# Exclude linux-bzimage-setup from ktest since it's hard to be unit tested
@for dir in $(OSDK_CRATES); do \
[ $$dir = "framework/libs/linux-bzimage/setup" ] && continue; \
(cd $$dir && cargo osdk test) || exit 1; \
done
docs: $(CARGO_OSDK)
@for dir in $(NON_OSDK_CRATES); do \
(cd $$dir && cargo doc --no-deps) || exit 1; \
done
@for dir in $(OSDK_CRATES); do \
(cd $$dir && cargo osdk doc --no-deps) || exit 1; \
done
@echo "" # Add a blank line
2022-08-08 23:02:55 +00:00
@cd docs && mdbook build # Build mdBook
2022-08-08 22:43:47 +00:00
2024-02-23 03:50:27 +00:00
.PHONY: format
format:
2024-02-27 12:28:43 +00:00
@./tools/format_all.sh
@make --no-print-directory -C regression format
2024-02-23 03:50:27 +00:00
.PHONY: check
check: $(CARGO_OSDK)
2024-02-27 16:44:55 +00:00
@./tools/format_all.sh --check # Check Rust format issues
@# Check if STD_CRATES and NOSTD_CRATES combined is the same as all workspace members
2024-02-23 03:50:27 +00:00
@sed -n '/^\[workspace\]/,/^\[.*\]/{/members = \[/,/\]/p}' Cargo.toml | \
grep -v "members = \[" | tr -d '", \]' | \
sort > /tmp/all_crates
2024-02-27 16:44:55 +00:00
@echo $(NON_OSDK_CRATES) $(OSDK_CRATES) | tr ' ' '\n' | sort > /tmp/combined_crates
2024-02-23 03:50:27 +00:00
@diff -B /tmp/all_crates /tmp/combined_crates || \
(echo "Error: The combination of STD_CRATES and NOSTD_CRATES" \
"is not the same as all workspace members" && exit 1)
2024-02-27 16:44:55 +00:00
@rm /tmp/all_crates /tmp/combined_crates
@for dir in $(NON_OSDK_CRATES); do \
2024-04-12 17:08:36 +00:00
echo "Checking $$dir"; \
2024-02-27 16:44:55 +00:00
(cd $$dir && cargo clippy -- -D warnings) || exit 1; \
done
@for dir in $(OSDK_CRATES); do \
2024-04-12 17:08:36 +00:00
echo "Checking $$dir"; \
(cd $$dir && cargo osdk clippy -- -- -D warnings) || exit 1; \
2024-02-27 16:44:55 +00:00
done
@make --no-print-directory -C regression check
2022-08-08 22:43:47 +00:00
2024-05-03 13:52:11 +00:00
.PHONY: check_osdk
check_osdk:
@cd osdk && cargo clippy -- -D warnings
2024-02-23 03:50:27 +00:00
.PHONY: clean
2022-08-08 22:43:47 +00:00
clean:
2023-04-10 03:12:42 +00:00
@cargo clean
2022-08-17 03:22:49 +00:00
@cd docs && mdbook clean
@make --no-print-directory -C regression clean
@rm -f $(CARGO_OSDK)