Skip to content

unsafe no-mangle #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -83,17 +83,29 @@ jobs:
- { rust: stable, vendor: Spansion, options: "--atomics" }
- { rust: stable, vendor: STMicro, options: "" }
- { rust: stable, vendor: STMicro, options: "--atomics" }
- { rust: stable, vendor: STM32-patched, options: "--strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt" }
- {
rust: stable,
vendor: STM32-patched,
options: "--strict -f enum_value::p: --max-cluster-size --atomics --atomics-feature atomics --impl-debug --impl-defmt defmt",
}
- { rust: stable, vendor: Toshiba, options: all }
- { rust: stable, vendor: Toshiba, options: "" }
# Test MSRV
- { rust: 1.76.0, vendor: Nordic, options: "" }
- { rust: 1.82.0, vendor: Nordic, options: "" }
# Use nightly for architectures which don't support stable
- { rust: nightly, vendor: MSP430, options: "--atomics" }
- { rust: nightly, vendor: MSP430, options: "" }
# Workaround for _1token0
- { rust: nightly-2024-09-25, vendor: Espressif, options: "--atomics --ident-formats-theme legacy" }
- { rust: nightly-2024-09-25, vendor: Espressif, options: "--ident-format register:::Reg" }
- {
rust: nightly-2024-09-25,
vendor: Espressif,
options: "--atomics --ident-formats-theme legacy",
}
- {
rust: nightly-2024-09-25,
vendor: Espressif,
options: "--ident-format register:::Reg",
}

steps:
- uses: actions/checkout@v4
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

- Bump MSRV of generated code to 1.82

## [v0.35.0] - 2024-11-12

- Add `crate_path` setting
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -17,9 +17,9 @@ This project is developed and maintained by the [Tools team][team].

## Minimum Supported Rust Version (MSRV)

The **generated code** is guaranteed to compile on stable Rust 1.76.0 and up.
The **generated code** is guaranteed to compile on stable Rust 1.82.0 and up.

If you encounter compilation errors on any stable version newer than 1.76.0, please open an issue.
If you encounter compilation errors on any stable version newer than 1.82.0, please open an issue.

# Testing Locally

8 changes: 5 additions & 3 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },));
}
Peripheral::Array(p, dim_element) => {
for p_name in names(p, dim_element) {
@@ -288,7 +288,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(quote!(#feature_attribute #p_singleton: #p_ty::steal(),));
exprs.extend(
quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },),
);
}
}
}
@@ -298,7 +300,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
// crate as that would let you `take` the device peripherals more than once (one per minor
// version)
#[no_mangle]
#[unsafe(no_mangle)]
static mut DEVICE_PERIPHERALS: bool = false;

/// All the peripherals.
10 changes: 5 additions & 5 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __INTERRUPTS: [Vector; #n] = [
#elements
];
@@ -179,7 +179,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
#[used]
pub static __INTERRUPTS:
[Vector; #n] = [
@@ -214,7 +214,7 @@ pub fn render(
#[cfg(feature = "rt")]
#[doc(hidden)]
#link_section_attr
#[no_mangle]
#[unsafe(no_mangle)]
pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [
#elements
];
@@ -414,7 +414,7 @@ pub fn render(
}

#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;
@@ -433,7 +433,7 @@ pub fn render(
};
($NAME:ident, $path:path) => {
#[allow(non_snake_case)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern #abi fn $NAME() {
// check that the handler exists
let _ = $crate::interrupt::Interrupt::$NAME;