mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 04:40:52 +00:00
Disallow log and defmt at the same time (#3675)
This commit is contained in:
parent
b21ae76176
commit
29ac33f2a0
@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- The `log` feature has been renamed to `log-04` (#3675)
|
||||||
|
- `defmt` and `log-04` can no longer be selected at the same time (#3675)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -18,11 +18,12 @@ bench = false
|
|||||||
test = true
|
test = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cfg-if = "1.0.0"
|
||||||
defmt = { version = "1.0.1", optional = true }
|
defmt = { version = "1.0.1", optional = true }
|
||||||
document-features = "0.2.11"
|
document-features = "0.2.11"
|
||||||
esp-config = { version = "0.4.0", path = "../esp-config" }
|
esp-config = { version = "0.4.0", path = "../esp-config" }
|
||||||
embedded-storage = "0.3.1"
|
embedded-storage = "0.3.1"
|
||||||
log = { version = "0.4.26", optional = true }
|
log-04 = { package = "log", version = "0.4.26", optional = true }
|
||||||
strum = { version = "0.27.1", default-features = false, features = ["derive"] }
|
strum = { version = "0.27.1", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
crc = { version = "3.0.0", optional = true }
|
crc = { version = "3.0.0", optional = true }
|
||||||
@ -38,8 +39,8 @@ default = ["validation"]
|
|||||||
## Enable MD5 validation of the partition table.
|
## Enable MD5 validation of the partition table.
|
||||||
validation = ["dep:md-5"]
|
validation = ["dep:md-5"]
|
||||||
|
|
||||||
## Enable support for the `log` crate
|
## Enable support for version 0.4 of the `log` crate
|
||||||
log = ["dep:log"]
|
log-04 = ["dep:log-04"]
|
||||||
|
|
||||||
## Enable support for `defmt`
|
## Enable support for `defmt`
|
||||||
defmt = ["dep:defmt"]
|
defmt = ["dep:defmt"]
|
||||||
|
@ -3,9 +3,25 @@ use std::env;
|
|||||||
use esp_config::generate_config_from_yaml_definition;
|
use esp_config::generate_config_from_yaml_definition;
|
||||||
use jiff::Timestamp;
|
use jiff::Timestamp;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! assert_unique_features {
|
||||||
|
($($feature:literal),+ $(,)?) => {
|
||||||
|
assert!(
|
||||||
|
(0 $(+ cfg!(feature = $feature) as usize)+ ) <= 1,
|
||||||
|
"Exactly zero or one of the following features must be enabled: {}",
|
||||||
|
[$($feature),+].join(", ")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo::rustc-check-cfg=cfg(embedded_test)");
|
println!("cargo::rustc-check-cfg=cfg(embedded_test)");
|
||||||
|
|
||||||
|
// Log and defmt are mutually exclusive features. The main technical reason is
|
||||||
|
// that allowing both would make the exact panicking behaviour a fragile
|
||||||
|
// implementation detail.
|
||||||
|
assert_unique_features!("log-04", "defmt");
|
||||||
|
|
||||||
let build_time = match env::var("SOURCE_DATE_EPOCH") {
|
let build_time = match env::var("SOURCE_DATE_EPOCH") {
|
||||||
Ok(val) => Timestamp::from_microsecond(val.parse::<i64>().unwrap()).unwrap(),
|
Ok(val) => Timestamp::from_microsecond(val.parse::<i64>().unwrap()).unwrap(),
|
||||||
Err(_) => Timestamp::now(),
|
Err(_) => Timestamp::now(),
|
||||||
|
@ -5,10 +5,13 @@
|
|||||||
macro_rules! assert {
|
macro_rules! assert {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::assert!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::assert!($($x)*);
|
||||||
::defmt::assert!($($x)*);
|
} else {
|
||||||
|
::core::assert!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -17,10 +20,13 @@ macro_rules! assert {
|
|||||||
macro_rules! assert_eq {
|
macro_rules! assert_eq {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::assert_eq!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::assert_eq!($($x)*);
|
||||||
::defmt::assert_eq!($($x)*);
|
} else {
|
||||||
|
::core::assert_eq!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -29,10 +35,13 @@ macro_rules! assert_eq {
|
|||||||
macro_rules! assert_ne {
|
macro_rules! assert_ne {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::assert_ne!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::assert_ne!($($x)*);
|
||||||
::defmt::assert_ne!($($x)*);
|
} else {
|
||||||
|
::core::assert_ne!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -41,10 +50,13 @@ macro_rules! assert_ne {
|
|||||||
macro_rules! debug_assert {
|
macro_rules! debug_assert {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::debug_assert!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::debug_assert!($($x)*);
|
||||||
::defmt::debug_assert!($($x)*);
|
} else {
|
||||||
|
::core::debug_assert!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -53,10 +65,13 @@ macro_rules! debug_assert {
|
|||||||
macro_rules! debug_assert_eq {
|
macro_rules! debug_assert_eq {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::debug_assert_eq!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::debug_assert_eq!($($x)*);
|
||||||
::defmt::debug_assert_eq!($($x)*);
|
} else {
|
||||||
|
::core::debug_assert_eq!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -65,10 +80,13 @@ macro_rules! debug_assert_eq {
|
|||||||
macro_rules! debug_assert_ne {
|
macro_rules! debug_assert_ne {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::debug_assert_ne!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::debug_assert_ne!($($x)*);
|
||||||
::defmt::debug_assert_ne!($($x)*);
|
} else {
|
||||||
|
::core::debug_assert_ne!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -77,10 +95,13 @@ macro_rules! debug_assert_ne {
|
|||||||
macro_rules! todo {
|
macro_rules! todo {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::todo!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::todo!($($x)*);
|
||||||
::defmt::todo!($($x)*);
|
} else {
|
||||||
|
::core::todo!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -89,10 +110,13 @@ macro_rules! todo {
|
|||||||
macro_rules! unreachable {
|
macro_rules! unreachable {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::unreachable!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::unreachable!($($x)*);
|
||||||
::defmt::unreachable!($($x)*);
|
} else {
|
||||||
|
::core::unreachable!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -101,10 +125,13 @@ macro_rules! unreachable {
|
|||||||
macro_rules! panic {
|
macro_rules! panic {
|
||||||
($($x:tt)*) => {
|
($($x:tt)*) => {
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "defmt"))]
|
cfg_if::cfg_if! {
|
||||||
::core::panic!($($x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::panic!($($x)*);
|
||||||
::defmt::panic!($($x)*);
|
} else {
|
||||||
|
::core::panic!($($x)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -113,12 +140,15 @@ macro_rules! panic {
|
|||||||
macro_rules! trace {
|
macro_rules! trace {
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
($s:literal $(, $x:expr)* $(,)?) => {
|
||||||
{
|
{
|
||||||
#[cfg(feature = "log")]
|
cfg_if::cfg_if! {
|
||||||
::log::trace!($s $(, $x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::trace!($s $(, $x)*);
|
||||||
::defmt::trace!($s $(, $x)*);
|
} else if #[cfg(feature = "log-04")] {
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
::log_04::trace!($s $(, $x)*);
|
||||||
let _ = ($( & $x ),*);
|
} else {
|
||||||
|
let _ = ($( & $x ),*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -127,12 +157,15 @@ macro_rules! trace {
|
|||||||
macro_rules! debug {
|
macro_rules! debug {
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
($s:literal $(, $x:expr)* $(,)?) => {
|
||||||
{
|
{
|
||||||
#[cfg(feature = "log")]
|
cfg_if::cfg_if! {
|
||||||
::log::debug!($s $(, $x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::debug!($s $(, $x)*);
|
||||||
::defmt::debug!($s $(, $x)*);
|
} else if #[cfg(feature = "log-04")] {
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
::log_04::debug!($s $(, $x)*);
|
||||||
let _ = ($( & $x ),*);
|
} else {
|
||||||
|
let _ = ($( & $x ),*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -141,12 +174,15 @@ macro_rules! debug {
|
|||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
($s:literal $(, $x:expr)* $(,)?) => {
|
||||||
{
|
{
|
||||||
#[cfg(feature = "log")]
|
cfg_if::cfg_if! {
|
||||||
::log::info!($s $(, $x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::info!($s $(, $x)*);
|
||||||
::defmt::info!($s $(, $x)*);
|
} else if #[cfg(feature = "log-04")] {
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
::log_04::info!($s $(, $x)*);
|
||||||
let _ = ($( & $x ),*);
|
} else {
|
||||||
|
let _ = ($( & $x ),*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -155,12 +191,15 @@ macro_rules! info {
|
|||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
($s:literal $(, $x:expr)* $(,)?) => {
|
||||||
{
|
{
|
||||||
#[cfg(feature = "log")]
|
cfg_if::cfg_if! {
|
||||||
::log::warn!($s $(, $x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::warn!($s $(, $x)*);
|
||||||
::defmt::warn!($s $(, $x)*);
|
} else if #[cfg(feature = "log-04")] {
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
::log_04::warn!($s $(, $x)*);
|
||||||
let _ = ($( & $x ),*);
|
} else {
|
||||||
|
let _ = ($( & $x ),*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -169,12 +208,15 @@ macro_rules! warn {
|
|||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
($s:literal $(, $x:expr)* $(,)?) => {
|
||||||
{
|
{
|
||||||
#[cfg(feature = "log")]
|
cfg_if::cfg_if! {
|
||||||
::log::error!($s $(, $x)*);
|
if #[cfg(feature = "defmt")] {
|
||||||
#[cfg(feature = "defmt")]
|
::defmt::error!($s $(, $x)*);
|
||||||
::defmt::error!($s $(, $x)*);
|
} else if #[cfg(feature = "log-04")] {
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
::log_04::error!($s $(, $x)*);
|
||||||
let _ = ($( & $x ),*);
|
} else {
|
||||||
|
let _ = ($( & $x ),*);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Removed `esp_wifi::deinit_unchecked` and `esp_wifi::EspWifiController::deinit` - you can just drop `EspWifiController` instead (#3553)
|
- Removed `esp_wifi::deinit_unchecked` and `esp_wifi::EspWifiController::deinit` - you can just drop `EspWifiController` instead (#3553)
|
||||||
|
- `defmt` and `log-04` can no longer be selected at the same time (#3675)
|
||||||
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -3,6 +3,17 @@ use std::error::Error;
|
|||||||
use esp_config::generate_config_from_yaml_definition;
|
use esp_config::generate_config_from_yaml_definition;
|
||||||
use esp_metadata::{Chip, Config};
|
use esp_metadata::{Chip, Config};
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! assert_unique_features {
|
||||||
|
($($feature:literal),+ $(,)?) => {
|
||||||
|
assert!(
|
||||||
|
(0 $(+ cfg!(feature = $feature) as usize)+ ) <= 1,
|
||||||
|
"Exactly zero or one of the following features must be enabled: {}",
|
||||||
|
[$($feature),+].join(", ")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
// Load the configuration file for the configured device:
|
// Load the configuration file for the configured device:
|
||||||
let chip = Chip::from_cargo_feature()?;
|
let chip = Chip::from_cargo_feature()?;
|
||||||
@ -11,6 +22,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// Define all necessary configuration symbols for the configured device:
|
// Define all necessary configuration symbols for the configured device:
|
||||||
config.define_symbols();
|
config.define_symbols();
|
||||||
|
|
||||||
|
// Log and defmt are mutually exclusive features. The main technical reason is
|
||||||
|
// that allowing both would make the exact panicking behaviour a fragile
|
||||||
|
// implementation detail.
|
||||||
|
assert_unique_features!("log-04", "defmt");
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!cfg!(feature = "ble") || config.contains("bt"),
|
!cfg!(feature = "ble") || config.contains("bt"),
|
||||||
r#"
|
r#"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user