Skip to content

Commit

Permalink
Update to Rust 1.80, make check-cfg unconditional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jul 25, 2024
1 parent 8b4bb62 commit 2d678d6
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 111 deletions.
6 changes: 0 additions & 6 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ if ! command -v cargo-batch &> /dev/null; then
exit 1
fi

# check-cfg is stable on rustc 1.79 but not cargo 1.79.
# however, our cargo-batch is currently based on cargo 1.80, which does support check-cfg.
# so, force build.rs scripts to emit check-cfg commands.
# when 1.80 hits stable we can make build.rs unconditionally emit check-cfg and remove all this.
export EMBASSY_FORCE_CHECK_CFG=1

export RUSTFLAGS=-Dwarnings
export DEFMT_LOG=trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,cyw43=info,cyw43_pio=info,smoltcp=info
if [[ -z "${CARGO_TARGET_DIR}" ]]; then
Expand Down
21 changes: 1 addition & 20 deletions embassy-executor/build_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@

use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::process::Command;

/// Helper for emitting cargo instruction for enabling configs (`cargo:rustc-cfg=X`) and declaring
/// them (`cargo:rust-check-cfg=cfg(X)`).
#[derive(Debug)]
pub struct CfgSet {
enabled: HashSet<String>,
declared: HashSet<String>,
emit_declared: bool,
}

impl CfgSet {
pub fn new() -> Self {
Self {
enabled: HashSet::new(),
declared: HashSet::new(),
emit_declared: is_rustc_nightly(),
}
}

Expand All @@ -49,7 +45,7 @@ impl CfgSet {
///
/// This enables rustc to check that the configs in `#[cfg(...)]` attributes are valid.
pub fn declare(&mut self, cfg: impl AsRef<str>) {
if self.declared.insert(cfg.as_ref().to_owned()) && self.emit_declared {
if self.declared.insert(cfg.as_ref().to_owned()) {
println!("cargo:rustc-check-cfg=cfg({})", cfg.as_ref());
}
}
Expand All @@ -69,21 +65,6 @@ impl CfgSet {
}
}

fn is_rustc_nightly() -> bool {
if env::var_os("EMBASSY_FORCE_CHECK_CFG").is_some() {
return true;
}

let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));

let output = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`");

String::from_utf8_lossy(&output.stdout).contains("nightly")
}

/// Sets configs that describe the target platform.
pub fn set_target_cfgs(cfgs: &mut CfgSet) {
let target = env::var("TARGET").unwrap();
Expand Down
21 changes: 1 addition & 20 deletions embassy-hal-internal/build_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@

use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::process::Command;

/// Helper for emitting cargo instruction for enabling configs (`cargo:rustc-cfg=X`) and declaring
/// them (`cargo:rust-check-cfg=cfg(X)`).
#[derive(Debug)]
pub struct CfgSet {
enabled: HashSet<String>,
declared: HashSet<String>,
emit_declared: bool,
}

impl CfgSet {
pub fn new() -> Self {
Self {
enabled: HashSet::new(),
declared: HashSet::new(),
emit_declared: is_rustc_nightly(),
}
}

Expand All @@ -49,7 +45,7 @@ impl CfgSet {
///
/// This enables rustc to check that the configs in `#[cfg(...)]` attributes are valid.
pub fn declare(&mut self, cfg: impl AsRef<str>) {
if self.declared.insert(cfg.as_ref().to_owned()) && self.emit_declared {
if self.declared.insert(cfg.as_ref().to_owned()) {
println!("cargo:rustc-check-cfg=cfg({})", cfg.as_ref());
}
}
Expand All @@ -69,21 +65,6 @@ impl CfgSet {
}
}

fn is_rustc_nightly() -> bool {
if env::var_os("EMBASSY_FORCE_CHECK_CFG").is_some() {
return true;
}

let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));

