twizzler-operating-system / twizzler

The Twizzler Operating System
BSD 3-Clause "New" or "Revised" License
62 stars 13 forks source link

Add support for dev-dependencies for the kernel build process #191

Open zphrs opened 1 week ago

zphrs commented 1 week ago

Currently when running kernel tests using cargo build-all --tests dev dependencies are not included into the build. Dev dependencies are useful for separating out dependencies which are exclusively used for testing so that they are not included in non-test builds.

Current Behavior

Dev dependencies are not included in the test build generated from running cargo build-all --tests.

Expected Behavior

Dev dependencies should be included in the test build generated from cargo build-all --tests.

Example Cargo.toml & test module from src/kernel/src/crypto.rs

[dev-dependencies]
hex-literal = { version = "0.4.1", default-features = false }
mod test {

    use hex_literal::hex;
    use twizzler_kernel_macros::kernel_test;

    use super::*;

    #[kernel_test]
    fn test_hashing() {
        let expected = hex!("09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b");
        let hash = sha256(b"hello, world");
        assert_eq!(hash[..], expected);
    }
}

Currently the line [dev-dependencies] is commented out within the kernel's Cargo.toml file. Ideally hex-literal would be a dev dependency as it is only used in the test_hashing test harness to provide the hex! macro. To test that this issue is resolved, uncommenting the [dev-dependencies] line which is right above hex-literal shouldn't break either the test compilation (cargo build-all --tests) of a normal cargo build-all. Note that currently all builds of the kernel with the dev-dependency line uncommented returns a build error if hex-literal is a dev dependency:

error[E0432]: unresolved import `hex_literal`
  --> src/kernel/src/crypto.rs:35:9
   |
35 |     use hex_literal::hex;
   |         ^^^^^^^^^^^ use of undeclared crate or module `hex_literal`