2024-01-03 06:40:54 +00:00
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2024-09-21 12:37:30 +00:00
|
|
|
# =========================== Makefile options. ===============================
|
|
|
|
|
|
|
|
|
|
# Global build options.
|
2025-08-19 08:56:19 +00:00
|
|
|
OSDK_TARGET_ARCH ?= x86_64
|
2024-06-26 12:07:44 +00:00
|
|
|
BENCHMARK ?= none
|
2024-04-12 17:08:36 +00:00
|
|
|
BOOT_METHOD ?= grub-rescue-iso
|
|
|
|
|
BOOT_PROTOCOL ?= multiboot2
|
|
|
|
|
BUILD_SYSCALL_TEST ?= 0
|
|
|
|
|
ENABLE_KVM ?= 1
|
|
|
|
|
INTEL_TDX ?= 0
|
2024-07-07 16:13:02 +00:00
|
|
|
MEM ?= 8G
|
2024-11-04 04:03:18 +00:00
|
|
|
OVMF ?= on
|
2024-05-06 09:36:31 +00:00
|
|
|
RELEASE ?= 0
|
|
|
|
|
RELEASE_LTO ?= 0
|
2024-06-28 05:29:28 +00:00
|
|
|
LOG_LEVEL ?= error
|
2024-04-12 17:08:36 +00:00
|
|
|
SCHEME ?= ""
|
2024-07-07 16:13:02 +00:00
|
|
|
SMP ?= 1
|
2024-08-22 09:45:28 +00:00
|
|
|
OSTD_TASK_STACK_SIZE_IN_PAGES ?= 64
|
2025-03-19 05:53:41 +00:00
|
|
|
FEATURES ?=
|
|
|
|
|
NO_DEFAULT_FEATURES ?= 0
|
2025-06-25 03:53:10 +00:00
|
|
|
COVERAGE ?= 0
|
2026-01-12 02:02:10 +00:00
|
|
|
# Specify whether to build regression tests under `test/initramfs/src/apps`.
|
2025-07-17 09:37:02 +00:00
|
|
|
ENABLE_BASIC_TEST ?= false
|
2026-01-07 09:52:15 +00:00
|
|
|
# Specify the primary system console (supported: tty0, ttyS0, hvc0).
|
2025-11-28 02:03:02 +00:00
|
|
|
# - tty0: The active virtual terminal (VT).
|
2026-01-07 09:52:15 +00:00
|
|
|
# - ttyS0: The serial (UART) terminal.
|
|
|
|
|
# - hvc0: The virtio-console terminal.
|
2025-11-28 02:03:02 +00:00
|
|
|
# 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
|
2024-09-21 12:37:30 +00:00
|
|
|
# End of global build options.
|
|
|
|
|
|
|
|
|
|
# GDB debugging and profiling options.
|
|
|
|
|
GDB_TCP_PORT ?= 1234
|
2024-09-29 03:49:39 +00:00
|
|
|
GDB_PROFILE_FORMAT ?= flame-graph
|
2024-09-21 12:37:30 +00:00
|
|
|
GDB_PROFILE_COUNT ?= 200
|
|
|
|
|
GDB_PROFILE_INTERVAL ?= 0.1
|
|
|
|
|
# End of GDB options.
|
2024-04-22 14:23:24 +00:00
|
|
|
|
2024-02-21 08:58:40 +00:00
|
|
|
# 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.
|
2023-10-26 03:27:35 +00:00
|
|
|
AUTO_TEST ?= none
|
2024-04-22 14:23:24 +00:00
|
|
|
EXTRA_BLOCKLISTS_DIRS ?= ""
|
2025-05-20 07:55:59 +00:00
|
|
|
SYSCALL_TEST_WORKDIR ?= /tmp
|
2024-02-21 08:58:40 +00:00
|
|
|
# End of auto test features.
|
|
|
|
|
|
2024-10-22 02:02:19 +00:00
|
|
|
# Network settings
|
2024-12-10 02:08:58 +00:00
|
|
|
# NETDEV possible values are user,tap
|
|
|
|
|
NETDEV ?= user
|
2024-11-02 02:59:39 +00:00
|
|
|
VHOST ?= off
|
2025-10-21 03:14:20 +00:00
|
|
|
# The name server listed by /etc/resolv.conf inside the Asterinas VM
|
|
|
|
|
DNS_SERVER ?= none
|
2024-10-22 02:02:19 +00:00
|
|
|
# End of network settings
|
|
|
|
|
|
2025-11-25 03:37:47 +00:00
|
|
|
# NixOS settings
|
2025-12-10 03:26:22 +00:00
|
|
|
NIXOS_DISK_SIZE_IN_MB ?= 8192
|
2025-12-09 07:30:02 +00:00
|
|
|
NIXOS_DISABLE_SYSTEMD ?= false
|
2025-11-25 03:37:47 +00:00
|
|
|
# The following option is only effective when NIXOS_DISABLE_SYSTEMD is set to 'true'.
|
2025-12-02 10:01:50 +00:00
|
|
|
# Use a login shell to ensure that environment variables are initialized correctly.
|
|
|
|
|
NIXOS_STAGE_2_INIT ?= /bin/sh -l
|
2025-11-25 03:37:47 +00:00
|
|
|
# End of NixOS settings
|
|
|
|
|
|
2025-12-11 13:10:10 +00:00
|
|
|
# ISO installer settings
|
|
|
|
|
AUTO_INSTALL ?= true
|
|
|
|
|
# End of ISO installer settings
|
|
|
|
|
|
2025-12-11 15:18:54 +00:00
|
|
|
# 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
|
|
|
|
|
|
2024-09-21 12:37:30 +00:00
|
|
|
# ========================= End of Makefile options. ==========================
|
|
|
|
|
|
2025-04-30 12:54:24 +00:00
|
|
|
SHELL := /bin/bash
|
|
|
|
|
|
2024-03-01 07:42:06 +00:00
|
|
|
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
|
|
|
|
|
|
2025-06-13 12:35:53 +00:00
|
|
|
# Common arguments for `cargo osdk` `build`, `run` and `test` commands.
|
2025-08-19 08:56:19 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS := --target-arch=$(OSDK_TARGET_ARCH)
|
2025-06-13 12:35:53 +00:00
|
|
|
# The build arguments also apply to the `cargo osdk run` command.
|
|
|
|
|
CARGO_OSDK_BUILD_ARGS := --kcmd-args="ostd.log_level=$(LOG_LEVEL)"
|
2025-11-28 02:03:02 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="console=$(CONSOLE)"
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_TEST_ARGS :=
|
2023-08-02 11:08:02 +00:00
|
|
|
|
2023-10-23 10:58:40 +00:00
|
|
|
ifeq ($(AUTO_TEST), syscall)
|
|
|
|
|
BUILD_SYSCALL_TEST := 1
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="SYSCALL_TEST_SUITE=$(SYSCALL_TEST_SUITE)"
|
|
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="SYSCALL_TEST_WORKDIR=$(SYSCALL_TEST_WORKDIR)"
|
|
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="EXTRA_BLOCKLISTS_DIRS=$(EXTRA_BLOCKLISTS_DIRS)"
|
|
|
|
|
CARGO_OSDK_BUILD_ARGS += --init-args="/opt/syscall_test/run_syscall_test.sh"
|
2024-06-28 11:12:24 +00:00
|
|
|
else ifeq ($(AUTO_TEST), test)
|
2025-07-17 09:37:02 +00:00
|
|
|
ENABLE_BASIC_TEST := true
|
2024-08-26 10:04:55 +00:00
|
|
|
ifneq ($(SMP), 1)
|
2025-12-02 14:56:01 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="BLOCK_UNSUPPORTED_SMP_TESTS=1"
|
2024-08-26 10:04:55 +00:00
|
|
|
endif
|
2025-09-30 05:58:47 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --kcmd-args="INTEL_TDX=$(INTEL_TDX)"
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --init-args="/test/run_general_test.sh"
|
2024-04-09 04:34:01 +00:00
|
|
|
else ifeq ($(AUTO_TEST), boot)
|
2025-07-17 09:37:02 +00:00
|
|
|
ENABLE_BASIC_TEST := true
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --init-args="/test/boot_hello.sh"
|
2024-04-07 15:08:18 +00:00
|
|
|
else ifeq ($(AUTO_TEST), vsock)
|
2025-07-17 09:37:02 +00:00
|
|
|
ENABLE_BASIC_TEST := true
|
2024-11-04 04:03:18 +00:00
|
|
|
export VSOCK=on
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --init-args="/test/run_vsock_test.sh"
|
2023-10-23 10:58:40 +00:00
|
|
|
endif
|
2023-08-02 11:08:02 +00:00
|
|
|
|
2024-05-06 09:36:31 +00:00
|
|
|
ifeq ($(RELEASE_LTO), 1)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --profile release-lto
|
2024-08-22 09:45:28 +00:00
|
|
|
OSTD_TASK_STACK_SIZE_IN_PAGES = 8
|
2024-05-06 09:36:31 +00:00
|
|
|
else ifeq ($(RELEASE), 1)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --release
|
2025-08-28 14:58:08 +00:00
|
|
|
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
|
2023-11-02 06:09:37 +00:00
|
|
|
endif
|
|
|
|
|
|
2024-08-29 03:52:25 +00:00
|
|
|
# If the BENCHMARK is set, we will run the benchmark in the kernel mode.
|
|
|
|
|
ifneq ($(BENCHMARK), none)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += --init-args="/benchmark/common/bench_runner.sh $(BENCHMARK) asterinas"
|
2024-08-29 03:52:25 +00:00
|
|
|
endif
|
|
|
|
|
|
2024-01-28 06:54:38 +00:00
|
|
|
ifeq ($(INTEL_TDX), 1)
|
2024-07-09 02:34:59 +00:00
|
|
|
BOOT_METHOD = grub-qcow2
|
2024-05-08 07:58:56 +00:00
|
|
|
BOOT_PROTOCOL = linux-efi-handover64
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --scheme tdx
|
2023-09-10 11:23:53 +00:00
|
|
|
endif
|
|
|
|
|
|
2025-04-06 10:05:47 +00:00
|
|
|
ifeq ($(BOOT_PROTOCOL), linux-legacy32)
|
|
|
|
|
BOOT_METHOD = qemu-direct
|
|
|
|
|
OVMF = off
|
|
|
|
|
else ifeq ($(BOOT_PROTOCOL), multiboot)
|
|
|
|
|
BOOT_METHOD = qemu-direct
|
|
|
|
|
OVMF = off
|
|
|
|
|
endif
|
|
|
|
|
|
2025-10-29 03:37:22 +00:00
|
|
|
ifeq ($(SCHEME), "")
|
|
|
|
|
ifeq ($(OSDK_TARGET_ARCH), riscv64)
|
|
|
|
|
SCHEME = riscv
|
|
|
|
|
else ifeq ($(OSDK_TARGET_ARCH), loongarch64)
|
|
|
|
|
SCHEME = loongarch
|
|
|
|
|
endif
|
2025-06-13 12:35:53 +00:00
|
|
|
endif
|
|
|
|
|
|
2024-04-12 17:08:36 +00:00
|
|
|
ifneq ($(SCHEME), "")
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --scheme $(SCHEME)
|
2024-04-12 17:08:36 +00:00
|
|
|
else
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --boot-method="$(BOOT_METHOD)"
|
2023-08-02 11:08:02 +00:00
|
|
|
endif
|
|
|
|
|
|
2025-06-25 03:53:10 +00:00
|
|
|
ifeq ($(COVERAGE), 1)
|
|
|
|
|
CARGO_OSDK_COMMON_ARGS += --coverage
|
|
|
|
|
endif
|
|
|
|
|
|
2024-11-02 02:59:39 +00:00
|
|
|
ifdef FEATURES
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --features="$(FEATURES)"
|
2024-11-02 02:59:39 +00:00
|
|
|
endif
|
2025-03-19 05:53:41 +00:00
|
|
|
ifeq ($(NO_DEFAULT_FEATURES), 1)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --no-default-features
|
2025-03-19 05:53:41 +00:00
|
|
|
endif
|
2024-11-02 02:59:39 +00:00
|
|
|
|
2024-02-21 08:58:40 +00:00
|
|
|
# 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)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --grub-mkrescue=/usr/bin/grub-mkrescue --grub-boot-protocol="linux"
|
2025-03-12 14:47:29 +00:00
|
|
|
else ifeq ($(BOOT_PROTOCOL), linux-efi-pe64)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol="linux"
|
2024-04-12 17:08:36 +00:00
|
|
|
else ifeq ($(BOOT_PROTOCOL), linux-legacy32)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --linux-x86-legacy-boot --grub-boot-protocol="linux"
|
2024-04-12 17:08:36 +00:00
|
|
|
else
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol=$(BOOT_PROTOCOL)
|
2023-11-04 08:41:30 +00:00
|
|
|
endif
|
|
|
|
|
|
2024-02-21 08:58:40 +00:00
|
|
|
ifeq ($(ENABLE_KVM), 1)
|
2025-08-19 08:56:19 +00:00
|
|
|
ifeq ($(OSDK_TARGET_ARCH), x86_64)
|
2025-12-02 14:56:01 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += --qemu-args="-accel kvm"
|
2025-06-13 12:35:53 +00:00
|
|
|
endif
|
2023-08-02 11:08:02 +00:00
|
|
|
endif
|
|
|
|
|
|
2024-12-15 14:28:02 +00:00
|
|
|
# Skip GZIP to make encoding and decoding of initramfs faster
|
|
|
|
|
ifeq ($(INITRAMFS_SKIP_GZIP),1)
|
2026-01-12 02:02:10 +00:00
|
|
|
CARGO_OSDK_INITRAMFS_OPTION := --initramfs=$(abspath test/initramfs/build/initramfs.cpio)
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_COMMON_ARGS += $(CARGO_OSDK_INITRAMFS_OPTION)
|
2024-12-15 14:28:02 +00:00
|
|
|
endif
|
|
|
|
|
|
2025-06-13 12:35:53 +00:00
|
|
|
CARGO_OSDK_BUILD_ARGS += $(CARGO_OSDK_COMMON_ARGS)
|
|
|
|
|
CARGO_OSDK_TEST_ARGS += $(CARGO_OSDK_COMMON_ARGS)
|
|
|
|
|
|
2023-08-02 11:08:02 +00:00
|
|
|
# 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 := \
|
2024-06-19 08:18:39 +00:00
|
|
|
ostd/libs/align_ext \
|
|
|
|
|
ostd/libs/id-alloc \
|
2025-12-25 10:54:12 +00:00
|
|
|
ostd/libs/int-to-c-enum \
|
|
|
|
|
ostd/libs/int-to-c-enum/derive \
|
2024-06-19 08:18:39 +00:00
|
|
|
ostd/libs/linux-bzimage/boot-params \
|
2026-01-12 15:53:54 +00:00
|
|
|
ostd/libs/linux-bzimage/builder \
|
2024-06-21 05:51:13 +00:00
|
|
|
ostd/libs/ostd-macros \
|
2026-01-26 08:31:35 +00:00
|
|
|
ostd/libs/ostd-pod \
|
|
|
|
|
ostd/libs/ostd-pod/macros \
|
2024-07-01 08:00:09 +00:00
|
|
|
ostd/libs/ostd-test \
|
2026-01-16 08:22:15 +00:00
|
|
|
ostd/libs/padding-struct \
|
2025-09-13 07:10:11 +00:00
|
|
|
kernel/libs/aster-rights \
|
|
|
|
|
kernel/libs/aster-rights-proc \
|
|
|
|
|
kernel/libs/atomic-integer-wrapper \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/libs/cpio-decoder \
|
2024-12-27 08:27:42 +00:00
|
|
|
kernel/libs/jhash \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/libs/keyable-arc \
|
2025-09-13 07:10:11 +00:00
|
|
|
kernel/libs/logo-ascii-art \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/libs/typeflags \
|
2025-12-25 07:17:37 +00:00
|
|
|
kernel/libs/typeflags-util
|
2024-02-27 16:44:55 +00:00
|
|
|
|
2024-06-19 08:18:39 +00:00
|
|
|
# In contrast, OSDK crates depend on OSTD (or being `ostd` itself)
|
2024-02-27 16:44:55 +00:00
|
|
|
# and need to be built or tested with OSDK.
|
|
|
|
|
OSDK_CRATES := \
|
2025-03-11 08:57:10 +00:00
|
|
|
osdk/deps/frame-allocator \
|
2025-01-13 06:24:32 +00:00
|
|
|
osdk/deps/heap-allocator \
|
2025-01-04 11:43:50 +00:00
|
|
|
osdk/deps/test-kernel \
|
2024-06-19 08:18:39 +00:00
|
|
|
ostd \
|
|
|
|
|
ostd/libs/linux-bzimage/setup \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel \
|
|
|
|
|
kernel/comps/block \
|
2025-12-02 15:42:40 +00:00
|
|
|
kernel/comps/cmdline \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/comps/console \
|
|
|
|
|
kernel/comps/framebuffer \
|
2025-11-04 08:06:28 +00:00
|
|
|
kernel/comps/i8042 \
|
2026-01-12 15:53:54 +00:00
|
|
|
kernel/comps/input \
|
|
|
|
|
kernel/comps/logger \
|
|
|
|
|
kernel/comps/mlsdisk \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/comps/network \
|
2026-01-12 15:53:54 +00:00
|
|
|
kernel/comps/pci \
|
2024-10-17 09:41:24 +00:00
|
|
|
kernel/comps/softirq \
|
2025-04-24 10:04:37 +00:00
|
|
|
kernel/comps/systree \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/comps/time \
|
2025-12-22 14:00:03 +00:00
|
|
|
kernel/comps/uart \
|
2024-02-27 16:44:55 +00:00
|
|
|
kernel/comps/virtio \
|
2025-04-18 02:41:54 +00:00
|
|
|
kernel/libs/aster-bigtcp \
|
2026-01-12 15:53:54 +00:00
|
|
|
kernel/libs/aster-util \
|
2025-11-19 08:20:13 +00:00
|
|
|
kernel/libs/device-id \
|
2025-04-18 02:41:54 +00:00
|
|
|
kernel/libs/xarray
|
2024-02-21 08:58:40 +00:00
|
|
|
|
2024-12-09 08:25:49 +00:00
|
|
|
# OSDK dependencies
|
|
|
|
|
OSDK_SRC_FILES := \
|
|
|
|
|
$(shell find osdk/Cargo.toml osdk/Cargo.lock osdk/src -type f)
|
|
|
|
|
|
2024-02-23 03:50:27 +00:00
|
|
|
.PHONY: all
|
2025-12-11 13:10:10 +00:00
|
|
|
all: kernel
|
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:
|
2024-08-13 14:51:27 +00:00
|
|
|
@# 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
|
2022-08-17 03:22:49 +00:00
|
|
|
|
2024-12-09 08:25:49 +00:00
|
|
|
# This will install and update OSDK automatically
|
|
|
|
|
$(CARGO_OSDK): $(OSDK_SRC_FILES)
|
|
|
|
|
@$(MAKE) --no-print-directory install_osdk
|
2024-02-28 05:11:45 +00:00
|
|
|
|
2024-08-25 11:31:32 +00:00
|
|
|
.PHONY: check_osdk
|
|
|
|
|
check_osdk:
|
2026-01-04 11:13:43 +00:00
|
|
|
@# Run clippy on OSDK with and without the test configuration.
|
2026-02-07 15:45:25 +00:00
|
|
|
@cd osdk && RUSTFLAGS="-Dwarnings" cargo clippy --no-deps
|
|
|
|
|
@cd osdk && RUSTFLAGS="-Dwarnings" cargo clippy --tests --no-deps
|
2024-08-25 11:31:32 +00:00
|
|
|
|
|
|
|
|
.PHONY: test_osdk
|
|
|
|
|
test_osdk:
|
|
|
|
|
@cd osdk && \
|
|
|
|
|
OSDK_LOCAL_DEV=1 cargo build && \
|
|
|
|
|
OSDK_LOCAL_DEV=1 cargo test
|
|
|
|
|
|
2025-08-24 02:12:08 +00:00
|
|
|
.PHONY: check_vdso
|
|
|
|
|
check_vdso:
|
|
|
|
|
@# Checking `VDSO_LIBRARY_DIR` environment variable
|
|
|
|
|
@if [ -z "$(VDSO_LIBRARY_DIR)" ]; then \
|
2025-12-26 16:12:24 +00:00
|
|
|
echo "Error: the VDSO_LIBRARY_DIR environment variable must be given."; \
|
2025-08-24 02:12:08 +00:00
|
|
|
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
|
|
|
|
|
|
2024-02-29 15:44:41 +00:00
|
|
|
.PHONY: initramfs
|
2025-08-24 02:12:08 +00:00
|
|
|
initramfs: check_vdso
|
2026-01-12 02:02:10 +00:00
|
|
|
@$(MAKE) --no-print-directory -C test/initramfs
|
2024-02-29 15:44:41 +00:00
|
|
|
|
2025-12-11 13:10:10 +00:00
|
|
|
# Build the kernel with an initramfs
|
|
|
|
|
.PHONY: kernel
|
|
|
|
|
kernel: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk build $(CARGO_OSDK_BUILD_ARGS)
|
2023-08-07 02:56:03 +00:00
|
|
|
|
2025-12-11 13:10:10 +00:00
|
|
|
# Build the kernel with an initramfs and then run it
|
|
|
|
|
.PHONY: run_kernel
|
|
|
|
|
run_kernel: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS)
|
2024-04-09 04:34:01 +00:00
|
|
|
# Check the running status of auto tests from the QEMU log
|
|
|
|
|
ifeq ($(AUTO_TEST), syscall)
|
2025-06-04 02:15:25 +00:00
|
|
|
@tail --lines 100 qemu.log | grep -q "^All syscall tests passed." \
|
2024-06-21 08:17:58 +00:00
|
|
|
|| (echo "Syscall test failed" && exit 1)
|
2024-06-28 11:12:24 +00:00
|
|
|
else ifeq ($(AUTO_TEST), test)
|
|
|
|
|
@tail --lines 100 qemu.log | grep -q "^All general tests passed." \
|
|
|
|
|
|| (echo "General test failed" && exit 1)
|
2024-04-09 04:34:01 +00:00
|
|
|
else ifeq ($(AUTO_TEST), boot)
|
2024-06-21 08:17:58 +00:00
|
|
|
@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)
|
2024-06-21 08:17:58 +00:00
|
|
|
@tail --lines 100 qemu.log | grep -q "^Vsock test passed." \
|
|
|
|
|
|| (echo "Vsock test failed" && exit 1)
|
2024-04-09 04:34:01 +00:00
|
|
|
endif
|
2023-07-26 07:36:40 +00:00
|
|
|
|
2025-12-11 13:10:10 +00:00
|
|
|
# Build the Asterinas NixOS ISO installer image
|
|
|
|
|
iso: BOOT_PROTOCOL = linux-efi-handover64
|
|
|
|
|
iso:
|
|
|
|
|
@make kernel
|
2026-01-13 08:58:30 +00:00
|
|
|
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
|
|
|
|
|
$(MAKE) --no-print-directory -C test/nixos iso; \
|
|
|
|
|
else \
|
|
|
|
|
./tools/nixos/build_iso.sh; \
|
|
|
|
|
fi
|
2025-12-11 13:10:10 +00:00
|
|
|
|
|
|
|
|
# Build the Asterinas NixOS ISO installer image and then do installation
|
|
|
|
|
run_iso: OVMF = off
|
|
|
|
|
run_iso:
|
2026-01-04 09:02:47 +00:00
|
|
|
@./tools/nixos/run.sh iso
|
2025-12-11 13:10:10 +00:00
|
|
|
|
|
|
|
|
# Create an Asterinas NixOS installation on host
|
|
|
|
|
nixos: BOOT_PROTOCOL = linux-efi-handover64
|
|
|
|
|
nixos:
|
|
|
|
|
@make kernel
|
2026-01-13 08:58:30 +00:00
|
|
|
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
|
|
|
|
|
$(MAKE) --no-print-directory -C test/nixos nixos; \
|
|
|
|
|
else \
|
|
|
|
|
./tools/nixos/build_nixos.sh; \
|
|
|
|
|
fi
|
2025-12-11 13:10:10 +00:00
|
|
|
|
|
|
|
|
# After creating a Asterinas NixOS installation (via either the `run_iso` or `nixos` target),
|
|
|
|
|
# run the NixOS
|
|
|
|
|
run_nixos: OVMF = off
|
|
|
|
|
run_nixos:
|
2026-01-13 08:58:30 +00:00
|
|
|
@if [ -n "$(NIXOS_TEST_SUITE)" ]; then \
|
|
|
|
|
$(MAKE) --no-print-directory -C test/nixos run_nixos; \
|
|
|
|
|
else \
|
|
|
|
|
./tools/nixos/run.sh nixos; \
|
|
|
|
|
fi
|
2025-12-11 13:10:10 +00:00
|
|
|
|
2025-12-11 15:18:54 +00:00
|
|
|
# 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
|
|
|
|
|
|
2024-06-21 08:39:32 +00:00
|
|
|
.PHONY: gdb_server
|
2024-04-22 14:42:14 +00:00
|
|
|
gdb_server: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS) --gdb-server wait-client,vscode,addr=:$(GDB_TCP_PORT)
|
2024-03-20 21:52:55 +00:00
|
|
|
|
|
|
|
|
.PHONY: gdb_client
|
2024-12-09 08:25:49 +00:00
|
|
|
gdb_client: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk debug $(CARGO_OSDK_BUILD_ARGS) --remote :$(GDB_TCP_PORT)
|
2024-09-21 12:37:30 +00:00
|
|
|
|
|
|
|
|
.PHONY: profile_server
|
|
|
|
|
profile_server: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk run $(CARGO_OSDK_BUILD_ARGS) --gdb-server addr=:$(GDB_TCP_PORT)
|
2024-09-21 12:37:30 +00:00
|
|
|
|
|
|
|
|
.PHONY: profile_client
|
2024-12-09 08:25:49 +00:00
|
|
|
profile_client: initramfs $(CARGO_OSDK)
|
2025-06-13 12:35:53 +00:00
|
|
|
@cd kernel && cargo osdk profile $(CARGO_OSDK_BUILD_ARGS) --remote :$(GDB_TCP_PORT) \
|
2024-09-21 12:37:30 +00:00
|
|
|
--samples $(GDB_PROFILE_COUNT) --interval $(GDB_PROFILE_INTERVAL) --format $(GDB_PROFILE_FORMAT)
|
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 \
|
2023-11-06 07:42:26 +00:00
|
|
|
(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)
|
2025-12-10 03:10:55 +00:00
|
|
|
@# Notes:
|
|
|
|
|
@# 1. linux-bzimage-setup is excluded from ktest since it's hard to be unit tested;
|
|
|
|
|
@# 2. Artifacts are removed after testing each crate to save the limited disk space
|
|
|
|
|
@# available to free-tier Github runners.
|
2024-02-27 16:44:55 +00:00
|
|
|
@for dir in $(OSDK_CRATES); do \
|
2024-06-19 08:18:39 +00:00
|
|
|
[ $$dir = "ostd/libs/linux-bzimage/setup" ] && continue; \
|
2025-02-20 01:20:14 +00:00
|
|
|
echo "[make] Testing $$dir"; \
|
2025-06-13 12:35:53 +00:00
|
|
|
(cd $$dir && cargo osdk test $(CARGO_OSDK_TEST_ARGS)) || exit 1; \
|
2024-09-30 09:47:07 +00:00
|
|
|
tail --lines 10 qemu.log | grep -q "^\\[ktest runner\\] All crates tested." \
|
|
|
|
|
|| (echo "Test failed" && exit 1); \
|
2025-12-10 03:10:55 +00:00
|
|
|
rm -r target/osdk/*; \
|
2024-02-21 08:58:40 +00:00
|
|
|
done
|
|
|
|
|
|
2024-06-21 08:39:32 +00:00
|
|
|
.PHONY: docs
|
2024-03-06 09:05:54 +00:00
|
|
|
docs: $(CARGO_OSDK)
|
|
|
|
|
@for dir in $(NON_OSDK_CRATES); do \
|
2025-12-26 07:37:59 +00:00
|
|
|
(cd $$dir && RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps) || exit 1; \
|
2024-03-06 09:05:54 +00:00
|
|
|
done
|
|
|
|
|
@for dir in $(OSDK_CRATES); do \
|
2025-12-26 07:37:59 +00:00
|
|
|
EXTRA_DOC_FLAGS=""; \
|
|
|
|
|
# The kernel crate is primarily composed of private items. \
|
|
|
|
|
# We include the --document-private-items flag \
|
|
|
|
|
# to ensure documentation of the internal items is fully checked. \
|
|
|
|
|
if [ "$$dir" = "kernel" ]; then \
|
|
|
|
|
EXTRA_DOC_FLAGS="--document-private-items -Arustdoc::private_intra_doc_links"; \
|
|
|
|
|
fi; \
|
|
|
|
|
(cd $$dir && RUSTDOCFLAGS="-Dwarnings $$EXTRA_DOC_FLAGS" cargo osdk doc --no-deps) || exit 1; \
|
2024-03-06 09:05:54 +00:00
|
|
|
done
|
2025-08-21 10:40:35 +00:00
|
|
|
|
|
|
|
|
.PHONY: book
|
|
|
|
|
book:
|
|
|
|
|
@cd book && mdbook build
|
2022-08-08 22:43:47 +00:00
|
|
|
|
2024-02-23 03:50:27 +00:00
|
|
|
.PHONY: format
|
2024-02-25 14:03:54 +00:00
|
|
|
format:
|
2024-02-27 12:28:43 +00:00
|
|
|
@./tools/format_all.sh
|
2025-11-25 03:37:47 +00:00
|
|
|
@nixfmt ./distro
|
2026-01-12 02:02:10 +00:00
|
|
|
@$(MAKE) --no-print-directory -C test/initramfs format
|
2026-01-13 08:58:30 +00:00
|
|
|
@$(MAKE) --no-print-directory -C test/nixos format
|
2024-02-25 14:03:54 +00:00
|
|
|
|
2024-02-23 03:50:27 +00:00
|
|
|
.PHONY: check
|
2024-08-15 07:17:59 +00:00
|
|
|
check: initramfs $(CARGO_OSDK)
|
2025-04-30 12:54:24 +00:00
|
|
|
@# Check formatting issues of the Rust code
|
|
|
|
|
@./tools/format_all.sh --check
|
|
|
|
|
@
|
|
|
|
|
@# Check if the combination of STD_CRATES and NON_OSDK_CRATES 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 || \
|
2024-06-21 08:17:58 +00:00
|
|
|
(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
|
2025-04-30 12:54:24 +00:00
|
|
|
@
|
|
|
|
|
@# Check if all workspace members enable workspace lints
|
|
|
|
|
@for dir in $(NON_OSDK_CRATES) $(OSDK_CRATES); 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
|
2024-02-27 16:44:55 +00:00
|
|
|
@for dir in $(NON_OSDK_CRATES); do \
|
2024-04-12 17:08:36 +00:00
|
|
|
echo "Checking $$dir"; \
|
2026-01-04 11:13:43 +00:00
|
|
|
# Run clippy on each crate with and without the test configuration. \
|
2026-02-07 15:45:25 +00:00
|
|
|
(cd $$dir && RUSTFLAGS="-Dwarnings" cargo clippy --no-deps) || exit 1; \
|
|
|
|
|
(cd $$dir && RUSTFLAGS="-Dwarnings" cargo clippy --tests --no-deps) || exit 1; \
|
2024-02-27 16:44:55 +00:00
|
|
|
done
|
|
|
|
|
@for dir in $(OSDK_CRATES); do \
|
2024-04-12 17:08:36 +00:00
|
|
|
echo "Checking $$dir"; \
|
2025-08-19 08:56:19 +00:00
|
|
|
# Exclude linux-bzimage-setup since it only supports x86-64 currently and will panic \
|
|
|
|
|
# in other architectures. \
|
|
|
|
|
[ "$$dir" = "ostd/libs/linux-bzimage/setup" ] && [ "$(OSDK_TARGET_ARCH)" != "x86_64" ] && continue; \
|
2025-12-31 08:23:46 +00:00
|
|
|
# Run clippy on each crate with and without the ktest configuration. \
|
2026-02-07 15:45:25 +00:00
|
|
|
(cd $$dir && RUSTFLAGS="-Dwarnings" cargo osdk clippy -- --no-deps) || exit 1; \
|
|
|
|
|
(cd $$dir && RUSTFLAGS="-Dwarnings" cargo osdk clippy --ktests -- --no-deps) || exit 1; \
|
2024-02-27 16:44:55 +00:00
|
|
|
done
|
2025-04-30 12:54:24 +00:00
|
|
|
@
|
2025-12-05 11:47:20 +00:00
|
|
|
@# Check formatting issues of the C code and Nix files (regression tests)
|
2026-01-12 02:02:10 +00:00
|
|
|
@$(MAKE) --no-print-directory -C test/initramfs check
|
2025-04-30 12:54:24 +00:00
|
|
|
@
|
2026-01-13 08:58:30 +00:00
|
|
|
@# Check formatting issues of the Rust code in NixOS tests
|
|
|
|
|
@$(MAKE) --no-print-directory -C test/nixos check
|
|
|
|
|
@
|
2025-04-30 12:54:24 +00:00
|
|
|
@# Check typos
|
2024-08-20 09:45:22 +00:00
|
|
|
@typos
|
2025-12-05 11:47:20 +00:00
|
|
|
@# Check formatting issues of Nix files under distro directory
|
|
|
|
|
@nixfmt --check ./distro
|
2022-08-08 22:43:47 +00:00
|
|
|
|
2024-02-23 03:50:27 +00:00
|
|
|
.PHONY: clean
|
2022-08-08 22:43:47 +00:00
|
|
|
clean:
|
2024-08-25 11:31:32 +00:00
|
|
|
@echo "Cleaning up Asterinas workspace target files"
|
2023-04-10 03:12:42 +00:00
|
|
|
@cargo clean
|
2024-08-25 11:31:32 +00:00
|
|
|
@echo "Cleaning up OSDK workspace target files"
|
|
|
|
|
@cd osdk && cargo clean
|
2025-08-21 10:40:35 +00:00
|
|
|
@echo "Cleaning up mdBook output files"
|
|
|
|
|
@cd book && mdbook clean
|
2024-08-25 11:31:32 +00:00
|
|
|
@echo "Cleaning up test target files"
|
2026-01-12 02:02:10 +00:00
|
|
|
@$(MAKE) --no-print-directory -C test/initramfs clean
|
2024-08-25 11:31:32 +00:00
|
|
|
@echo "Uninstalling OSDK"
|
2024-03-14 09:17:49 +00:00
|
|
|
@rm -f $(CARGO_OSDK)
|