[WIP] add entry2 attribute
this adds an entry2 attribute in the vein of cortex_m_rt::entry. This attribute
lets you safely use `static mut` variables -- they get transformed into
`&'static mut` references. Example:
``` rust
#[entry2]
fn main() -> ! {
static mut COUNT: u32 = 0;
// user code
let count: &'static mut = COUNT;
}
```
I did something different in this version: instead of using random identifiers I
wrapped the user entry point into a `const` item to make it impossible to invoke
it from software (if that were allowed using the `static mut` would result in
UB).
Just for reference the above code expands into this:
``` rust
const main: () = {
#[no_mangle]
fn main() -> ! {
let COUNT: &'static mut u32 = {
static COUNT: u32 = 0;
&mut COUNT
};
// user code
let count: &'static mut = COUNT;
}
};
```
Not using random identifiers means that we avoid a (host) dependency on the rand
crate.
This change is a breaking change because it bumps the Minimum Supported Rust
Version (MSRV) to 1.31.0 -- this crate current MSRV is 1.30.0. The MSRV needs to
be bumped because `#[no_mangle]` / `#[link_section]` items inside private
items (like the `const` item above) only get the right symbol visibility in Rust
1.31.0 (the visibility rules around `#[no_mangle]` / `#[link_section]` got
changed in that version).
Instead of naming this attribute: `entry2`, we could replace the existing
`entry!` macro but that would be another breaking change.
parent
c7c64dd1
Please register or sign in to comment