Skip to content

Commit cd02b2f

Browse files
committed
Use x86_64-unknown-uefi target
Rust now supports uefi as a build target: rust-lang/rust#56769 This change mainly eliminates references to the custom JSON target file. It also requires that the entry point's name be changed to `efi_main`. Note that the "C" abi is now correct for EFI applications, but will still be incorrect when uefi-rs is brought in as an external dependancy for a different target. This means the entry point should always be `extern "C"` while the table of function pointers should be `extern "win64"`.
1 parent 954a359 commit cd02b2f

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

BUILDING.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
UEFI applications are simple COFF (Windows) executables, with the special
44
`EFI_Application` subsystem, and some limitations (such as no dynamic linking).
5-
6-
The `x86_64-uefi.json` file describes a custom target for building UEFI apps.
5+
[Rust supports building UEFI applications](https://github.com/rust-lang/rust/pull/56769)
6+
though the `x86_64-unknown-uefi` target.
77

88
## Prerequisites
99

@@ -19,15 +19,12 @@ The following steps allow you to build a simple UEFI app.
1919

2020
```rust
2121
#[no_mangle]
22-
pub extern "win64" fn uefi_start(handle: Handle, system_table: SystemTable<Boot>) -> Status;
22+
pub extern "C" fn efi_main(handle: Handle, system_table: SystemTable<Boot>) -> Status;
2323
```
2424

25-
- Copy the `uefi-test-runner/x86_64-uefi.json` target file to your project's root.
26-
You can customize it.
27-
28-
- Build using `cargo xbuild --target x86_64-uefi`.
25+
- Build using `cargo xbuild --target x86_64-unknown-uefi`.
2926

30-
- The `target` directory will contain a `x86_64-uefi` subdirectory,
27+
- The `target` directory will contain a `x86_64-unknown-uefi` subdirectory,
3128
where you will find the `uefi_app.efi` file - a normal UEFI executable.
3229

3330
- To run this on a real computer:

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
OS loaders, hypervisors and other low-level applications. While it started out
99
as x86-specific, it has been adopted on other platforms, such as ARM.
1010

11-
This crates makes it easy to write UEFI applications in Rust.
11+
This crate makes it easy to both:
12+
- Write UEFI applications in Rust (via the [`x86_64-unknown-uefi`][rustc-uefi] target)
13+
- Call UEFI functions from an OS (usually built with a [custom target][rustc-custom])
1214

1315
The objective is to provide **safe** and **performant** wrappers for UEFI interfaces,
1416
and allow developers to write idiomatic Rust code.
@@ -20,6 +22,8 @@ and has been tested _only_ with **64-bit** UEFI.
2022

2123
[UEFI]: https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface
2224
[gm-blog]: https://medium.com/@gil0mendes/an-efi-app-a-bit-rusty-82c36b745f49
25+
[rustc-uefi]: https://github.com/rust-lang/rust/pull/56769
26+
[rustc-custom]: https://doc.rust-lang.org/rustc/targets/custom.html
2327

2428
![uefi-rs running in QEMU](https://imgur.com/SFPSVuO.png)
2529

@@ -49,7 +53,7 @@ This project contains multiple sub-crates:
4953

5054
## Building kernels which use UEFI
5155

52-
This crate makes it easy to start buildimg simple applications with UEFI.
56+
This crate makes it easy to start building simple applications with UEFI.
5357
However, there are some limitations you should be aware of:
5458

5559
- The global logger / allocator **can only be set once** per binary.
@@ -92,8 +96,6 @@ An example UEFI app is built in the `uefi-test-runner` directory.
9296

9397
Check out the testing [README.md](uefi-test-runner/README.md) for instructions on how to run the crate's tests.
9498

95-
This repo also contains a `x86_64-uefi.json` file, which is a custom Rust target for 64-bit UEFI applications.
96-
9799
## Building UEFI programs
98100

99101
For instructions on how to create your own UEFI apps, see the [BUILDING.md](BUILDING.md) file.

uefi-test-runner/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Run QEMU without showing GUI
2424
'headless': False,
2525
# Target to build for.
26-
'target': 'x86_64-uefi',
26+
'target': 'x86_64-unknown-uefi',
2727
# Configuration to build.
2828
'config': 'debug',
2929
# QEMU executable to use

uefi-test-runner/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod boot;
2020
mod proto;
2121

2222
#[no_mangle]
23-
pub extern "win64" fn uefi_start(image: uefi::Handle, st: SystemTable<Boot>) -> Status {
23+
pub extern "C" fn efi_main(image: uefi::Handle, st: SystemTable<Boot>) -> Status {
2424
// Initialize utilities (logging, memory allocation...)
2525
uefi_services::init(&st).expect_success("Failed to initialize utilities");
2626

uefi-test-runner/x86_64-uefi.json

-26
This file was deleted.

0 commit comments

Comments
 (0)