diff --git a/Cargo.lock b/Cargo.lock index af2924163..e08d1211b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,6 +147,7 @@ dependencies = [ "serde_json", "snafu", "strum 0.28.0", + "sysinfo", "time", "tokio", "toml", @@ -1129,9 +1130,9 @@ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" [[package]] name = "libc" -version = "0.2.190" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "libgit2-sys" @@ -1247,6 +1248,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" +[[package]] +name = "ntapi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.50.3" @@ -1271,6 +1281,25 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-io-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15" +dependencies = [ + "libc", + "objc2-core-foundation", +] + [[package]] name = "oci-spec" version = "0.10.0" @@ -1637,9 +1666,9 @@ dependencies = [ [[package]] name = "rstest" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "948203e6d13b83e51a90d7cf236dd58a0065f23f4b902f00f306e7eb2bd09b9c" +checksum = "1493d41b35c0ca33433425bd25fc76f9595f2d6031727bc54a86317d73974f05" dependencies = [ "futures-timer", "futures-util", @@ -1648,9 +1677,9 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d92eaf7b6e51e12471d71ddc72608e7151573de44099aacfbb1128177c0da4" +checksum = "05c7b2f315394a42e73034681345115eaa5ee454617c3f7bf802dab2a5c02f6c" dependencies = [ "cfg-if", "glob", @@ -1660,7 +1689,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.119", + "syn 3.0.8", "unicode-ident", ] @@ -2110,6 +2139,20 @@ dependencies = [ "syn 3.0.8", ] +[[package]] +name = "sysinfo" +version = "0.40.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e80749408e2d8bec0ffa303012cf4e1b3b355f4a09087b4fdf7473680f6a2de" +dependencies = [ + "libc", + "memchr", + "ntapi", + "objc2-core-foundation", + "objc2-io-kit", + "windows", +] + [[package]] name = "system-configuration" version = "0.7.0" @@ -2660,6 +2703,22 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + [[package]] name = "winapi-util" version = "0.1.11" @@ -2669,12 +2728,95 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + [[package]] name = "windows-registry" version = "0.6.1" @@ -2773,6 +2915,15 @@ dependencies = [ "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index aac8def66..5e6fd70a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,15 +20,16 @@ humansize = "2.1" oci-spec = "0.10" purl = { version = "0.1.6", default-features = false } reqwest = { version = "0.13", features = ["json"] } -rstest = "0.27" -secrecy = "0.10" regex = "1.13" +rstest = "0.29" +secrecy = "0.10" semver = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" snafu = "0.9" spdx = "0.13" strum = { version = "0.28", features = ["derive"] } +sysinfo = { version = "0.40", default-features = false } tempfile = "3.27" time = { version = "0.3", features = ["parsing", "formatting"] } tokio = { version = "1.53", features = ["rt", "macros", "process"] } diff --git a/rust/boil/Cargo.toml b/rust/boil/Cargo.toml index a47b82123..2a06e8d67 100644 --- a/rust/boil/Cargo.toml +++ b/rust/boil/Cargo.toml @@ -26,6 +26,7 @@ serde.workspace = true serde_json.workspace = true snafu.workspace = true strum.workspace = true +sysinfo = { workspace = true, features = ["system"] } time.workspace = true tokio.workspace = true toml.workspace = true diff --git a/rust/boil/src/cli/build.rs b/rust/boil/src/cli/build.rs index f05d2e6fb..003f71587 100644 --- a/rust/boil/src/cli/build.rs +++ b/rust/boil/src/cli/build.rs @@ -7,6 +7,7 @@ use std::{ use clap::{Args, ValueHint, value_parser}; use snafu::{ResultExt, Snafu, ensure}; use strum::EnumDiscriminants; +use sysinfo::System; use url::Host; use crate::{ @@ -37,6 +38,8 @@ pub struct BuildArguments { pub vendor_version: String, /// Target platform of the image. + /// + /// Defaults to the system's architecture or linux/amd64 if unknown/not supported. #[arg( short, long, short_alias = 'a', alias = "architecture", @@ -144,9 +147,13 @@ pub struct BuildArguments { } impl BuildArguments { - // TODO: Auto-detect this fn default_architecture() -> TargetPlatform { - TargetPlatform::Linux(Architecture::Amd64) + // NOTE (@Techassi): This is sadly not an enum we could match on, so we kind of have to + // treat this like free-form text. As such, we match on both aarch64 and arm64. + match System::cpu_arch().as_str() { + "aarch64" | "arm64" => TargetPlatform::Linux(Architecture::Arm64), + _ => TargetPlatform::Linux(Architecture::Amd64), + } } fn default_target_containerfile() -> PathBuf {