@@ -3,47 +3,49 @@ use std::{
33 process:: Command ,
44} ;
55
6- const BOOTLOADER_X86_64_UEFI_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
7-
8- const BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
9- const BOOTLOADER_X86_64_BIOS_STAGE_2_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
10- const BOOTLOADER_X86_64_BIOS_STAGE_3_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
11- const BOOTLOADER_X86_64_BIOS_STAGE_4_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
6+ const BOOTLOADER_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
127
138fn main ( ) {
149 let out_dir = PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
1510
16- let uefi_path = build_uefi_bootloader ( & out_dir) ;
17- println ! (
18- "cargo:rustc-env=UEFI_BOOTLOADER_PATH={}" ,
19- uefi_path. display( )
20- ) ;
11+ #[ cfg( feature = "uefi" ) ]
12+ {
13+ let uefi_path = build_uefi_bootloader ( & out_dir) ;
14+ println ! (
15+ "cargo:rustc-env=UEFI_BOOTLOADER_PATH={}" ,
16+ uefi_path. display( )
17+ ) ;
18+ }
2119
22- let bios_boot_sector_path = build_bios_boot_sector ( & out_dir) ;
23- println ! (
24- "cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}" ,
25- bios_boot_sector_path. display( )
26- ) ;
27- let bios_stage_2_path = build_bios_stage_2 ( & out_dir) ;
28- println ! (
29- "cargo:rustc-env=BIOS_STAGE_2_PATH={}" ,
30- bios_stage_2_path. display( )
31- ) ;
20+ #[ cfg( feature = "bios" ) ]
21+ {
22+ let bios_boot_sector_path = build_bios_boot_sector ( & out_dir) ;
23+ println ! (
24+ "cargo:rustc-env=BIOS_BOOT_SECTOR_PATH={}" ,
25+ bios_boot_sector_path. display( )
26+ ) ;
27+ let bios_stage_2_path = build_bios_stage_2 ( & out_dir) ;
28+ println ! (
29+ "cargo:rustc-env=BIOS_STAGE_2_PATH={}" ,
30+ bios_stage_2_path. display( )
31+ ) ;
3232
33- let bios_stage_3_path = build_bios_stage_3 ( & out_dir) ;
34- println ! (
35- "cargo:rustc-env=BIOS_STAGE_3_PATH={}" ,
36- bios_stage_3_path. display( )
37- ) ;
33+ let bios_stage_3_path = build_bios_stage_3 ( & out_dir) ;
34+ println ! (
35+ "cargo:rustc-env=BIOS_STAGE_3_PATH={}" ,
36+ bios_stage_3_path. display( )
37+ ) ;
3838
39- let bios_stage_4_path = build_bios_stage_4 ( & out_dir) ;
40- println ! (
41- "cargo:rustc-env=BIOS_STAGE_4_PATH={}" ,
42- bios_stage_4_path. display( )
43- ) ;
39+ let bios_stage_4_path = build_bios_stage_4 ( & out_dir) ;
40+ println ! (
41+ "cargo:rustc-env=BIOS_STAGE_4_PATH={}" ,
42+ bios_stage_4_path. display( )
43+ ) ;
44+ }
4445}
4546
4647#[ cfg( not( docsrs_dummy_build) ) ]
48+ #[ cfg( feature = "uefi" ) ]
4749fn build_uefi_bootloader ( out_dir : & Path ) -> PathBuf {
4850 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
4951 let mut cmd = Command :: new ( cargo) ;
@@ -53,7 +55,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
5355 cmd. arg ( "--path" ) . arg ( "uefi" ) ;
5456 println ! ( "cargo:rerun-if-changed=uefi" ) ;
5557 } else {
56- cmd. arg ( "--version" ) . arg ( BOOTLOADER_X86_64_UEFI_VERSION ) ;
58+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
5759 }
5860 cmd. arg ( "--locked" ) ;
5961 cmd. arg ( "--target" ) . arg ( "x86_64-unknown-uefi" ) ;
@@ -78,6 +80,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
7880}
7981
8082#[ cfg( not( docsrs_dummy_build) ) ]
83+ #[ cfg( feature = "bios" ) ]
8184fn build_bios_boot_sector ( out_dir : & Path ) -> PathBuf {
8285 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
8386 let mut cmd = Command :: new ( cargo) ;
@@ -90,8 +93,7 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf {
9093 cmd. arg ( "--path" ) . arg ( & local_path) ;
9194 println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
9295 } else {
93- cmd. arg ( "--version" )
94- . arg ( BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION ) ;
96+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
9597 }
9698 cmd. arg ( "--locked" ) ;
9799 cmd. arg ( "--target" ) . arg ( "i386-code16-boot-sector.json" ) ;
@@ -121,6 +123,7 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf {
121123}
122124
123125#[ cfg( not( docsrs_dummy_build) ) ]
126+ #[ cfg( feature = "bios" ) ]
124127fn build_bios_stage_2 ( out_dir : & Path ) -> PathBuf {
125128 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
126129 let mut cmd = Command :: new ( cargo) ;
@@ -133,8 +136,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf {
133136 cmd. arg ( "--path" ) . arg ( & local_path) ;
134137 println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
135138 } else {
136- cmd. arg ( "--version" )
137- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_2_VERSION ) ;
139+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
138140 }
139141 cmd. arg ( "--locked" ) ;
140142 cmd. arg ( "--target" ) . arg ( "i386-code16-stage-2.json" ) ;
@@ -162,6 +164,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf {
162164}
163165
164166#[ cfg( not( docsrs_dummy_build) ) ]
167+ #[ cfg( feature = "bios" ) ]
165168fn build_bios_stage_3 ( out_dir : & Path ) -> PathBuf {
166169 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
167170 let mut cmd = Command :: new ( cargo) ;
@@ -174,8 +177,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf {
174177 cmd. arg ( "--path" ) . arg ( & local_path) ;
175178 println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
176179 } else {
177- cmd. arg ( "--version" )
178- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_3_VERSION ) ;
180+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
179181 }
180182 cmd. arg ( "--locked" ) ;
181183 cmd. arg ( "--target" ) . arg ( "i686-stage-3.json" ) ;
@@ -203,6 +205,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf {
203205}
204206
205207#[ cfg( not( docsrs_dummy_build) ) ]
208+ #[ cfg( feature = "bios" ) ]
206209fn build_bios_stage_4 ( out_dir : & Path ) -> PathBuf {
207210 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
208211 let mut cmd = Command :: new ( cargo) ;
@@ -215,8 +218,7 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf {
215218 cmd. arg ( "--path" ) . arg ( & local_path) ;
216219 println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
217220 } else {
218- cmd. arg ( "--version" )
219- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_4_VERSION ) ;
221+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
220222 }
221223 cmd. arg ( "--locked" ) ;
222224 cmd. arg ( "--target" ) . arg ( "x86_64-stage-4.json" ) ;
@@ -244,6 +246,7 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf {
244246 convert_elf_to_bin ( elf_path)
245247}
246248
249+ #[ cfg( feature = "bios" ) ]
247250fn convert_elf_to_bin ( elf_path : PathBuf ) -> PathBuf {
248251 let flat_binary_path = elf_path. with_extension ( "bin" ) ;
249252
0 commit comments