Skip to content

Commit 3bee44a

Browse files
authored
Merge pull request #358 from rust-osdev/fix-docsrs
Fix docs.rs build
2 parents fa87d01 + 1f29d22 commit 3bee44a

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

.github/workflows/ci.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
- uses: r7kamura/[email protected]
2626
- name: "Run `cargo check`"
2727
run: cargo check --all-targets --all
28+
- name: "Check docs.rs build"
29+
run: cargo check
30+
env:
31+
RUSTFLAGS: "--cfg docsrs_dummy_build"
2832

2933
test:
3034
name: Test
@@ -109,7 +113,7 @@ jobs:
109113
run: cargo semver-checks check-release
110114

111115
typos:
112-
name: Check spelling
113-
runs-on: ubuntu-latest
114-
steps:
115-
- uses: crate-ci/[email protected]
116+
name: Check spelling
117+
runs-on: ubuntu-latest
118+
steps:
119+
- uses: crate-ci/[email protected]

build.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ use std::path::{Path, PathBuf};
55
const BOOTLOADER_VERSION: &str = env!("CARGO_PKG_VERSION");
66

77
fn main() {
8+
#[cfg(not(feature = "uefi"))]
9+
async fn uefi_main() {}
10+
#[cfg(not(feature = "bios"))]
11+
async fn bios_main() {}
12+
813
block_on((uefi_main(), bios_main()).join());
914
}
1015

11-
#[cfg(not(docsrs_dummy_build))]
1216
#[cfg(feature = "bios")]
1317
async fn bios_main() {
1418
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
@@ -17,6 +21,7 @@ async fn bios_main() {
1721
// BIOS crates don't have enough dependencies to utilize all cores on modern
1822
// CPUs. So by running the build commands in parallel, we increase the number
1923
// of utilized cores.)
24+
#[cfg(not(docsrs_dummy_build))]
2025
let (bios_boot_sector_path, bios_stage_2_path, bios_stage_3_path, bios_stage_4_path) = (
2126
build_bios_boot_sector(&out_dir),
2227
build_bios_stage_2(&out_dir),
@@ -25,6 +30,14 @@ async fn bios_main() {
2530
)
2631
.join()
2732
.await;
33+
// dummy implementations because docsrs builds have no network access
34+
#[cfg(docsrs_dummy_build)]
35+
let (bios_boot_sector_path, bios_stage_2_path, bios_stage_3_path, bios_stage_4_path) = (
36+
PathBuf::new(),
37+
PathBuf::new(),
38+
PathBuf::new(),
39+
PathBuf::new(),
40+
);
2841
println!(
2942
"cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}",
3043
bios_boot_sector_path.display()
@@ -43,11 +56,16 @@ async fn bios_main() {
4356
);
4457
}
4558

46-
#[cfg(not(docsrs_dummy_build))]
4759
#[cfg(feature = "uefi")]
4860
async fn uefi_main() {
4961
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
62+
63+
#[cfg(not(docsrs_dummy_build))]
5064
let uefi_path = build_uefi_bootloader(&out_dir).await;
65+
// dummy implementation because docsrs builds have no network access
66+
#[cfg(docsrs_dummy_build)]
67+
let uefi_path = PathBuf::new();
68+
5169
println!(
5270
"cargo:rustc-env=UEFI_BOOTLOADER_PATH={}",
5371
uefi_path.display()
@@ -295,9 +313,3 @@ async fn convert_elf_to_bin(elf_path: PathBuf) -> PathBuf {
295313
}
296314
flat_binary_path
297315
}
298-
299-
// dummy implementations because docsrs builds have no network access
300-
#[cfg(any(not(feature = "bios"), docsrs_dummy_build))]
301-
async fn bios_main() {}
302-
#[cfg(any(not(feature = "uefi"), docsrs_dummy_build))]
303-
async fn uefi_main() {}

0 commit comments

Comments
 (0)