Skip to content

Commit 96e635a

Browse files
committed
Adapt riscv-rt to edition 2024
1 parent 38dc500 commit 96e635a

File tree

10 files changed

+31
-40
lines changed

10 files changed

+31
-40
lines changed

.github/workflows/riscv-rt.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
build-riscv:
1111
strategy:
1212
matrix:
13-
# All generated code should be running on stable now, MRSV is 1.67.0
14-
toolchain: [ stable, nightly, 1.67.0 ]
13+
# All generated code should be running on stable now, MRSV is 1.85.0
14+
toolchain: [ stable, nightly, 1.85.0 ]
1515
target:
1616
- riscv32i-unknown-none-elf
1717
- riscv32im-unknown-none-elf
@@ -27,11 +27,6 @@ jobs:
2727
# Nightly is only for reference and allowed to fail
2828
- toolchain: nightly
2929
experimental: true
30-
exclude:
31-
- toolchain: 1.67.0
32-
target: riscv32im-unknown-none-elf
33-
- toolchain: 1.67.0
34-
target: riscv32imafc-unknown-none-elf
3530
runs-on: ubuntu-latest
3631
continue-on-error: ${{ matrix.experimental || false }}
3732
steps:

.github/workflows/tests.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
run-build:
2121
strategy:
2222
matrix:
23-
# All generated code should be running on stable now, MRSV is 1.67.0
24-
toolchain: [ stable, nightly, 1.67.0 ]
23+
# All generated code should be running on stable now, MRSV is 1.85.0
24+
toolchain: [ stable, nightly, 1.85.0 ]
2525
target:
2626
- riscv32i-unknown-none-elf
2727
- riscv32im-unknown-none-elf
@@ -36,11 +36,6 @@ jobs:
3636
# Nightly is only for reference and allowed to fail
3737
- toolchain: nightly
3838
experimental: true
39-
exclude:
40-
- toolchain: 1.67.0
41-
target: riscv32im-unknown-none-elf
42-
- toolchain: 1.67.0
43-
target: riscv32imafc-unknown-none-elf
4439
runs-on: ubuntu-latest
4540
continue-on-error: ${{ matrix.experimental || false }}
4641
steps:

riscv-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12+
- Update to Rust edition 2024 (MSRV 1.85)
1213
- Main function no longer needs to be close to _start. A linker script may copy
1314
all code to RAM and keep .init in flash/ROM.
1415
- By default, the stack is now split into equal parts based on the number of

riscv-rt/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "riscv-rt"
33
version = "0.15.0"
4-
rust-version = "1.67"
4+
rust-version = "1.85"
55
repository = "https://github.com/rust-embedded/riscv"
66
authors = ["The RISC-V Team <risc-v@teams.rust-embedded.org>"]
77
categories = ["embedded", "no-std"]
88
description = "Minimal runtime / startup for RISC-V CPU's"
99
documentation = "https://docs.rs/riscv-rt"
1010
keywords = ["riscv", "runtime", "startup"]
1111
license = "ISC"
12-
edition = "2021"
12+
edition = "2024"
1313
links = "riscv-rt" # Prevent multiple versions of riscv-rt being linked
1414

1515
[package.metadata.docs.rs]

riscv-rt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [RISC-V team][team].
1111

1212
## Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.61 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.85 and up. It **won't**
1515
compile with older versions but that may change in any new patch release.
1616

1717
## License

riscv-rt/examples/multi_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use riscv::asm::wfi;
77
use riscv::register::{mie, mip};
88
use riscv_rt::entry;
99

