Enable arch-aware make check

This commit is contained in:
Chen Chengjun 2025-08-19 08:56:19 +00:00 committed by Tate, Hongliang Tian
parent 1452aab69c
commit bf5360d721
5 changed files with 31 additions and 14 deletions

View File

@ -70,7 +70,7 @@ runs:
[[ "${{ matrix.id }}" == "compile" ]] && CMD+="make build FEATURES=all"
[[ "${{ matrix.id }}" == "usermode_test" ]] && CMD+="make test"
[[ "${{ matrix.id }}" == "ktest" ]] && CMD+="make ktest NETDEV=tap"
[[ -n "${{ inputs.arch }}" ]] && CMD+=" ARCH=${{ inputs.arch }}"
[[ -n "${{ inputs.arch }}" ]] && CMD+=" OSDK_TARGET_ARCH=${{ inputs.arch }}"
echo "Executing: $CMD"
eval $CMD
@ -86,7 +86,7 @@ runs:
[[ -n "${{ inputs.smp }}" ]] && CMD+=" SMP=${{ inputs.smp }}"
[[ -n "${{ inputs.netdev }}" ]] && CMD+=" NETDEV=${{ inputs.netdev }}"
[[ -n "${{ inputs.scheme }}" ]] && CMD+=" SCHEME=${{ inputs.scheme }}"
[[ -n "${{ inputs.arch }}" ]] && CMD+=" ARCH=${{ inputs.arch }}"
[[ -n "${{ inputs.arch }}" ]] && CMD+=" OSDK_TARGET_ARCH=${{ inputs.arch }}"
[[ -n "${{ inputs.extra_blocklists }}" ]] && CMD+=" EXTRA_BLOCKLISTS_DIRS=${{ inputs.extra_blocklists }}"
[[ -n "${{ inputs.syscall_test_suite }}" ]] && CMD+=" SYSCALL_TEST_SUITE=${{ inputs.syscall_test_suite }}"
[[ -n "${{ inputs.syscall_test_workdir }}" ]] && CMD+=" SYSCALL_TEST_WORKDIR=${{ inputs.syscall_test_workdir }}"

View File

@ -3,7 +3,7 @@
# =========================== Makefile options. ===============================
# Global build options.
ARCH ?= x86_64
OSDK_TARGET_ARCH ?= x86_64
BENCHMARK ?= none
BOOT_METHOD ?= grub-rescue-iso
BOOT_PROTOCOL ?= multiboot2
@ -52,7 +52,7 @@ 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=$(ARCH)
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_TEST_ARGS :=
@ -105,9 +105,9 @@ BOOT_METHOD = qemu-direct
OVMF = off
endif
ifeq ($(ARCH), riscv64)
ifeq ($(OSDK_TARGET_ARCH), riscv64)
SCHEME = riscv
else ifeq ($(ARCH), loongarch64)
else ifeq ($(OSDK_TARGET_ARCH), loongarch64)
SCHEME = loongarch
endif
@ -141,7 +141,7 @@ CARGO_OSDK_COMMON_ARGS += --grub-boot-protocol=$(BOOT_PROTOCOL)
endif
ifeq ($(ENABLE_KVM), 1)
ifeq ($(ARCH), x86_64)
ifeq ($(OSDK_TARGET_ARCH), x86_64)
CARGO_OSDK_COMMON_ARGS += --qemu-args="-accel kvm"
endif
endif
@ -314,7 +314,6 @@ format:
@$(MAKE) --no-print-directory -C test format
.PHONY: check
# FIXME: Make `make check` arch-aware.
check: initramfs $(CARGO_OSDK)
@# Check formatting issues of the Rust code
@./tools/format_all.sh --check
@ -345,6 +344,9 @@ check: initramfs $(CARGO_OSDK)
done
@for dir in $(OSDK_CRATES); do \
echo "Checking $$dir"; \
# 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; \
(cd $$dir && cargo osdk clippy -- -- -D warnings) || exit 1; \
done
@

View File

@ -79,7 +79,22 @@ impl Display for Arch {
}
/// Get the default architecture implied by the host rustc's default architecture.
///
/// If the environment variable `OSDK_TARGET_ARCH` is set, use it to determine the default
/// architecture directly.
pub fn get_default_arch() -> Arch {
if let Ok(arch) = std::env::var("OSDK_TARGET_ARCH") {
return match arch.as_str() {
"aarch64" => Arch::Aarch64,
"riscv64" => Arch::RiscV64,
"x86_64" => Arch::X86_64,
"loongarch64" => Arch::LoongArch64,
_ => panic!(
"The environment variable `OSDK_TARGET_ARCH` specifies an unsupported native architecture"
),
};
};
let output = crate::util::new_command_checked_exists("rustc")
.arg("-vV")
.output()

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: MPL-2.0
ARCH ?= x86_64
OSDK_TARGET_ARCH ?= x86_64
SMP ?= 1
VERBOSE ?= 1
SYSCALL_TEST_SUITE ?= ltp
@ -47,7 +47,7 @@ endif
all: build
.PHONY: build
ifeq ($(ARCH), loongarch64)
ifeq ($(OSDK_TARGET_ARCH), loongarch64)
build: $(EXT2_IMAGE) $(EXFAT_IMAGE)
@echo "For loongarch, we generate a fake initramfs to successfully test or build."
@touch $(INITRAMFS_IMAGE)
@ -59,7 +59,7 @@ endif
$(INITRAMFS_IMAGE): $(INITRAMFS)
@nix-build \
--tarball-ttl $(NIXPKGS_CACHE_TTL) \
--argstr target $(ARCH) \
--argstr target $(OSDK_TARGET_ARCH) \
--arg enableBasicTest $(ENABLE_BASIC_TEST) \
--arg enableBenchmark $(ENABLE_BENCHMARK) \
--arg enableSyscallTest $(ENABLE_SYSCALL_TEST) \
@ -74,7 +74,7 @@ $(INITRAMFS_IMAGE): $(INITRAMFS)
$(INITRAMFS):
@nix-build \
--tarball-ttl $(NIXPKGS_CACHE_TTL) \
--argstr target $(ARCH) \
--argstr target $(OSDK_TARGET_ARCH) \
--arg enableBasicTest $(ENABLE_BASIC_TEST) \
--arg enableBenchmark $(ENABLE_BENCHMARK) \
--arg enableSyscallTest $(ENABLE_SYSCALL_TEST) \

View File

@ -38,9 +38,9 @@ While most tests rely on `Nix` for compilation, the `gvisor` syscall test suite
The test suite supports building for multiple architectures, including `x86_64` and `riscv64`. You can specify the desired architecture by running:
```bash
make build ARCH=x86_64
make build OSDK_TARGET_ARCH=x86_64
# or
make build ARCH=riscv64
make build OSDK_TARGET_ARCH=riscv64
```
The build artifacts (initramfs) can be found in the `test/build` directory after the compilation.