@@ -4,16 +4,22 @@ use std::{
4
4
} ;
5
5
6
6
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" ;
7
8
8
9
fn main ( ) {
9
10
let out_dir = PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
10
11
11
12
let uefi_path = build_uefi_bootloader ( & out_dir) ;
12
-
13
13
println ! (
14
14
"cargo:rustc-env=UEFI_BOOTLOADER_PATH={}" ,
15
15
uefi_path. display( )
16
16
) ;
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
+ ) ;
17
23
}
18
24
19
25
fn build_uefi_bootloader ( out_dir : & Path ) -> PathBuf {
@@ -46,3 +52,40 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
46
52
panic ! ( "failed to build uefi bootloader" ) ;
47
53
}
48
54
}
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
+ }
0 commit comments