Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- Remove the `allow-opt-level-z` feature from `esp32c3-hal` (#654)

## [0.10.0] - 2023-06-04

### Added
Expand Down
3 changes: 1 addition & 2 deletions esp32c3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedde
rt = []
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
allow-opt-level-z = []
async = ["esp-hal-common/async", "embedded-hal-async"]
embassy = ["esp-hal-common/embassy"]
embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-16_000_000"]
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]
interrupt-preemption = ["esp-hal-common/interrupt-preemption"]

[profile.dev]
Expand Down
42 changes: 1 addition & 41 deletions esp32c3-hal/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, fs::File, io::Write, path::PathBuf, process::exit};
use std::{env, fs::File, io::Write, path::PathBuf};

// Thanks to kennytm and TheDan64 for the assert_used_features macro.
// Source:
Expand All @@ -18,8 +18,6 @@ assert_unique_features! {"mcu-boot", "direct-boot"}

#[cfg(feature = "direct-boot")]
fn main() {
check_opt_level();

// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());

Expand Down Expand Up @@ -54,8 +52,6 @@ fn main() {

#[cfg(not(any(feature = "mcu-boot", feature = "direct-boot")))]
fn main() {
check_opt_level();

// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
Expand Down Expand Up @@ -84,8 +80,6 @@ fn main() {

#[cfg(feature = "mcu-boot")]
fn main() {
check_opt_level();

// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());

Expand Down Expand Up @@ -128,37 +122,3 @@ fn add_defaults() {

println!("cargo:rustc-link-search={}", out.display());
}

const OPT_LEVEL_Z_MSG: &str = r#"opt-level=z will produce broken 128-bit shifts (i.e. `1u128 << i`). The hal's interrupt handling relies on that operation, causing an 'attempt to subtract with overflow' panic if an enabled interrupt is triggered while using that opt-level.

Please use `opt-level="s"` in lieu of "z", or alternatively enable `features = ["allow-opt-level-z"]` to suppress this error. The latter option is only recommended if you:

* Do not use interrupts, and
* Do not have any shifts of 128-bit integers (either u128 or i128) in your code

See also: https://github.com/esp-rs/esp-hal/issues/196
and: https://github.com/llvm/llvm-project/issues/57988
"#;

// Once a rust nightly has a fix for https://github.com/llvm/llvm-project/issues/57988 , consider:
// 1. Removing this check in favor of bumping the minimum rust verison, and/or
// 2. Augmenting this check to ensure that version for opt-level=z
fn check_opt_level() {
if cfg!(feature = "allow-opt-level-z") {
return;
}

if let Some(ref opt_level) = env::var_os("OPT_LEVEL") {
if opt_level == "z" {
println!(
"{}",
OPT_LEVEL_Z_MSG
.lines()
.map(|l| format!("cargo:warning={l}"))
.collect::<Vec<String>>()
.join("\n")
);
exit(1);
}
}
}