let output = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`");

String::from_utf8_lossy(&output.stdout).contains("nightly")
}

/// Sets configs that describe the target platform.
pub fn set_target_cfgs(cfgs: &mut CfgSet) {
let target = env::var("TARGET").unwrap();
Expand Down
18 changes: 6 additions & 12 deletions embassy-rp/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ impl<'d, T: Instance> I2c<'d, T, Async> {
}
}

/// Read from address into buffer using DMA.
/// Read from address into buffer asynchronously.
pub async fn read_async(&mut self, addr: impl Into<u16>, buffer: &mut [u8]) -> Result<(), Error> {
Self::setup(addr.into())?;
self.read_async_internal(buffer, true, true).await
}

/// Write to address from buffer using DMA.
/// Write to address from buffer asynchronously.
pub async fn write_async(
&mut self,
addr: impl Into<u16>,
Expand All @@ -328,7 +328,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> {
self.write_async_internal(bytes, true).await
}

/// Write to address from bytes and read from address into buffer using DMA.
/// Write to address from bytes and read from address into buffer asynchronously.
pub async fn write_read_async(
&mut self,
addr: impl Into<u16>,
Expand Down Expand Up @@ -779,9 +779,6 @@ pub fn i2c_reserved_addr(addr: u16) -> bool {
}

pub(crate) trait SealedInstance {
const TX_DREQ: u8;
const RX_DREQ: u8;

fn regs() -> crate::pac::i2c::I2c;
fn reset() -> crate::pac::resets::regs::Peripherals;
fn waker() -> &'static AtomicWaker;
Expand Down Expand Up @@ -816,11 +813,8 @@ pub trait Instance: SealedInstance {
}

macro_rules! impl_instance {
($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => {
($type:ident, $irq:ident, $reset:ident) => {
impl SealedInstance for peripherals::$type {
const TX_DREQ: u8 = $tx_dreq;
const RX_DREQ: u8 = $rx_dreq;

#[inline]
fn regs() -> pac::i2c::I2c {
pac::$type
Expand All @@ -846,8 +840,8 @@ macro_rules! impl_instance {
};
}

impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33);
impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35);
impl_instance!(I2C0, I2C0_IRQ, set_i2c0);
impl_instance!(I2C1, I2C1_IRQ, set_i2c1);

/// SDA pin.
pub trait SdaPin<T: Instance>: crate::gpio::Pin {}
Expand Down
21 changes: 1 addition & 20 deletions embassy-stm32/build_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@

use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::process::Command;

/// Helper for emitting cargo instruction for enabling configs (`cargo:rustc-cfg=X`) and declaring
/// them (`cargo:rust-check-cfg=cfg(X)`).
#[derive(Debug)]
pub struct CfgSet {
enabled: HashSet<String>,
declared: HashSet<String>,
emit_declared: bool,
}

impl CfgSet {
pub fn new() -> Self {
Self {
enabled: HashSet::new(),
declared: HashSet::new(),
emit_declared: is_rustc_nightly(),
}
}

Expand All @@ -49,7 +45,7 @@ impl CfgSet {
///
/// This enables rustc to check that the configs in `#[cfg(...)]` attributes are valid.
pub fn declare(&mut self, cfg: impl AsRef<str>) {
if self.declared.insert(cfg.as_ref().to_owned()) && self.emit_declared {
if self.declared.insert(cfg.as_ref().to_owned()) {
println!("cargo:rustc-check-cfg=cfg({})", cfg.as_ref());
}
}
Expand All @@ -69,21 +65,6 @@ impl CfgSet {
}
}

fn is_rustc_nightly() -> bool {
if env::var_os("EMBASSY_FORCE_CHECK_CFG").is_some() {
return true;
}

let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));

