Skip to content

Commit 01fdcbc

Browse files
committed
Move bios boot sector build to top level build script
1 parent 0d77948 commit 01fdcbc

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

bios/build.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

build.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ use std::{
44
};
55

66
const BOOTLOADER_X86_64_UEFI_VERSION: &str = "0.1.0-alpha.0";
7+
const BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION: &str = "0.1.0-alpha.0";
78

89
fn main() {
910
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
1011

1112
let uefi_path = build_uefi_bootloader(&out_dir);
12-
1313
println!(
1414
"cargo:rustc-env=UEFI_BOOTLOADER_PATH={}",
1515
uefi_path.display()
1616
);
17+
18+
let bios_boot_sector_path = build_bios_boot_sector(&out_dir);
19+
println!(
20+
"cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}",
21+
bios_boot_sector_path.display()
22+
);
1723
}
1824

1925
fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
@@ -46,3 +52,40 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
4652
panic!("failed to build uefi bootloader");
4753
}
4854
}
55+
56+
fn build_bios_boot_sector(out_dir: &Path) -> PathBuf {
57+
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());
58+
let mut cmd = Command::new(cargo);
59+
cmd.arg("install").arg("bootloader-x86_64-bios-boot-sector");
60+
let local_path = Path::new(env!("CARGO_MANIFEST_DIR"))
61+
.join("bios")
62+
.join("boot_sector");
63+
if local_path.exists() {
64+
// local build
65+
cmd.arg("--path").arg(&local_path);
66+
} else {
67+
cmd.arg("--version")
68+
.arg(BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION);
69+
}
70+
cmd.arg("--locked");
71+
cmd.arg("--target").arg("x86-16bit.json");
72+
cmd.arg("--profile").arg("first-stage");
73+
cmd.arg("-Zbuild-std=core")
74+
.arg("-Zbuild-std-features=compiler-builtins-mem");
75+
cmd.arg("--root").arg(out_dir);
76+
let status = cmd
77+
.status()
78+
.expect("failed to run cargo install for bios boot sector");
79+
if status.success() {
80+
let path = out_dir
81+
.join("bin")
82+
.join("bootloader-x86_64-bios-boot-sector");
83+
assert!(
84+
path.exists(),
85+
"bios boot sector executable does not exist after building"
86+
);
87+
path
88+
} else {
89+
panic!("failed to build bios boot sector");
90+
}
91+
}
File renamed without changes.

0 commit comments

Comments
 (0)