From d608a988f531292616fca474ac651461b26746e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Wed, 15 Apr 2026 15:33:43 +0200 Subject: [PATCH] riscvrt: rename no-interrupts and no-exceptions to custom-interrupts and custom-exceptions --- .github/workflows/clippy.yaml | 4 ++-- .github/workflows/tests.yaml | 8 ++++---- riscv-rt/CHANGELOG.md | 2 ++ riscv-rt/Cargo.toml | 6 ++++-- riscv-rt/build.rs | 12 ++++++------ riscv-rt/exceptions.x | 4 ++-- riscv-rt/interrupts.x | 4 ++-- riscv-rt/src/exceptions.rs | 2 +- riscv-rt/src/interrupts.rs | 2 +- riscv-rt/src/lib.rs | 36 +++++++++++++++++++++++++++++------ tests-build/Cargo.toml | 4 ++-- tests-build/src/lib.rs | 8 ++++---- tests-trybuild/Cargo.toml | 2 +- 13 files changed, 61 insertions(+), 33 deletions(-) diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml index 7d55bcb4..4dd3f85c 100644 --- a/.github/workflows/clippy.yaml +++ b/.github/workflows/clippy.yaml @@ -29,8 +29,8 @@ jobs: - name: Run clippy (no features) run: cargo clippy --all --no-default-features -- -D warnings - name: Run clippy (all features) - # We exclude riscv-peripheral because it's not yet stable-compliant (added -A deprecated for pre_init macro) - run: cargo clippy --exclude riscv-peripheral --all --all-features -- -D warnings -A deprecated + # Added -A deprecated for pre_init macro and no-interrupts and no-exceptions features + run: cargo clippy --all --all-features -- -D warnings -A deprecated # Additonal clippy checks for riscv-rt clippy-riscv-rt: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 05b3b03f..53d29133 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -54,13 +54,13 @@ jobs: run: RUSTFLAGS="-C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features device,memory - name: Build (custom interrupts and exceptions) - run: RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tmemory.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features no-interrupts,no-exceptions + run: RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tmemory.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features custom-interrupts,custom-exceptions - name: Build (custom interrupts and exceptions, include device.x) - run: RUSTFLAGS="-C link-arg=-Tmemory.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features no-interrupts,no-exceptions,device + run: RUSTFLAGS="-C link-arg=-Tmemory.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features custom-interrupts,custom-exceptions,device - name: Build (custom interrupts and exceptions, include memory.x) - run: RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features no-interrupts,no-exceptions,memory + run: RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features custom-interrupts,custom-exceptions,memory - name: Build (custom interrupts and exceptions, include device.x and memory.x) - run: RUSTFLAGS="-C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features no-interrupts,no-exceptions,device,memory + run: RUSTFLAGS="-C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features custom-interrupts,custom-exceptions,device,memory # Job to check that all the builds succeeded tests-check: diff --git a/riscv-rt/CHANGELOG.md b/riscv-rt/CHANGELOG.md index c0a75560..5c1eb871 100644 --- a/riscv-rt/CHANGELOG.md +++ b/riscv-rt/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Deprecate `no-interrupts` feature in favor of `custom-interrupts` +- Deprecate `no-exceptions` feature in favor of `custom-exceptions` - `_setup_interrupts` can now optionally receive an `usize` input argument with the ID of the running hart. This allows users to implement hart-specific interrupt setup in multi-hart targets. diff --git a/riscv-rt/Cargo.toml b/riscv-rt/Cargo.toml index ca8e0d86..c2f89fb2 100644 --- a/riscv-rt/Cargo.toml +++ b/riscv-rt/Cargo.toml @@ -39,12 +39,14 @@ riscv = { path = "../riscv", version = "0.16.0", features = ["critical-section-s pre-init = [] post-init = [] custom-setup-interrupts = [] +custom-interrupts = [] +custom-exceptions = [] s-mode = ["riscv-macros/s-mode"] single-hart = [] v-trap = ["riscv/rt-v-trap", "riscv-macros/rt-v-trap"] u-boot = ["riscv-macros/rvrt-u-boot", "single-hart"] -no-interrupts = [] -no-exceptions = [] +no-interrupts = ["custom-interrupts"] # deprecated, use `custom-interrupts` instead +no-exceptions = ["custom-exceptions"] # deprecated, use `custom-exceptions` instead no-mhartid = ["single-hart"] no-xie-xip = [] no-xtvec = [] diff --git a/riscv-rt/build.rs b/riscv-rt/build.rs index cfe4a239..84b90967 100644 --- a/riscv-rt/build.rs +++ b/riscv-rt/build.rs @@ -14,13 +14,13 @@ fn add_linker_script(arch_width: u32) -> io::Result<()> { // Get target-dependent linker configuration and replace ${INCLUDE_LINKER_FILES} with it let mut include_content = String::new(); - // If no-exceptions is disabled, include the exceptions.x files - if env::var_os("CARGO_FEATURE_NO_EXCEPTIONS").is_none() { + // If custom-exceptions is disabled, include the exceptions.x files + if env::var_os("CARGO_FEATURE_CUSTOM_EXCEPTIONS").is_none() { let exceptions_content = fs::read_to_string("exceptions.x")?; include_content.push_str(&(exceptions_content + "\n")); } - // If no-interrupts is disabled, include the interrupts.x files - if env::var_os("CARGO_FEATURE_NO_INTERRUPTS").is_none() { + // If custom-interrupts is disabled, include the interrupts.x files + if env::var_os("CARGO_FEATURE_CUSTOM_INTERRUPTS").is_none() { let interrupts_content = fs::read_to_string("interrupts.x")?; include_content.push_str(&(interrupts_content + "\n")); } @@ -74,10 +74,10 @@ fn main() { println!("cargo:rerun-if-env-changed=RISCV_RT_BASE_ISA"); println!("cargo:rerun-if-env-changed=RISCV_RT_LLVM_ARCH_PATCH"); if env::var_os("CARGO_FEATURE_V_TRAP").is_some() - && env::var_os("CARGO_FEATURE_NO_INTERRUPTS").is_none() + && env::var_os("CARGO_FEATURE_CUSTOM_INTERRUPTS").is_none() { // This environment variable is used by the `#[riscv::pac_enum()]` call in - // `src/interrupts.rs` (when `v-trap` is enabled and `no-interrupts` disabled). + // `src/interrupts.rs` (when `v-trap` is enabled and `custom-interrupts` disabled). println!("cargo:rerun-if-env-changed=RISCV_MTVEC_ALIGN"); } diff --git a/riscv-rt/exceptions.x b/riscv-rt/exceptions.x index e9d3f8fb..685db229 100644 --- a/riscv-rt/exceptions.x +++ b/riscv-rt/exceptions.x @@ -1,7 +1,7 @@ /* # EXCEPTION HANDLERS DESCRIBED IN THE STANDARD RISC-V ISA - If the `no-exceptions` feature is DISABLED, this file will be included in link.x.in. - If the `no-exceptions` feature is ENABLED, this file will be ignored. + If the `custom-exceptions` feature is DISABLED, this file will be included in link.x.in. + If the `custom-exceptions` feature is ENABLED, this file will be ignored. */ /* It is possible to define a special handler for each exception type. diff --git a/riscv-rt/interrupts.x b/riscv-rt/interrupts.x index 2440be77..d7299e82 100644 --- a/riscv-rt/interrupts.x +++ b/riscv-rt/interrupts.x @@ -1,7 +1,7 @@ /* # CORE INTERRUPT HANDLERS DESCRIBED IN THE STANDARD RISC-V ISA - If the `no-interrupts` feature is DISABLED, this file will be included in link.x.in. - If the `no-interrupts` feature is ENABLED, this file will be ignored. + If the `custom-interrupts` feature is DISABLED, this file will be included in link.x.in. + If the `custom-interrupts` feature is ENABLED, this file will be ignored. */ /* It is possible to define a special handler for each interrupt type. diff --git a/riscv-rt/src/exceptions.rs b/riscv-rt/src/exceptions.rs index e499db81..4433dded 100644 --- a/riscv-rt/src/exceptions.rs +++ b/riscv-rt/src/exceptions.rs @@ -9,7 +9,7 @@ //! //! If your target has custom exception sources, the target PAC might provide equivalent //! code to adapt for the target needs. In this case, you may need to opt out this module. -//! To do so, activate the `no-exceptions` feature of the `riscv-rt` crate. +//! To do so, activate the `custom-exceptions` feature of the `riscv-rt` crate. use crate::TrapFrame; diff --git a/riscv-rt/src/interrupts.rs b/riscv-rt/src/interrupts.rs index 71b77014..a11ff2c7 100644 --- a/riscv-rt/src/interrupts.rs +++ b/riscv-rt/src/interrupts.rs @@ -14,7 +14,7 @@ //! //! If your target has custom core interrupt sources, the target PAC might provide equivalent code //! to adapt for the target needs (and is responsible for any alignment constraint). In this case, -//! you may need to opt out this module. To do so, activate the `no-interrupts` feature of the +//! you may need to opt out this module. To do so, activate the `custom-interrupts` feature of the //! `riscv-rt` crate. #[riscv::pac_enum(unsafe CoreInterruptNumber)] diff --git a/riscv-rt/src/lib.rs b/riscv-rt/src/lib.rs index fb8460f0..5d0c907e 100644 --- a/riscv-rt/src/lib.rs +++ b/riscv-rt/src/lib.rs @@ -582,12 +582,12 @@ //! //! Skips disabling interrupts (to support chips without XIE/XIP CSRs). //! -//! ## `no-interrupts` +//! ## `custom-interrupts` //! //! Opts out of the default implementation for `_dispatch_core_interrupt` to support platforms //! with custom core interrupt sources. //! -//! ## `no-exceptions` +//! ## `custom-exceptions` //! //! Opts out of the default implementation for `_dispatch_exception` to support platforms //! with custom exception sources. @@ -683,13 +683,37 @@ #![no_std] #![deny(missing_docs)] +/// Backwards-compatibility deprecation warnings for renamed feature `no-interrupts`. +/// If a user enables the old feature, emit a warning pointing them to the new `custom-interrupts`. +#[cfg(feature = "no-interrupts")] +#[deprecated(note = "feature `no-interrupts` is deprecated; use `custom-interrupts` instead")] +pub const __RISCV_RT_DEPRECATED_NO_INTERRUPTS: () = (); + +#[cfg(feature = "no-interrupts")] +#[allow(clippy::let_unit_value)] +const _: () = { + let _ = __RISCV_RT_DEPRECATED_NO_INTERRUPTS; +}; + +/// Backwards-compatibility deprecation warnings for renamed feature `no-exceptions`. +/// If a user enables the old feature, emit a warning pointing them to the new `custom-exceptions`. +#[cfg(feature = "no-exceptions")] +#[deprecated(note = "feature `no-exceptions` is deprecated; use `custom-exceptions` instead")] +pub const __RISCV_RT_DEPRECATED_NO_EXCEPTIONS: () = (); + +#[cfg(feature = "no-exceptions")] +#[allow(clippy::let_unit_value)] +const _: () = { + let _ = __RISCV_RT_DEPRECATED_NO_EXCEPTIONS; +}; + #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] mod asm; -#[cfg(not(feature = "no-exceptions"))] +#[cfg(not(feature = "custom-exceptions"))] pub mod exceptions; -#[cfg(not(feature = "no-interrupts"))] +#[cfg(not(feature = "custom-interrupts"))] pub mod interrupts; #[cfg(feature = "s-mode")] @@ -838,13 +862,13 @@ pub struct TrapFrame { /// Targets that comply with the RISC-V standard can use the implementation provided /// by this crate in the [`exceptions`] module. Targets with special exception sources /// may provide their custom implementation of the `_dispatch_exception` function. You may -/// also need to enable the `no-exceptions` feature to op-out the default implementation. +/// also need to enable the `custom-exceptions` feature to op-out the default implementation. /// /// In direct mode (i.e., `v-trap` feature disabled), interrupt dispatching is performed /// by an extern `_dispatch_core_interrupt` function. Targets that comply with the RISC-V /// standard can use the implementation provided by this crate in the [`interrupts`] module. /// Targets with special interrupt sources may provide their custom implementation of the -/// `_dispatch_core_interrupt` function. You may also need to enable the `no-interrupts` +/// `_dispatch_core_interrupt` function. You may also need to enable the `custom-interrupts` /// feature to op-out the default implementation. /// /// In vectored mode (i.e., `v-trap` feature enabled), interrupt dispatching is performed diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml index 4798fa37..0a2e833f 100644 --- a/tests-build/Cargo.toml +++ b/tests-build/Cargo.toml @@ -14,5 +14,5 @@ single-hart = ["riscv-rt/single-hart"] v-trap = ["riscv-rt/v-trap"] device = ["riscv-rt/device"] memory = ["riscv-rt/memory"] -no-exceptions = ["riscv-rt/no-exceptions"] -no-interrupts = ["riscv-rt/no-interrupts"] +custom-exceptions = ["riscv-rt/custom-exceptions"] +custom-interrupts = ["riscv-rt/custom-interrupts"] diff --git a/tests-build/src/lib.rs b/tests-build/src/lib.rs index dc5c4c4b..592248b9 100644 --- a/tests-build/src/lib.rs +++ b/tests-build/src/lib.rs @@ -9,10 +9,10 @@ pub enum ExternalInterrupt { I2c = 2, } -#[cfg(not(feature = "no-interrupts"))] +#[cfg(not(feature = "custom-interrupts"))] pub use riscv::interrupt::Interrupt as CoreInterrupt; -#[cfg(feature = "no-interrupts")] +#[cfg(feature = "custom-interrupts")] #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[riscv::pac_enum(unsafe CoreInterruptNumber)] pub enum CoreInterrupt { @@ -21,10 +21,10 @@ pub enum CoreInterrupt { MachineExternal = 11, } -#[cfg(not(feature = "no-exceptions"))] +#[cfg(not(feature = "custom-exceptions"))] pub use riscv::interrupt::Exception; -#[cfg(feature = "no-exceptions")] +#[cfg(feature = "custom-exceptions")] #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[riscv::pac_enum(unsafe ExceptionNumber)] pub enum Exception { diff --git a/tests-trybuild/Cargo.toml b/tests-trybuild/Cargo.toml index 91969fe0..1e218cab 100644 --- a/tests-trybuild/Cargo.toml +++ b/tests-trybuild/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] riscv = { path = "../riscv" } riscv-macros = { path = "../riscv-macros" } -riscv-rt = { path = "../riscv-rt", features = ["no-exceptions", "no-interrupts", "post-init"] } +riscv-rt = { path = "../riscv-rt", features = ["custom-exceptions", "custom-interrupts", "post-init"] } trybuild = "1.0" [features]