From c5ed8690d3f00e619c4423b52ec24ce8b48340af Mon Sep 17 00:00:00 2001 From: Jason Couture Date: Mon, 9 Jan 2023 16:52:38 -0500 Subject: [PATCH 1/4] Use async/await to speed up builds of bios by building all 4 stages concurrently --- Cargo.lock | 405 ++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 + build.rs | 138 +++++++++--------- 3 files changed, 472 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 415b0b55..6fbaa43d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,77 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "async-channel" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-io" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +dependencies = [ + "async-lock", + "autocfg", + "concurrent-queue", + "futures-lite", + "libc", + "log", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "windows-sys", +] + +[[package]] +name = "async-lock" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" +dependencies = [ + "event-listener", + "futures-lite", +] + +[[package]] +name = "async-process" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "libc", + "signal-hook", + "windows-sys", +] + +[[package]] +name = "async-task" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "autocfg" version = "1.1.0" @@ -53,13 +124,30 @@ dependencies = [ "wyz", ] +[[package]] +name = "blocking" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", +] + [[package]] name = "bootloader" version = "0.11.0" dependencies = [ "anyhow", + "async-process", "bootloader_test_runner", "fatfs", + "futures", + "futures-concurrency", "gpt", "llvm-tools", "mbrman", @@ -166,6 +254,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" + [[package]] name = "cfg-if" version = "1.0.0" @@ -185,6 +279,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "concurrent-queue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "conquer-once" version = "0.3.2" @@ -209,6 +312,21 @@ dependencies = [ "build_const", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "1.8.0" @@ -236,6 +354,121 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-concurrency" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a740c32e1bde284ce2f51df98abd4fa38e9e539670443c111211777e3ab09927" +dependencies = [ + "bitvec", + "futures-core", + "pin-project", +] + +[[package]] +name = "futures-core" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" + +[[package]] +name = "futures-executor" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + +[[package]] +name = "futures-task" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" + +[[package]] +name = "futures-util" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "getrandom" version = "0.2.6" @@ -270,9 +503,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.122" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "llvm-tools" @@ -321,6 +554,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "noto-sans-mono-bitmap" version = "0.1.6" @@ -358,6 +597,58 @@ version = "0.1.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa50141d081512ab30fd9e7e7692476866df5098b028536ad6680212e717fa8d" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "polling" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" +dependencies = [ + "autocfg", + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "windows-sys", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -504,6 +795,44 @@ dependencies = [ "syn", ] +[[package]] +name = "signal-hook" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spinning_top" version = "0.2.4" @@ -734,12 +1063,27 @@ dependencies = [ "quote", ] +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -762,6 +1106,63 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 335407b2..d2c0122c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,6 +112,9 @@ rustflags = [ [build-dependencies] llvm-tools = "0.1.1" +async-process = "1.6.0" +futures = "0.3.25" +futures-concurrency = "7.0.0" [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs_dummy_build"] diff --git a/build.rs b/build.rs index bb24ce6b..eaf90351 100644 --- a/build.rs +++ b/build.rs @@ -1,52 +1,58 @@ -use std::{ - path::{Path, PathBuf}, - process::Command, -}; - +use async_process::Command; +use futures::executor::block_on; +use futures_concurrency::future::Join; +use std::path::{Path, PathBuf}; const BOOTLOADER_VERSION: &str = env!("CARGO_PKG_VERSION"); fn main() { - let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - - #[cfg(feature = "uefi")] - { - let uefi_path = build_uefi_bootloader(&out_dir); - println!( - "cargo:rustc-env=UEFI_BOOTLOADER_PATH={}", - uefi_path.display() - ); - } - - #[cfg(feature = "bios")] - { - let bios_boot_sector_path = build_bios_boot_sector(&out_dir); - println!( - "cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}", - bios_boot_sector_path.display() - ); - let bios_stage_2_path = build_bios_stage_2(&out_dir); - println!( - "cargo:rustc-env=BIOS_STAGE_2_PATH={}", - bios_stage_2_path.display() - ); + block_on((uefi_main(), bios_main()).join()); +} - let bios_stage_3_path = build_bios_stage_3(&out_dir); - println!( - "cargo:rustc-env=BIOS_STAGE_3_PATH={}", - bios_stage_3_path.display() - ); +#[cfg(not(docsrs_dummy_build))] +#[cfg(feature = "bios")] +async fn bios_main() { + let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); + // Run the bios parts concurrently. (Build time / 4 :D ) + let (bios_boot_sector_path, bios_stage_2_path, bios_stage_3_path, bios_stage_4_path) = ( + build_bios_boot_sector(&out_dir), + build_bios_stage_2(&out_dir), + build_bios_stage_3(&out_dir), + build_bios_stage_4(&out_dir), + ) + .join() + .await; + println!( + "cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}", + bios_boot_sector_path.display() + ); + println!( + "cargo:rustc-env=BIOS_STAGE_2_PATH={}", + bios_stage_2_path.display() + ); + println!( + "cargo:rustc-env=BIOS_STAGE_3_PATH={}", + bios_stage_3_path.display() + ); + println!( + "cargo:rustc-env=BIOS_STAGE_4_PATH={}", + bios_stage_4_path.display() + ); +} - let bios_stage_4_path = build_bios_stage_4(&out_dir); - println!( - "cargo:rustc-env=BIOS_STAGE_4_PATH={}", - bios_stage_4_path.display() - ); - } +#[cfg(not(docsrs_dummy_build))] +#[cfg(feature = "uefi")] +async fn uefi_main() { + let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); + let uefi_path = build_uefi_bootloader(&out_dir).await; + println!( + "cargo:rustc-env=UEFI_BOOTLOADER_PATH={}", + uefi_path.display() + ); } #[cfg(not(docsrs_dummy_build))] #[cfg(feature = "uefi")] -fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { +async fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); cmd.arg("install").arg("bootloader-x86_64-uefi"); @@ -67,6 +73,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { cmd.env_remove("CARGO_ENCODED_RUSTFLAGS"); let status = cmd .status() + .await .expect("failed to run cargo install for uefi bootloader"); if status.success() { let path = out_dir.join("bin").join("bootloader-x86_64-uefi.efi"); @@ -82,7 +89,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf { #[cfg(not(docsrs_dummy_build))] #[cfg(feature = "bios")] -fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { +async fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); cmd.arg("install").arg("bootloader-x86_64-bios-boot-sector"); @@ -107,7 +114,8 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { cmd.env_remove("RUSTC_WORKSPACE_WRAPPER"); // used by clippy let status = cmd .status() - .expect("failed to run cargo install for bios boot sector"); + .await + .expect("failed to run cargo install for bios bootsector"); let elf_path = if status.success() { let path = out_dir .join("bin") @@ -120,12 +128,12 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf { } else { panic!("failed to build bios boot sector"); }; - convert_elf_to_bin(elf_path) + convert_elf_to_bin(elf_path).await } #[cfg(not(docsrs_dummy_build))] #[cfg(feature = "bios")] -fn build_bios_stage_2(out_dir: &Path) -> PathBuf { +async fn build_bios_stage_2(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); cmd.arg("install").arg("bootloader-x86_64-bios-stage-2"); @@ -154,6 +162,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf { cmd.env_remove("RUSTC_WORKSPACE_WRAPPER"); // used by clippy let status = cmd .status() + .await .expect("failed to run cargo install for bios second stage"); let elf_path = if status.success() { let path = out_dir.join("bin").join("bootloader-x86_64-bios-stage-2"); @@ -165,12 +174,12 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf { } else { panic!("failed to build bios second stage"); }; - convert_elf_to_bin(elf_path) + convert_elf_to_bin(elf_path).await } #[cfg(not(docsrs_dummy_build))] #[cfg(feature = "bios")] -fn build_bios_stage_3(out_dir: &Path) -> PathBuf { +async fn build_bios_stage_3(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); cmd.arg("install").arg("bootloader-x86_64-bios-stage-3"); @@ -195,6 +204,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf { cmd.env_remove("RUSTC_WORKSPACE_WRAPPER"); // used by clippy let status = cmd .status() + .await .expect("failed to run cargo install for bios stage-3"); let elf_path = if status.success() { let path = out_dir.join("bin").join("bootloader-x86_64-bios-stage-3"); @@ -206,12 +216,12 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf { } else { panic!("failed to build bios stage-3"); }; - convert_elf_to_bin(elf_path) + convert_elf_to_bin(elf_path).await } #[cfg(not(docsrs_dummy_build))] #[cfg(feature = "bios")] -fn build_bios_stage_4(out_dir: &Path) -> PathBuf { +async fn build_bios_stage_4(out_dir: &Path) -> PathBuf { let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()); let mut cmd = Command::new(cargo); cmd.arg("install").arg("bootloader-x86_64-bios-stage-4"); @@ -236,6 +246,7 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf { cmd.env_remove("RUSTC_WORKSPACE_WRAPPER"); // used by clippy let status = cmd .status() + .await .expect("failed to run cargo install for bios stage-4"); let elf_path = if status.success() { let path = out_dir.join("bin").join("bootloader-x86_64-bios-stage-4"); @@ -248,11 +259,11 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf { panic!("failed to build bios stage-4"); }; - convert_elf_to_bin(elf_path) + convert_elf_to_bin(elf_path).await } #[cfg(feature = "bios")] -fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { +async fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { let flat_binary_path = elf_path.with_extension("bin"); let llvm_tools = llvm_tools::LlvmTools::new().expect("failed to get llvm tools"); @@ -269,6 +280,7 @@ fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { cmd.arg(&flat_binary_path); let output = cmd .output() + .await .expect("failed to execute llvm-objcopy command"); if !output.status.success() { panic!( @@ -279,25 +291,7 @@ fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { flat_binary_path } -// dummy implementations because docsrs builds have no network access - -#[cfg(docsrs_dummy_build)] -fn build_uefi_bootloader(_out_dir: &Path) -> PathBuf { - PathBuf::new() -} -#[cfg(docsrs_dummy_build)] -fn build_bios_boot_sector(_out_dir: &Path) -> PathBuf { - PathBuf::new() -} -#[cfg(docsrs_dummy_build)] -fn build_bios_stage_2(_out_dir: &Path) -> PathBuf { - PathBuf::new() -} -#[cfg(docsrs_dummy_build)] -fn build_bios_stage_3(_out_dir: &Path) -> PathBuf { - PathBuf::new() -} -#[cfg(docsrs_dummy_build)] -fn build_bios_stage_4(_out_dir: &Path) -> PathBuf { - PathBuf::new() -} +#[cfg(any(not(feature = "bios"), docsrs_dummy_build))] +async fn bios_main() {} +#[cfg(any(not(feature = "uefi"), docsrs_dummy_build))] +async fn uefi_main() {} From b51355085042844a5b6981d54dcc25b0d7d515d4 Mon Sep 17 00:00:00 2001 From: Jason Couture Date: Tue, 10 Jan 2023 21:02:52 -0500 Subject: [PATCH 2/4] Remove spammy debug message --- common/src/load_kernel.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/load_kernel.rs b/common/src/load_kernel.rs index 442a4e73..685bad0f 100644 --- a/common/src/load_kernel.rs +++ b/common/src/load_kernel.rs @@ -309,7 +309,6 @@ where for page in start_page..=end_inclusive_page { // Translate the virtual page to the physical frame. - debug!("{page:?}"); let phys_addr = self .page_table .translate_page(page) From 970b701b046e03e1243f49ad51b0439af63e1b7f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 11 Jan 2023 11:57:09 +0100 Subject: [PATCH 3/4] Add comment about docs.rs dummy functions again --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index eaf90351..d949d816 100644 --- a/build.rs +++ b/build.rs @@ -291,6 +291,7 @@ async fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf { flat_binary_path } +// dummy implementations because docsrs builds have no network access #[cfg(any(not(feature = "bios"), docsrs_dummy_build))] async fn bios_main() {} #[cfg(any(not(feature = "uefi"), docsrs_dummy_build))] From 0ed7a10a7286d3d3a6934e26e6b5920ea440e3f8 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 11 Jan 2023 12:04:05 +0100 Subject: [PATCH 4/4] Clarify why the concurrent build commands speed things up --- build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index d949d816..b5652bc6 100644 --- a/build.rs +++ b/build.rs @@ -12,7 +12,11 @@ fn main() { #[cfg(feature = "bios")] async fn bios_main() { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - // Run the bios parts concurrently. (Build time / 4 :D ) + // Run the bios build commands concurrently. + // (Cargo already uses multiple threads for building dependencies, but these + // BIOS crates don't have enough dependencies to utilize all cores on modern + // CPUs. So by running the build commands in parallel, we increase the number + // of utilized cores.) let (bios_boot_sector_path, bios_stage_2_path, bios_stage_3_path, bios_stage_4_path) = ( build_bios_boot_sector(&out_dir), build_bios_stage_2(&out_dir),