10-
#[export_name = "_mp_hook"]
10+
#[unsafe(export_name = "_mp_hook")]
1111
#[rustfmt::skip]
1212
pub extern "Rust" fn user_mp_hook(hartid: usize) -> bool {
1313
if hartid == 0 {

riscv-rt/macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
1111
name = "riscv-rt-macros"
1212
repository = "https://github.com/rust-embedded/riscv"
1313
version = "0.5.0"
14-
edition = "2021"
14+
edition = "2024"
1515

1616
[lib]
1717
proc-macro = true

riscv-rt/macros/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use proc_macro::TokenStream;
44
use proc_macro2::{Span, TokenStream as TokenStream2};
55
use quote::quote;
66
use syn::{
7+
FnArg, ItemFn, LitInt, LitStr, PatType, Path, ReturnType, Token, Type, Visibility,
78
parse::{self, Parse},
89
parse_macro_input, parse_quote,
910
punctuated::Punctuated,
1011
spanned::Spanned,
11-
FnArg, ItemFn, LitInt, LitStr, PatType, Path, ReturnType, Token, Type, Visibility,
1212
};
1313

1414
/// Attribute to declare the entry point of the program
@@ -142,7 +142,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
142142

143143
quote!(
144144
#[allow(non_snake_case)]
145-
#[export_name = "main"]
145+
#[unsafe(export_name = "main")]
146146
#(#attrs)*
147147
pub #unsafety fn __risc_v_rt__main(#args) -> ! {
148148
#(#stmts)*
@@ -254,7 +254,7 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
254254
let block = f.block;
255255

256256
quote!(
257-
#[export_name = "__pre_init"]
257+
#[unsafe(export_name = "__pre_init")]
258258
#(#attrs)*
259259
pub unsafe fn #ident() #block
260260
)
@@ -457,7 +457,7 @@ fn store_trap<T: FnMut(&str) -> bool>(arch: RiscvArch, mut filter: T) -> String
457457
arch.trap_frame()
458458
.iter()
459459
.enumerate()
460-
.filter(|(_, &reg)| !reg.starts_with('_') && filter(reg))
460+
.filter(|(_, reg)| !reg.starts_with('_') && filter(reg))
461461
.map(|(i, reg)| format!("{store} {reg}, {i}*{width}(sp)"))
462462
.collect::<Vec<_>>()
463463
.join("\n ")
@@ -471,7 +471,7 @@ fn load_trap(arch: RiscvArch) -> String {
471471
arch.trap_frame()
472472
.iter()
473473
.enumerate()
474-
.filter(|(_, &reg)| !reg.starts_with('_'))
474+
.filter(|(_, reg)| !reg.starts_with('_'))
475475
.map(|(i, reg)| format!("{load} {reg}, {i}*{width}(sp)"))
476476
.collect::<Vec<_>>()
477477
.join("\n ")
@@ -766,7 +766,7 @@ fn trap(
766766

767767
#start_trap
768768

769-
#[export_name = #export_name]
769+
#[unsafe(export_name = #export_name)]
770770
#f
771771
)
772772
.into()

riscv-rt/src/exceptions.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
use crate::TrapFrame;
1515

16-
extern "C" {
16+
unsafe extern "C" {
1717
fn InstructionMisaligned(trap_frame: &TrapFrame);
1818
fn InstructionFault(trap_frame: &TrapFrame);
1919
fn IllegalInstruction(trap_frame: &TrapFrame);
@@ -31,7 +31,7 @@ extern "C" {
3131
}
3232

3333
/// Array with all the exception handlers sorted according to their exception source code.
34-
#[no_mangle]
34+
#[unsafe(no_mangle)]
3535
pub static __EXCEPTIONS: [Option<unsafe extern "C" fn(&TrapFrame)>; 16] = [
3636
Some(InstructionMisaligned),
3737
Some(InstructionFault),
@@ -57,13 +57,13 @@ pub static __EXCEPTIONS: [Option<unsafe extern "C" fn(&TrapFrame)>; 16] = [
5757
///
5858
/// This function must be called only from the [`crate::start_trap_rust`] function.
5959
/// Do **NOT** call this function directly.
60-
#[no_mangle]
60+
#[unsafe(no_mangle)]
6161
pub unsafe extern "C" fn _dispatch_exception(trap_frame: &TrapFrame, code: usize) {
62-
extern "C" {
63-
fn ExceptionHandler(trap_frame: &TrapFrame);
62+
unsafe extern "C" {
63+
unsafe fn ExceptionHandler(trap_frame: &TrapFrame);
6464
}
6565
match __EXCEPTIONS.get(code) {
66-
Some(Some(handler)) => handler(trap_frame),
67-
_ => ExceptionHandler(trap_frame),
66+
Some(Some(handler)) => unsafe { handler(trap_frame) },
67+
_ => unsafe { ExceptionHandler(trap_frame) },
6868
}
6969
}

riscv-rt/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ pub use riscv_rt_macros::pre_init;
595595
/// two copies of riscv-rt together, linking will fail. We also declare a links key in
596596
/// Cargo.toml which is the more modern way to solve the same problem, but we have to keep
597597
/// __ONCE__ around to prevent linking with versions before the links key was added.
598-
#[export_name = "error: riscv-rt appears more than once in the dependency graph"]
598+
#[unsafe(export_name = "error: riscv-rt appears more than once in the dependency graph")]
599599
#[doc(hidden)]
600600
pub static __ONCE__: () = ();
601601

@@ -675,11 +675,11 @@ pub struct TrapFrame {
675675
/// Do **NOT** call this function directly.
676676
#[cfg_attr(
677677
any(target_arch = "riscv32", target_arch = "riscv64"),
678-
link_section = ".trap.rust"
678+
unsafe(link_section = ".trap.rust")
679679
)]
680-
#[export_name = "_start_trap_rust"]
680+
#[unsafe(export_name = "_start_trap_rust")]
681681
pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
682-
extern "C" {
682+
unsafe extern "C" {
683683
#[cfg(not(feature = "v-trap"))]
684684
fn _dispatch_core_interrupt(code: usize);
685685
#[cfg(feature = "v-trap")]
@@ -689,10 +689,10 @@ pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
689689

690690
match xcause::read().cause() {
691691
#[cfg(not(feature = "v-trap"))]
692-
xcause::Trap::Interrupt(code) => _dispatch_core_interrupt(code),
692+
xcause::Trap::Interrupt(code) => unsafe { _dispatch_core_interrupt(code) },
693693
#[cfg(feature = "v-trap")]
694-
xcause::Trap::Interrupt(_) => DefaultHandler(),
695-
xcause::Trap::Exception(code) => _dispatch_exception(&*trap_frame, code),
694+
xcause::Trap::Interrupt(_) => unsafe { DefaultHandler() },
695+
xcause::Trap::Exception(code) => unsafe { _dispatch_exception(&*trap_frame, code) },
696696
}
697697
}
698698

@@ -701,7 +701,7 @@ pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
701701
/// The returned pointer is guaranteed to be 4-byte aligned.
702702
#[inline]
703703
pub fn heap_start() -> *mut usize {
704-
extern "C" {
704+
unsafe extern "C" {
705705
static mut __sheap: usize;
706706
}
707707

0 commit comments

Comments
 (0)