Skip to content

Commit 8379e3e

Browse files
author
Xiaoyu Lu
committed
Add UEFI target support
1 parent 24e5214 commit 8379e3e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

build.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ const ASM_TARGETS: &[AsmTarget] = &[
235235
asm_extension: "S",
236236
preassemble: true,
237237
},
238+
AsmTarget {
239+
oss: &[UEFI],
240+
arch: "x86_64",
241+
perlasm_format: "nasm",
242+
asm_extension: "asm",
243+
preassemble: true,
244+
},
238245
];
239246

240247
struct AsmTarget {
@@ -279,6 +286,8 @@ const MACOS_ABI: &[&str] = &["ios", "macos"];
279286

280287
const WINDOWS: &str = "windows";
281288

289+
const UEFI: &str = "uefi";
290+
282291
/// Read an environment variable and tell Cargo that we depend on it.
283292
///
284293
/// This needs to be used for any environment variable that isn't a standard
@@ -381,8 +390,9 @@ fn pregenerate_asm_main() {
381390
perlasm(&perlasm_src_dsts, asm_target);
382391

383392
if asm_target.preassemble {
384-
// Preassembly is currently only done for Windows targets.
385-
assert_eq!(&asm_target.oss, &[WINDOWS]);
393+
// Preassembly is currently done for Windows and UEFI targets.
394+
assert!(asm_target.oss.contains(&WINDOWS) || asm_target.oss.contains(&UEFI));
395+
386396
let os = WINDOWS;
387397

388398
let srcs = asm_srcs(perlasm_src_dsts);
@@ -460,7 +470,7 @@ fn build_c_code(
460470

461471
// For Windows we also pregenerate the object files for non-Git builds so
462472
// the user doesn't need to install the assembler.
463-
if use_pregenerated && target.os == WINDOWS {
473+
if use_pregenerated && (target.os == WINDOWS || target.os == UEFI) {
464474
asm_srcs = asm_srcs
465475
.iter()
466476
.map(|src| obj_path(&pregenerated, src.as_path()))
@@ -602,6 +612,7 @@ fn cc(file: &Path, ext: &str, target: &Target, include_dir: &Path, out_file: &Pa
602612
&& target.os != "redox"
603613
&& target.os != "windows"
604614
&& target.arch != "wasm32"
615+
&& target.os != "uefi"
605616
{
606617
let _ = c.flag("-fstack-protector");
607618
}
@@ -642,6 +653,13 @@ fn cc(file: &Path, ext: &str, target: &Target, include_dir: &Path, out_file: &Pa
642653
}
643654
}
644655

656+
// UEFI is a baremental freestanding environment without stdlib.
657+
if target.os == "uefi" && target.arch == "x86_64" {
658+
let _ = c.flag("-nostdlibinc");
659+
let _ = c.define("RING_CORE_NOSTDLIBINC", "1");
660+
let _ = c.flag("-ffreestanding");
661+
}
662+
645663
if target.force_warnings_into_errors {
646664
c.warnings_into_errors(true);
647665
}

0 commit comments

Comments
 (0)