Skip to content

Commit

Permalink
build: Allow building without mstpm
Browse files Browse the repository at this point in the history
Remove the default dependency from "kernel" on mstpm so it can be
compiled without it. Change the Makefile to specify mstpm as feature by
default. This allows running FEATURES='""' make to not build the mstpm.

To run unit tests without testing mstpm, use:

FEATURES_TEST='""' SVSM_ARGS_TEST='--exclude libmstpm' make test

Signed-off-by: Adam Dunlap <[email protected]>
  • Loading branch information
AdamCDunlap committed Aug 14, 2024
1 parent 6103334 commit f6da12e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FEATURES ?= "default"
SVSM_ARGS = --features ${FEATURES}
FEATURES ?= mstpm
SVSM_ARGS += --features ${FEATURES}

SVSM_ARGS_TEST = --no-default-features
ifdef FEATURES_TEST
SVSM_ARGS_TEST += --features ${FEATURES_TEST}
endif
FEATURES_TEST ?= mstpm
SVSM_ARGS_TEST += --no-default-features --features ${FEATURES_TEST}

ifdef RELEASE
TARGET_PATH=release
Expand Down Expand Up @@ -112,15 +110,15 @@ bin/meta.bin: utils/gen_meta utils/print-meta bin
./utils/gen_meta $@

bin/stage2.bin: bin
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} --no-default-features --bin stage2
cargo build --manifest-path kernel/Cargo.toml ${CARGO_ARGS} --bin stage2
objcopy -O binary ${STAGE2_ELF} $@

bin/svsm-kernel.elf: bin
cargo build ${CARGO_ARGS} ${SVSM_ARGS} --bin svsm
objcopy -O elf64-x86-64 --strip-unneeded ${SVSM_KERNEL_ELF} $@

bin/test-kernel.elf: bin
LINK_TEST=1 cargo +nightly test ${CARGO_ARGS} -p svsm --config 'target.x86_64-unknown-none.runner=["sh", "-c", "cp $$0 ../${TEST_KERNEL_ELF}"]'
LINK_TEST=1 cargo +nightly test ${CARGO_ARGS} ${SVSM_ARGS_TEST} -p svsm --config 'target.x86_64-unknown-none.runner=["sh", "-c", "cp $$0 ../${TEST_KERNEL_ELF}"]'
objcopy -O elf64-x86-64 --strip-unneeded ${TEST_KERNEL_ELF} bin/test-kernel.elf

${FS_BIN}: bin
Expand Down
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ libmstpm = { workspace = true, optional = true }
test.workspace = true

[features]
default = ["mstpm"]
default = []
enable-gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
mstpm = ["dep:libmstpm"]

Expand Down

0 comments on commit f6da12e

Please sign in to comment.