Skip to content

Commit 6e4e73b

Browse files
committed
Use feature() on nightly toolchains only.
`feature()` is only allowed on Nightly, it's completely disallowed on stable and beta even for already-stabilized features. So, we autodetect whether the user is using nightly and conditionally use `feature()`. This allows the crates to Just Work on current 1.75 beta and will also Just Work when 1.75 stable is out. Keeping `feature()` is desirable to keep support for: - Espressif's xtensa rustc fork. (they build from the stable branch but enable use of `feature()`, so latest xtensa rustc still requires `feature()`) - Users of older nightlies Once xtensa rust 1.75 is out, we can remove this (upstream nightlies that require `feature()` will be quite old by then, so dropping support for them should be OK). I decided to not use already-made crates like `rustversion` to do this because they're quite big and do way more than what we need, so I felt badd adding another dep. The code is inspired from `rustversion`'s build.rs.
1 parent e39a13d commit 6e4e73b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

embedded-nal-async/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::env;
2+
use std::ffi::OsString;
3+
use std::process::Command;
4+
5+
fn main() {
6+
println!("cargo:rerun-if-changed=build.rs");
7+
8+
let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));
9+
10+
let output = Command::new(rustc)
11+
.arg("--version")
12+
.output()
13+
.expect("failed to run `rustc --version`");
14+
15+
if String::from_utf8_lossy(&output.stdout).contains("nightly") {
16+
println!("cargo:rustc-cfg=nightly");
17+
}
18+
}

embedded-nal-async/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! # embedded-nal-async - An async Network Abstraction Layer for Embedded Systems
22
33
#![no_std]
4-
#![feature(async_fn_in_trait, impl_trait_projections)]
5-
#![allow(stable_features, unknown_lints, async_fn_in_trait)]
4+
#![cfg_attr(nightly, allow(stable_features, unknown_lints))]
5+
#![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))]
6+
#![allow(async_fn_in_trait)]
67
#![deny(missing_docs)]
78
#![deny(unsafe_code)]
89
#![cfg_attr(feature = "ip_in_core", feature(ip_in_core))]

0 commit comments

Comments
 (0)