From 8c3b49c426fab4d2f2da73b33963f485e1450d8c Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 May 2024 17:02:07 +0000 Subject: [PATCH 1/3] Add cargo:rustc-check-cfg instructions to build.rs See https://blog.rust-lang.org/2024/05/06/check-cfg.html#custom-cfgs-in-build-scripts --- cortex-m-rt/build.rs | 6 ++++++ cortex-m-semihosting/build.rs | 1 + cortex-m/build.rs | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/cortex-m-rt/build.rs b/cortex-m-rt/build.rs index 9334d166..2a1406cf 100644 --- a/cortex-m-rt/build.rs +++ b/cortex-m-rt/build.rs @@ -42,6 +42,12 @@ INCLUDE device.x"# f }; + println!("cargo:rustc-check-cfg=cfg(armv6m)"); + println!("cargo:rustc-check-cfg=cfg(armv7m)"); + println!("cargo:rustc-check-cfg=cfg(armv8m)"); + println!("cargo:rustc-check-cfg=cfg(cortex_m)"); + println!("cargo:rustc-check-cfg=cfg(has_fpu)"); + let max_int_handlers = if target.starts_with("thumbv6m-") { println!("cargo:rustc-cfg=cortex_m"); println!("cargo:rustc-cfg=armv6m"); diff --git a/cortex-m-semihosting/build.rs b/cortex-m-semihosting/build.rs index ed0d0697..6c897f63 100644 --- a/cortex-m-semihosting/build.rs +++ b/cortex-m-semihosting/build.rs @@ -3,6 +3,7 @@ use std::env; fn main() { let target = env::var("TARGET").unwrap(); + println!("cargo:rustc-check-cfg=cfg(thumb)"); if target.starts_with("thumbv") { println!("cargo:rustc-cfg=thumb"); } diff --git a/cortex-m/build.rs b/cortex-m/build.rs index f81072bd..cfcd394e 100644 --- a/cortex-m/build.rs +++ b/cortex-m/build.rs @@ -4,6 +4,16 @@ fn main() { let target = env::var("TARGET").unwrap(); let host_triple = env::var("HOST").unwrap(); + println!("cargo:rustc-check-cfg=cfg(armv6m)"); + println!("cargo:rustc-check-cfg=cfg(armv7em)"); + println!("cargo:rustc-check-cfg=cfg(armv7m)"); + println!("cargo:rustc-check-cfg=cfg(armv8m)"); + println!("cargo:rustc-check-cfg=cfg(armv8m_base)"); + println!("cargo:rustc-check-cfg=cfg(armv8m_main)"); + println!("cargo:rustc-check-cfg=cfg(cortex_m)"); + println!("cargo:rustc-check-cfg=cfg(has_fpu)"); + println!("cargo:rustc-check-cfg=cfg(native)"); + if host_triple == target { println!("cargo:rustc-cfg=native"); } From 769ece7345e1404fce9c9c2a54961a9fbdceeb48 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 May 2024 17:58:34 +0000 Subject: [PATCH 2/3] Rename .cargo/config to config.toml --- .cargo/{config => config.toml} | 0 cortex-m-rt/.cargo/{config => config.toml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .cargo/{config => config.toml} (100%) rename cortex-m-rt/.cargo/{config => config.toml} (100%) diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/cortex-m-rt/.cargo/config b/cortex-m-rt/.cargo/config.toml similarity index 100% rename from cortex-m-rt/.cargo/config rename to cortex-m-rt/.cargo/config.toml From 8ab3799e03995ddb4e969f7b38d3f82129941728 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 May 2024 20:04:52 +0000 Subject: [PATCH 3/3] Allow unexpected_cfgs in cfg-static Otherwise build fails on nightly due to the use of an undeclared cfg attribute --- cortex-m-rt/examples/cfg-static.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cortex-m-rt/examples/cfg-static.rs b/cortex-m-rt/examples/cfg-static.rs index 2ffee138..5585a32c 100644 --- a/cortex-m-rt/examples/cfg-static.rs +++ b/cortex-m-rt/examples/cfg-static.rs @@ -4,6 +4,8 @@ #![deny(warnings)] #![no_main] #![no_std] +// This example uses an undefined cfg, `cfg(never)` +#![allow(unexpected_cfgs)] extern crate cortex_m_rt as rt; extern crate panic_halt;