Skip to content

Fix docs.rs build #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- uses: r7kamura/[email protected]
- 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
Expand Down Expand Up @@ -109,7 +113,7 @@ jobs:
run: cargo semver-checks check-release

typos:
name: Check spelling
runs-on: ubuntu-latest
steps:
- uses: crate-ci/[email protected]
name: Check spelling
runs-on: ubuntu-latest
steps:
- uses: crate-ci/[email protected]
28 changes: 20 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ 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());
}

#[cfg(not(docsrs_dummy_build))]
#[cfg(feature = "bios")]
async fn bios_main() {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
Expand All @@ -17,6 +21,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),
Expand All @@ -25,6 +30,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()
Expand All @@ -43,11 +56,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()
Expand Down Expand Up @@ -295,9 +313,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() {}