Skip to content

Commit

Permalink
uefi_std: Remove unstable features except prelude_import
Browse files Browse the repository at this point in the history
Most of the unstable features are not required for building.

For panics, the only remaining detail is having an implementation of the
panic handler (`panic_handler`) itself.

- `eh_personality`: Not required with `panic=abort`
- `_Unwind_Resume`: Symbol not present with `panic=abort`
- `alloc_error_handler`: OOM triggers a panic; feature will be removed [1]

[1]: rust-lang/rust#112331

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed May 30, 2024
1 parent e9030af commit a784d3b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 55 deletions.
2 changes: 1 addition & 1 deletion crates/uefi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]
#![allow(dead_code)]
#![allow(non_snake_case)]
#![no_std]

#[macro_use]
pub mod macros;
Expand Down
19 changes: 1 addition & 18 deletions crates/uefi_std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#![no_std]
#![feature(alloc_error_handler)]
#![feature(concat_idents)]
#![feature(core_intrinsics)]
#![feature(custom_test_frameworks)]
#![feature(format_args_nl)]
#![feature(lang_items)]
#![feature(log_syntax)]
#![feature(prelude_import)]
#![feature(prelude_2024)]
#![feature(slice_concat_ext)]
#![feature(test)]
#![feature(trace_macros)]

/* This section was addapted from the Rust Standard Library, and is licensed accordingly
* https://github.com/rust-lang/rust/blob/master/src/libstd/lib.rs
Expand Down Expand Up @@ -60,7 +49,6 @@ pub use core::i16;
pub use core::i32;
pub use core::i64;
pub use core::i8;
pub use core::intrinsics;
pub use core::isize;
pub use core::iter;
pub use core::marker;
Expand Down Expand Up @@ -96,28 +84,23 @@ pub use core::{
};

// Re-export built-in macros defined through libcore.
pub use core::prelude::v1::{
pub use core::prelude::rust_2021::{
// Stable
assert,
cfg,
column,
compile_error,
concat,
// Unstable
concat_idents,
env,
file,
format_args,
format_args_nl,
include,
include_bytes,
include_str,
line,
log_syntax,
module_path,
option_env,
stringify,
trace_macros,
};

/* } */
Expand Down
12 changes: 6 additions & 6 deletions crates/uefi_std/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ pub use crate::result::Result::{self, Err, Ok};

// Re-exported built-in macros
#[doc(no_inline)]
pub use core::prelude::v1::{
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
stringify, trace_macros,
pub use core::prelude::rust_2021::{
assert, cfg, column, compile_error, concat, env, file,
include, include_bytes, include_str, line, module_path, option_env,
stringify,
};

// FIXME: Attribute and derive macros are not documented because for them rustdoc generates
// dead links which fail link checker testing.
#[allow(deprecated)]
#[doc(hidden)]
pub use core::prelude::v1::{
bench, test, test_case, Clone, Copy, Debug, Default, Eq, Hash, Ord,
pub use core::prelude::rust_2021::{
Clone, Copy, Debug, Default, Eq, Hash, Ord,
PartialEq, PartialOrd,
};

Expand Down
31 changes: 1 addition & 30 deletions crates/uefi_std/src/rt/panic.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
// These functions are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.

use core::prelude::rust_2024::alloc_error_handler;

#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}

#[panic_handler]
#[no_mangle]
pub fn rust_begin_panic(pi: &::core::panic::PanicInfo) -> ! {
pub fn panic(pi: &core::panic::PanicInfo) -> ! {
print!("SETUP PANIC: {}", pi);

loop {}
}

#[alloc_error_handler]
#[no_mangle]
pub fn rust_oom(layout: ::core::alloc::Layout) -> ! {
println!(
"SETUP OOM: {} bytes aligned to {} bytes\n",
layout.size(),
layout.align()
);

loop {}
}

#[allow(non_snake_case)]
#[no_mangle]
pub extern "C" fn _Unwind_Resume() {
loop {}
}

0 comments on commit a784d3b

Please sign in to comment.