let output = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`");

String::from_utf8_lossy(&output.stdout).contains("nightly")
}

/// Sets configs that describe the target platform.
pub fn set_target_cfgs(cfgs: &mut CfgSet) {
let target = env::var("TARGET").unwrap();
Expand Down
1 change: 1 addition & 0 deletions embassy-stm32/src/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![macro_use]
#![allow(missing_docs)] // TODO
#![cfg_attr(adc_f3_v2, allow(unused))]

#[cfg(not(adc_f3_v2))]
#[cfg_attr(adc_f1, path = "f1.rs")]
Expand Down
2 changes: 2 additions & 0 deletions embassy-stm32/src/opamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct OpAmpOutput<'d, T: Instance> {
/// OpAmp internal outputs, wired directly to ADC inputs.
///
/// This struct can be used as an ADC input.
#[cfg(opamp_g4)]
pub struct OpAmpInternalOutput<'d, T: Instance> {
_inner: &'d OpAmp<'d, T>,
}
Expand Down Expand Up @@ -184,6 +185,7 @@ impl<'d, T: Instance> Drop for OpAmpOutput<'d, T> {
}
}

#[cfg(opamp_g4)]
impl<'d, T: Instance> Drop for OpAmpInternalOutput<'d, T> {
fn drop(&mut self) {
T::regs().csr().modify(|w| {
Expand Down
17 changes: 5 additions & 12 deletions embassy-stm32/src/ospi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,6 @@ pub(crate) trait SealedInstance {
const REGS: Regs;
}

trait SealedWord {
const CONFIG: u8;
}

/// OSPI instance trait.
#[allow(private_bounds)]
pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {}
Expand Down Expand Up @@ -1110,17 +1106,14 @@ impl<'d, T: Instance, M: PeriMode> GetConfig for Ospi<'d, T, M> {

/// Word sizes usable for OSPI.
#[allow(private_bounds)]
pub trait Word: word::Word + SealedWord {}
pub trait Word: word::Word {}

macro_rules! impl_word {
($T:ty, $config:expr) => {
impl SealedWord for $T {
const CONFIG: u8 = $config;
}
($T:ty) => {
impl Word for $T {}
};
}

impl_word!(u8, 8);
impl_word!(u16, 16);
impl_word!(u32, 32);
impl_word!(u8);
impl_word!(u16);
impl_word!(u32);
1 change: 1 addition & 0 deletions embassy-stm32/src/spi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ pub(crate) struct Info {
struct State {}

impl State {
#[allow(unused)]
const fn new() -> Self {
Self {}
}
Expand Down
21 changes: 1 addition & 20 deletions embassy-sync/build_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@

use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::process::Command;

/// Helper for emitting cargo instruction for enabling configs (`cargo:rustc-cfg=X`) and declaring
/// them (`cargo:rust-check-cfg=cfg(X)`).
#[derive(Debug)]
pub struct CfgSet {
enabled: HashSet<String>,
declared: HashSet<String>,
emit_declared: bool,
}

impl CfgSet {
pub fn new() -> Self {
Self {
enabled: HashSet::new(),
declared: HashSet::new(),
emit_declared: is_rustc_nightly(),
}
}

Expand All @@ -49,7 +45,7 @@ impl CfgSet {
///
/// This enables rustc to check that the configs in `#[cfg(...)]` attributes are valid.
pub fn declare(&mut self, cfg: impl AsRef<str>) {
if self.declared.insert(cfg.as_ref().to_owned()) && self.emit_declared {
if self.declared.insert(cfg.as_ref().to_owned()) {
println!("cargo:rustc-check-cfg=cfg({})", cfg.as_ref());
}
}
Expand All @@ -69,21 +65,6 @@ impl CfgSet {
}
}

fn is_rustc_nightly() -> bool {
if env::var_os("EMBASSY_FORCE_CHECK_CFG").is_some() {
return true;
}

let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));

let output = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`");

String::from_utf8_lossy(&output.stdout).contains("nightly")
}

/// Sets configs that describe the target platform.
pub fn set_target_cfgs(cfgs: &mut CfgSet) {
let target = env::var("TARGET").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions embassy-usb/src/msos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ pub enum DescriptorType {

/// Table 5. Descriptor set information structure.
#[allow(non_snake_case)]
#[allow(unused)]
#[repr(C, packed(1))]
pub struct DescriptorSetInformation {
dwWindowsVersion: u32,
Expand All @@ -288,6 +289,7 @@ pub struct DescriptorSetInformation {

/// Table 4. Microsoft OS 2.0 platform capability descriptor header.
#[allow(non_snake_case)]
#[allow(unused)]
#[repr(C, packed(1))]
pub struct PlatformDescriptor {
bLength: u8,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.79"
channel = "1.80"
components = [ "rust-src", "rustfmt", "llvm-tools" ]
targets = [
"thumbv7em-none-eabi",
Expand Down

0 comments on commit 2d678d6

Please sign in to comment.