From 5bfac796b3d4586e9ae383e21f8820d8affc2c1d Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Tue, 7 Jul 2020 11:06:40 +0000 Subject: [PATCH] build: add a default feature KVM It gets bubbled all the way up from hypervsior crate to top-level Cargo.toml. Cloud Hypervisor can't function without KVM at this point, so make it a default feature. Fix all scripts that use --no-default-features. Signed-off-by: Wei Liu --- .github/workflows/cross-build.yaml | 2 +- Cargo.toml | 3 ++- hypervisor/Cargo.toml | 2 ++ scripts/dev_cli.sh | 2 +- scripts/run_cargo_tests.sh | 18 +++++++++--------- scripts/run_integration_tests_aarch64.sh | 8 ++++---- scripts/run_integration_tests_x86_64.sh | 2 +- scripts/run_unit_tests.sh | 2 +- vmm/Cargo.toml | 1 + 9 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cross-build.yaml b/.github/workflows/cross-build.yaml index 38004b87e..a7fec037e 100644 --- a/.github/workflows/cross-build.yaml +++ b/.github/workflows/cross-build.yaml @@ -31,4 +31,4 @@ jobs: with: use-cross: true command: build - args: --target=${{ matrix.target }} --no-default-features --features "mmio" + args: --target=${{ matrix.target }} --no-default-features --features "mmio,kvm" diff --git a/Cargo.toml b/Cargo.toml index fb32bc222..7c2a05911 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,12 +35,13 @@ serde_json = "1.0.56" net_util = { path = "net_util" } [features] -default = ["acpi", "pci", "cmos"] +default = ["acpi", "pci", "cmos", "kvm"] acpi = ["vmm/acpi"] pci = ["vmm/pci_support"] mmio = ["vmm/mmio_support"] cmos = ["vmm/cmos"] fwdebug = ["vmm/fwdebug"] +kvm = ["vmm/kvm"] # Integration tests require a special environment to run in integration_tests = [] diff --git a/hypervisor/Cargo.toml b/hypervisor/Cargo.toml index 1a51105c7..5c3347c79 100644 --- a/hypervisor/Cargo.toml +++ b/hypervisor/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors = ["Muminul Islam "] edition = "2018" +[features] +kvm = [] [dependencies] anyhow = "1.0" diff --git a/scripts/dev_cli.sh b/scripts/dev_cli.sh index 97081accb..b6f7dda32 100755 --- a/scripts/dev_cli.sh +++ b/scripts/dev_cli.sh @@ -204,7 +204,7 @@ cmd_build() { [ $build = "release" ] && cargo_args+=("--release") cargo_args+=(--target "$target") [ $(uname -m) = "aarch64" ] && cargo_args+=("--no-default-features") - [ $(uname -m) = "aarch64" ] && cargo_args+=(--features "mmio") + [ $(uname -m) = "aarch64" ] && cargo_args+=(--features "mmio,kvm") rustflags="" if [ $(uname -m) = "aarch64" ] && [ $libc = "musl" ] ; then diff --git a/scripts/run_cargo_tests.sh b/scripts/run_cargo_tests.sh index 5b9b51b10..e9edfd306 100755 --- a/scripts/run_cargo_tests.sh +++ b/scripts/run_cargo_tests.sh @@ -15,14 +15,14 @@ time cargo rustc --bin cloud-hypervisor -- -D warnings time cargo rustc -p vhost_user_net --bin vhost_user_net -- -D warnings time cargo test time cargo audit -time cargo clippy --all-targets --no-default-features --features "pci,acpi" -- -D warnings -time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci,acpi" -- -D warnings -time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "pci,acpi" -- -D warnings -time cargo clippy --all-targets --no-default-features --features "pci" -- -D warnings -time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci" -- -D warnings -time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "pci" -- -D warnings -time cargo clippy --all-targets --no-default-features --features "mmio" -- -D warnings -time cargo rustc --bin cloud-hypervisor --no-default-features --features "mmio" -- -D warnings -time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "mmio" -- -D warnings +time cargo clippy --all-targets --no-default-features --features "pci,acpi,kvm" -- -D warnings +time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci,acpi,kvm" -- -D warnings +time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "pci,acpi,kvm" -- -D warnings +time cargo clippy --all-targets --no-default-features --features "pci,kvm" -- -D warnings +time cargo rustc --bin cloud-hypervisor --no-default-features --features "pci,kvm" -- -D warnings +time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "pci,kvm" -- -D warnings +time cargo clippy --all-targets --no-default-features --features "mmio,kvm" -- -D warnings +time cargo rustc --bin cloud-hypervisor --no-default-features --features "mmio,kvm" -- -D warnings +time cargo rustc -p vhost_user_net --bin vhost_user_net --no-default-features --features "mmio,kvm" -- -D warnings time cargo fmt -- --check time cargo build --all --release diff --git a/scripts/run_integration_tests_aarch64.sh b/scripts/run_integration_tests_aarch64.sh index 3b701f494..0e2a3367c 100755 --- a/scripts/run_integration_tests_aarch64.sh +++ b/scripts/run_integration_tests_aarch64.sh @@ -178,7 +178,7 @@ sed -i 's/"with-serde",\ //g' hypervisor/Cargo.toml cargo_args=("$@") cargo_args+=("--no-default-features") -cargo_args+=("--features mmio") +cargo_args+=("--features mmio,kvm") cargo build --release --target $BUILD_TARGET ${cargo_args[@]} strip target/$BUILD_TARGET/release/cloud-hypervisor strip target/$BUILD_TARGET/release/vhost_user_net @@ -204,7 +204,7 @@ RES=$? if [ $RES -eq 0 ]; then # virtio-mmio based testing - cargo build --release --target $BUILD_TARGET --no-default-features --features "mmio" + cargo build --release --target $BUILD_TARGET --no-default-features --features "mmio,kvm" strip target/$BUILD_TARGET/release/cloud-hypervisor strip target/$BUILD_TARGET/release/vhost_user_net strip target/$BUILD_TARGET/release/ch-remote @@ -212,12 +212,12 @@ if [ $RES -eq 0 ]; then sudo setcap cap_net_admin+ep target/$BUILD_TARGET/release/cloud-hypervisor # Ensure test binary has the same caps as the cloud-hypervisor one - time cargo test --no-run --no-default-features --features "integration_tests,mmio" -- --nocapture || exit 1 + time cargo test --no-run --no-default-features --features "integration_tests,mmio,kvm" -- --nocapture || exit 1 ls target/debug/deps/cloud_hypervisor-* | xargs -n 1 sudo setcap cap_net_admin+ep newgrp kvm << EOF export RUST_BACKTRACE=1 -time cargo test --no-default-features --features "integration_tests,mmio" "tests::parallel::test_aarch64_pe_boot" -- --nocapture +time cargo test --no-default-features --features "integration_tests,mmio,kvm" "tests::parallel::test_aarch64_pe_boot" -- --nocapture EOF RES=$? diff --git a/scripts/run_integration_tests_x86_64.sh b/scripts/run_integration_tests_x86_64.sh index f7202c593..17ab017cb 100755 --- a/scripts/run_integration_tests_x86_64.sh +++ b/scripts/run_integration_tests_x86_64.sh @@ -249,7 +249,7 @@ fi if [ $RES -eq 0 ]; then # virtio-mmio based testing - cargo build --all --release --target $BUILD_TARGET --no-default-features --features "mmio" + cargo build --all --release --target $BUILD_TARGET --no-default-features --features "mmio,kvm" strip target/$BUILD_TARGET/release/cloud-hypervisor strip target/$BUILD_TARGET/release/vhost_user_net strip target/$BUILD_TARGET/release/ch-remote diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh index af8d5c35e..80260c773 100755 --- a/scripts/run_unit_tests.sh +++ b/scripts/run_unit_tests.sh @@ -5,7 +5,7 @@ source $HOME/.cargo/env BUILD_TARGET=${BUILD_TARGET-x86_64-unknown-linux-gnu} cargo_args=("$@") [ $(uname -m) = "aarch64" ] && cargo_args+=("--no-default-features") -[ $(uname -m) = "aarch64" ] && cargo_args+=("--features mmio") +[ $(uname -m) = "aarch64" ] && cargo_args+=("--features mmio,kvm") [ $(uname -m) = "aarch64" ] && sed -i 's/"with-serde",\ //g' hypervisor/Cargo.toml cargo test --target $BUILD_TARGET --workspace --no-run ${cargo_args[@]} diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index f656b473d..783b8ad8d 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -11,6 +11,7 @@ pci_support = ["pci", "vfio-ioctls", "virtio-devices/pci_support"] mmio_support = ["virtio-devices/mmio_support"] cmos = ["devices/cmos"] fwdebug = ["devices/fwdebug"] +kvm = ["hypervisor/kvm"] [dependencies] arc-swap = ">=0.4.4"