@@ -3,47 +3,49 @@ use std::{
3
3
process:: Command ,
4
4
} ;
5
5
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" ) ;
12
7
13
8
fn main ( ) {
14
9
let out_dir = PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
15
10
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
+ }
21
19
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
+ ) ;
32
32
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
+ ) ;
38
38
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
+ }
44
45
}
45
46
46
47
#[ cfg( not( docsrs_dummy_build) ) ]
48
+ #[ cfg( feature = "uefi" ) ]
47
49
fn build_uefi_bootloader ( out_dir : & Path ) -> PathBuf {
48
50
let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
49
51
let mut cmd = Command :: new ( cargo) ;
@@ -53,7 +55,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
53
55
cmd. arg ( "--path" ) . arg ( "uefi" ) ;
54
56
println ! ( "cargo:rerun-if-changed=uefi" ) ;
55
57
} else {
56
- cmd. arg ( "--version" ) . arg ( BOOTLOADER_X86_64_UEFI_VERSION ) ;
58
+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
57
59
}
58
60
cmd. arg ( "--locked" ) ;
59
61
cmd. arg ( "--target" ) . arg ( "x86_64-unknown-uefi" ) ;
@@ -78,6 +80,7 @@ fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
78
80
}
79
81
80
82
#[ cfg( not( docsrs_dummy_build) ) ]
83
+ #[ cfg( feature = "bios" ) ]
81
84
fn build_bios_boot_sector ( out_dir : & Path ) -> PathBuf {
82
85
let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
83
86
let mut cmd = Command :: new ( cargo) ;
@@ -90,8 +93,7 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf {
90
93
cmd. arg ( "--path" ) . arg ( & local_path) ;
91
94
println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
92
95
} else {
93
- cmd. arg ( "--version" )
94
- . arg ( BOOTLOADER_X86_64_BIOS_BOOT_SECTOR_VERSION ) ;
96
+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
95
97
}
96
98
cmd. arg ( "--locked" ) ;
97
99
cmd. arg ( "--target" ) . arg ( "i386-code16-boot-sector.json" ) ;
@@ -121,6 +123,7 @@ fn build_bios_boot_sector(out_dir: &Path) -> PathBuf {
121
123
}
122
124
123
125
#[ cfg( not( docsrs_dummy_build) ) ]
126
+ #[ cfg( feature = "bios" ) ]
124
127
fn build_bios_stage_2 ( out_dir : & Path ) -> PathBuf {
125
128
let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
126
129
let mut cmd = Command :: new ( cargo) ;
@@ -133,8 +136,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf {
133
136
cmd. arg ( "--path" ) . arg ( & local_path) ;
134
137
println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
135
138
} else {
136
- cmd. arg ( "--version" )
137
- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_2_VERSION ) ;
139
+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
138
140
}
139
141
cmd. arg ( "--locked" ) ;
140
142
cmd. arg ( "--target" ) . arg ( "i386-code16-stage-2.json" ) ;
@@ -162,6 +164,7 @@ fn build_bios_stage_2(out_dir: &Path) -> PathBuf {
162
164
}
163
165
164
166
#[ cfg( not( docsrs_dummy_build) ) ]
167
+ #[ cfg( feature = "bios" ) ]
165
168
fn build_bios_stage_3 ( out_dir : & Path ) -> PathBuf {
166
169
let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
167
170
let mut cmd = Command :: new ( cargo) ;
@@ -174,8 +177,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf {
174
177
cmd. arg ( "--path" ) . arg ( & local_path) ;
175
178
println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
176
179
} else {
177
- cmd. arg ( "--version" )
178
- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_3_VERSION ) ;
180
+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
179
181
}
180
182
cmd. arg ( "--locked" ) ;
181
183
cmd. arg ( "--target" ) . arg ( "i686-stage-3.json" ) ;
@@ -203,6 +205,7 @@ fn build_bios_stage_3(out_dir: &Path) -> PathBuf {
203
205
}
204
206
205
207
#[ cfg( not( docsrs_dummy_build) ) ]
208
+ #[ cfg( feature = "bios" ) ]
206
209
fn build_bios_stage_4 ( out_dir : & Path ) -> PathBuf {
207
210
let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . into ( ) ) ;
208
211
let mut cmd = Command :: new ( cargo) ;
@@ -215,8 +218,7 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf {
215
218
cmd. arg ( "--path" ) . arg ( & local_path) ;
216
219
println ! ( "cargo:rerun-if-changed={}" , local_path. display( ) ) ;
217
220
} else {
218
- cmd. arg ( "--version" )
219
- . arg ( BOOTLOADER_X86_64_BIOS_STAGE_4_VERSION ) ;
221
+ cmd. arg ( "--version" ) . arg ( BOOTLOADER_VERSION ) ;
220
222
}
221
223
cmd. arg ( "--locked" ) ;
222
224
cmd. arg ( "--target" ) . arg ( "x86_64-stage-4.json" ) ;
@@ -244,6 +246,7 @@ fn build_bios_stage_4(out_dir: &Path) -> PathBuf {
244
246
convert_elf_to_bin ( elf_path)
245
247
}
246
248
249
+ #[ cfg( feature = "bios" ) ]
247
250
fn convert_elf_to_bin ( elf_path : PathBuf ) -> PathBuf {
248
251
let flat_binary_path = elf_path. with_extension ( "bin" ) ;
249
252
0 commit comments