Skip to content

Commit

Permalink
Fixes after bumping Rust toolchain
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Sep 18, 2024
1 parent 9a6bae7 commit 23e9048
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ cfg_if::cfg_if! {
unsafe extern "C" fn __rust_entry(bootinfo: *const sel4::BootInfo) -> ! {
let bootinfo = sel4::BootInfoPtr::new(bootinfo);
match main(&bootinfo) {
#[allow(unreachable_patterns)]
Ok(absurdity) => match absurdity {},
Err(err) => panic!("Error: {}", err),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-microkit/base/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ pub fn ipc_buffer_ptr() -> *mut sel4::IpcBuffer {
static mut __sel4_ipc_buffer_obj: sel4::IpcBuffer;
}

unsafe { ptr::addr_of_mut!(__sel4_ipc_buffer_obj) }
ptr::addr_of_mut!(__sel4_ipc_buffer_obj)
}
1 change: 1 addition & 0 deletions crates/sel4-microkit/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ macro_rules! declare_init {
#[allow(clippy::missing_safety_doc)]
pub fn run_main<T: Handler>(init: impl FnOnce() -> T + UnwindSafe) -> ! {
let result = catch_unwind(|| match init().run() {
#[allow(unreachable_patterns)]
Ok(absurdity) => match absurdity {},
Err(err) => err,
});
Expand Down
30 changes: 22 additions & 8 deletions crates/sel4-panicking/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@

use core::cmp::Reverse;

// Determine whether rustc includes https://github.com/rust-lang/rust/pull/121598
// Determine whether rustc includes the following changes:
// - https://blog.rust-lang.org/2024/05/06/check-cfg.html
// - https://github.com/rust-lang/rust/pull/121598
// - https://github.com/rust-lang/rust/pull/126732

fn main() {
let version_meta = rustc_version::version_meta().unwrap();
let semver = version_meta.semver;
let commit_date = order_date(version_meta.commit_date);
let key = (semver.major, semver.minor, semver.patch, commit_date);
let first_with_change = (1, 78, 0, order_date(Some("2024-02-28".to_owned())));
if key < first_with_change {
let key = {
let version_meta = rustc_version::version_meta().unwrap();
let semver = version_meta.semver;
let commit_date = order_date(version_meta.commit_date);
(semver.major, semver.minor, semver.patch, commit_date)
};
let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned())));
let unwind_intrinsic_renamed = (1, 78, 0, order_date(Some("2024-02-28".to_owned())));
let panic_info_message_stabilized = (1, 81, 0, order_date(Some("2024-07-01".to_owned())));
if key >= check_cfg_required {
println!("cargo:rustc-check-cfg=cfg(catch_unwind_intrinsic_still_named_try)");
println!("cargo:rustc-check-cfg=cfg(panic_info_message_stable)");
}
if key < unwind_intrinsic_renamed {
println!("cargo:rustc-cfg=catch_unwind_intrinsic_still_named_try");
}
if key >= panic_info_message_stabilized {
println!("cargo:rustc-cfg=panic_info_message_stable");
}
}

// assume no build date means more recent
// no build date means more recent
fn order_date(date: Option<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
23 changes: 16 additions & 7 deletions crates/sel4-panicking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#![feature(core_intrinsics)]
#![feature(lang_items)]
#![feature(panic_can_unwind)]
#![feature(panic_info_message)]
#![feature(thread_local)]
#![cfg_attr(not(panic_info_message_stable), feature(panic_info_message))]
#![allow(internal_features)]

#[cfg(feature = "alloc")]
Expand All @@ -21,6 +21,9 @@ use core::mem::ManuallyDrop;
use core::panic::Location;
use core::panic::{PanicInfo, UnwindSafe};

#[cfg(panic_info_message_stable)]
use core::panic::PanicMessage;

use cfg_if::cfg_if;

use sel4_panicking_env::abort;
Expand All @@ -38,9 +41,12 @@ use strategy::{panic_cleanup, start_panic};
pub use hook::{set_hook, PanicHook};
pub use payload::{Payload, SmallPayload, UpcastIntoPayload, SMALL_PAYLOAD_MAX_SIZE};

#[cfg(not(panic_info_message_stable))]
type PanicMessage<'a> = &'a fmt::Arguments<'a>;

pub struct ExternalPanicInfo<'a> {
payload: Payload,
message: Option<&'a fmt::Arguments<'a>>,
message: Option<PanicMessage<'a>>,
location: Option<&'a Location<'a>>,
can_unwind: bool,
}
Expand All @@ -50,8 +56,8 @@ impl<'a> ExternalPanicInfo<'a> {
&self.payload
}

pub fn message(&self) -> Option<&fmt::Arguments> {
self.message
pub fn message(&self) -> Option<&PanicMessage> {
self.message.as_ref()
}

pub fn location(&self) -> Option<&Location> {
Expand All @@ -66,14 +72,14 @@ impl<'a> ExternalPanicInfo<'a> {
impl fmt::Display for ExternalPanicInfo<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("panicked at ")?;
if let Some(location) = self.location {
if let Some(location) = self.location() {
location.fmt(f)?;
} else {
f.write_str("unknown location")?;
}
if let Some(message) = self.message {
if let Some(message) = self.message() {
f.write_str(":\n")?;
f.write_fmt(*message)?;
message.fmt(f)?;
}
Ok(())
}
Expand All @@ -83,6 +89,9 @@ impl fmt::Display for ExternalPanicInfo<'_> {
fn panic(info: &PanicInfo) -> ! {
do_panic(ExternalPanicInfo {
payload: NoPayload.upcast_into_payload(),
#[cfg(panic_info_message_stable)]
message: Some(info.message()),
#[cfg(not(panic_info_message_stable))]
message: info.message(),
location: info.location(),
can_unwind: info.can_unwind(),
Expand Down
2 changes: 2 additions & 0 deletions crates/sel4-root-task/src/termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<E> Termination for Result<!, E> {

fn report(self) -> Self::Error {
match self {
#[allow(unreachable_patterns)]
Ok(absurdity) => match absurdity {},
Err(err) => err,
}
Expand All @@ -44,6 +45,7 @@ impl<E> Termination for Result<Never, E> {

fn report(self) -> Self::Error {
match self {
#[allow(unreachable_patterns)]
Ok(absurdity) => match absurdity {},
Err(err) => err,
}
Expand Down
5 changes: 4 additions & 1 deletion crates/sel4/bitfield-ops/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk }:
{ mk, versions }:

mk {
package.name = "sel4-bitfield-ops";
build-dependencies = {
inherit (versions) rustc_version;
};
}
3 changes: 3 additions & 0 deletions crates/sel4/bitfield-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[build-dependencies]
rustc_version = "0.4.0"
27 changes: 27 additions & 0 deletions crates/sel4/bitfield-ops/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use core::cmp::Reverse;

// Determine whether rustc includes https://github.com/rust-lang/rust/pull/121598

fn main() {
let key = {
let version_meta = rustc_version::version_meta().unwrap();
let semver = version_meta.semver;
let commit_date = order_date(version_meta.commit_date);
(semver.major, semver.minor, semver.patch, commit_date)
};
let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned())));
if key >= check_cfg_required {
println!("cargo:rustc-check-cfg=cfg(kani)");
}
}

// no build date means more recent
fn order_date(date: Option<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}

0 comments on commit 23e9048

Please sign in to comment.