Skip to content

Commit ac55c03

Browse files
committed
Adapt riscv-rt to edition 2024
1 parent 26db589 commit ac55c03

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

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
@@ -136,7 +136,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
136136

137137
quote!(
138138
#[allow(non_snake_case)]
139-
#[export_name = "main"]
139+
#[unsafe(export_name = "main")]
140140
#(#attrs)*
141141
pub #unsafety fn __risc_v_rt__main(#args) -> ! {
142142
#(#stmts)*
@@ -248,7 +248,7 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
248248
let block = f.block;
249249

250250
quote!(
251-
#[export_name = "__pre_init"]
251+
#[unsafe(export_name = "__pre_init")]
252252
#(#attrs)*
253253
pub unsafe fn #ident() #block
254254
)
@@ -451,7 +451,7 @@ fn store_trap<T: FnMut(&str) -> bool>(arch: RiscvArch, mut filter: T) -> String
451451
arch.trap_frame()
452452
.iter()
453453
.enumerate()
454-
.filter(|(_, &reg)| !reg.starts_with('_') && filter(reg))
454+
.filter(|(_, reg)| !reg.starts_with('_') && filter(reg))
455455
.map(|(i, reg)| format!("{store} {reg}, {i}*{width}(sp)"))
456456
.collect::<Vec<_>>()
457457
.join("\n ")
@@ -465,7 +465,7 @@ fn load_trap(arch: RiscvArch) -> String {
465465
arch.trap_frame()
466466
.iter()
467467
.enumerate()
468-
.filter(|(_, &reg)| !reg.starts_with('_'))
468+
.filter(|(_, reg)| !reg.starts_with('_'))
469469
.map(|(i, reg)| format!("{load} {reg}, {i}*{width}(sp)"))
470470
.collect::<Vec<_>>()
471471
.join("\n ")
@@ -760,7 +760,7 @@ fn trap(
760760

761761
#start_trap
762762

763-
#[export_name = #export_name]
763+
#[unsafe(export_name = #export_name)]
764764
#f
765765
)
766766
.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
@@ -592,7 +592,7 @@ pub use riscv_rt_macros::pre_init;
592592
/// two copies of riscv-rt together, linking will fail. We also declare a links key in
593593
/// Cargo.toml which is the more modern way to solve the same problem, but we have to keep
594594
/// __ONCE__ around to prevent linking with versions before the links key was added.
595-
#[export_name = "error: riscv-rt appears more than once in the dependency graph"]
595+
#[unsafe(export_name = "error: riscv-rt appears more than once in the dependency graph")]
596596
#[doc(hidden)]
597597
pub static __ONCE__: () = ();
598598

@@ -672,11 +672,11 @@ pub struct TrapFrame {
672672
/// Do **NOT** call this function directly.
673673
#[cfg_attr(
674674
any(target_arch = "riscv32", target_arch = "riscv64"),
675-
link_section = ".trap.rust"
675+
unsafe(link_section = ".trap.rust")
676676
)]
677-
#[export_name = "_start_trap_rust"]
677+
#[unsafe(export_name = "_start_trap_rust")]
678678
pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
679-
extern "C" {
679+
unsafe extern "C" {
680680
#[cfg(not(feature = "v-trap"))]
681681
fn _dispatch_core_interrupt(code: usize);
682682
#[cfg(feature = "v-trap")]
@@ -686,10 +686,10 @@ pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
686686

687687
match xcause::read().cause() {
688688
#[cfg(not(feature = "v-trap"))]
689-
xcause::Trap::Interrupt(code) => _dispatch_core_interrupt(code),
689+
xcause::Trap::Interrupt(code) => unsafe { _dispatch_core_interrupt(code) },
690690
#[cfg(feature = "v-trap")]
691-
xcause::Trap::Interrupt(_) => DefaultHandler(),
692-
xcause::Trap::Exception(code) => _dispatch_exception(&*trap_frame, code),
691+
xcause::Trap::Interrupt(_) => unsafe { DefaultHandler() },
692+
xcause::Trap::Exception(code) => unsafe { _dispatch_exception(&*trap_frame, code) },
693693
}
694694
}
695695

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

0 commit comments

Comments
 (0)