From 7cb6a3d938da9fceb38143abac8b54ce099a09e4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 26 Mar 2023 16:40:04 +0200 Subject: [PATCH 1/4] Check docsrs build on CI --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58816d1b..7f3c9936 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,10 @@ jobs: - uses: r7kamura/rust-problem-matchers@v1.1.0 - name: "Run `cargo check`" run: cargo check --all-targets --all + - name: "Check docs.rs build" + run: cargo check + env: + RUSTFLAGS: "--cfg docsrs_dummy_build" test: name: Test From 27f52cdeb25acd0febb522423fc72af2ae9dec8b Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 26 Mar 2023 16:40:15 +0200 Subject: [PATCH 2/4] Auto-format GitHub actions --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f3c9936..43a57e33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,7 +113,7 @@ jobs: run: cargo semver-checks check-release typos: - name: Check spelling - runs-on: ubuntu-latest - steps: - - uses: crate-ci/typos@v1.0.4 + name: Check spelling + runs-on: ubuntu-latest + steps: + - uses: crate-ci/typos@v1.0.4 From ef05e9c895cc9113400e8a9cf45ad19bbef67025 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 26 Mar 2023 16:48:42 +0200 Subject: [PATCH 3/4] Fix docs.rs build by setting env variables on dummy builds too --- build.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 275fbdea..e5291f57 100644 --- a/build.rs +++ b/build.rs @@ -8,7 +8,6 @@ fn main() { block_on((uefi_main(), bios_main()).join()); } -#[cfg(not(docsrs_dummy_build))] #[cfg(feature = "bios")] async fn bios_main() { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); @@ -17,6 +16,7 @@ async fn bios_main() { // 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.) + #[cfg(not(docsrs_dummy_build))] 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), @@ -25,6 +25,14 @@ async fn bios_main() { ) .join() .await; + // dummy implementations because docsrs builds have no network access + #[cfg(docsrs_dummy_build)] + let (bios_boot_sector_path, bios_stage_2_path, bios_stage_3_path, bios_stage_4_path) = ( + PathBuf::new(), + PathBuf::new(), + PathBuf::new(), + PathBuf::new(), + ); println!( "cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}", bios_boot_sector_path.display() @@ -43,11 +51,16 @@ async fn bios_main() { ); } -#[cfg(not(docsrs_dummy_build))] #[cfg(feature = "uefi")] async fn uefi_main() { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); + + #[cfg(not(docsrs_dummy_build))] let uefi_path = build_uefi_bootloader(&out_dir).await; + // dummy implementation because docsrs builds have no network access + #[cfg(docsrs_dummy_build)] + let uefi_path = PathBuf::new(); + println!( "cargo:rustc-env=UEFI_BOOTLOADER_PATH={}", uefi_path.display() @@ -295,9 +308,3 @@ 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))] -async fn uefi_main() {} From 1f29d220ca61facfcef82ca4c462c4aa0919d72e Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 26 Mar 2023 16:55:01 +0200 Subject: [PATCH 4/4] Re-add dummy functions for building only BIOS or UEFI feature --- build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.rs b/build.rs index e5291f57..d40373d4 100644 --- a/build.rs +++ b/build.rs @@ -5,6 +5,11 @@ use std::path::{Path, PathBuf}; const BOOTLOADER_VERSION: &str = env!("CARGO_PKG_VERSION"); fn main() { + #[cfg(not(feature = "uefi"))] + async fn uefi_main() {} + #[cfg(not(feature = "bios"))] + async fn bios_main() {} + block_on((uefi_main(), bios_main()).join()); }