Skip to content

Commit

Permalink
unsafe no-mangle
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 11, 2024
1 parent b6ef0b0 commit ed35243
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() },),
);
}
}
}
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down Expand Up @@ -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] = [
Expand Down Expand Up @@ -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
];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ed35243

Please sign in to comment.