Skip to content

Commit

Permalink
base: unconditionally use stabilized "efiapi"
Browse files Browse the repository at this point in the history
With rust-1.68 the "efiapi" feature was stabilized. Use it
unconditionally and turn the old feature into a no-op.

As a next step we can replace all "efiapi!{}" calls with `extern
"efiapi"`.

Signed-off-by: David Rheinsberg <david@readahead.eu>
  • Loading branch information
dvdhrm committed Mar 16, 2023
1 parent f5ddfb8 commit dfcc047
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
matrix:
rust:
- "nightly"
- "stable"
# - "stable"
- "1.68" # XXX: Workaround until github-runners update `stable`.

steps:
- name: "Fetch Sources"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ compiler_builtins = { version = '0.1.0', optional = true }
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }

[features]
# Use the 'efiapi' calling convention designator (nightly-only).
# No-op for backwards compatibility.
efiapi = []
# Maps to `native` for backwards compatibility.
examples = ['native']
Expand Down
2 changes: 1 addition & 1 deletion examples/uefi-cross-compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// compile-flags: --target x86_64-unknown-uefi

#![feature(abi_efiapi, lang_items, no_core)]
#![feature(lang_items, no_core)]
#![no_core]
#![no_main]

Expand Down
53 changes: 6 additions & 47 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,60 +127,21 @@ compile_error!("The target endianness is not supported.");
// eficall_abi!()
//
// This macro is the architecture-dependent implementation of eficall!(). See the documentation of
// the eficall!() macro for a description.
// the eficall!() macro for a description. Nowadays, this simply maps to `extern "efiapi"`, since
// this has been stabilized with rust-1.68.

#[cfg(feature = "efiapi")]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "efiapi" $($suffix)* };
}

#[cfg(all(target_arch = "arm", not(feature = "efiapi")))]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "aapcs" $($suffix)* };
}

// XXX: Rust does not define aapcs64, yet. Once it does, we should switch to it, rather than
// referring to the system default.
#[cfg(all(target_arch = "aarch64", not(feature = "efiapi")))]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "C" $($suffix)* };
}

#[cfg(all(target_arch = "x86", not(feature = "efiapi")))]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "cdecl" $($suffix)* };
}

#[cfg(all(target_arch = "x86_64", not(feature = "efiapi")))]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "win64" $($suffix)* };
}

#[cfg(not(any(
feature = "efiapi",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64"
)))]
#[macro_export]
#[doc(hidden)]
macro_rules! eficall_abi {
(($($prefix:tt)*),($($suffix:tt)*)) => { $($prefix)* extern "C" $($suffix)* };
}

/// Annotate function with UEFI calling convention
///
/// Since rust-1.68 you can use `extern "efiapi"` as calling-convention to achieve the same
/// behavior as this macro. This macro is kept for backwards-compatibility only, but will nowadays
/// map to `extern "efiapi"`.
///
/// This macro takes a function-declaration as argument and produces the same function-declaration
/// but annotated with the correct calling convention. Since the default `extern "C"` annotation
/// depends on your compiler defaults, we cannot use it. Instead, this macro selects the default
Expand All @@ -200,7 +161,6 @@ macro_rules! eficall_abi {
/// inserted at the correct place:
///
/// ```
/// # #![cfg_attr(feature = "efiapi", feature(abi_efiapi))]
/// use r_efi::{eficall, eficall_abi};
///
/// eficall!{pub fn foobar() {
Expand All @@ -224,7 +184,6 @@ macro_rules! eficall_abi {
/// is "C":
///
/// ```
/// # #![cfg_attr(feature = "efiapi", feature(abi_efiapi))]
/// use r_efi::{eficall, eficall_abi};
///
/// type FooBar1 = unsafe extern "C" fn(u8) -> (u8);
Expand Down
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@
// basic unit-tests on the compilation host. For integration tests, we have separate compilation
// units, so they will be unaffected by this.
#![cfg_attr(not(test), no_std)]
// The `efiapi` calling convention designator automatically picks the correct
// EFI-compatible ABI for the target platform. It currently requires the
// `abi_efiapi` unstable feature and is thus guarded by us behind the `efiapi`
// crate-feature.
#![cfg_attr(feature = "efiapi", feature(abi_efiapi))]

// Import the different core modules. We separate them into different modules to make it easier to
// work on them and describe what each part implements. This is different to the reference
Expand Down

0 comments on commit dfcc047

Please sign in to comment.