The Crate Does not Compile when the `defmt-03` Feature is Enabled

Open
#610 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
embedded-iot

Research direction

Reproduce the failure with cargo build --features defmt-03, then inspect the defmt::Format uses in embedded-hal/src/i2c.rs and embedded-hal/src/spi.rs. Review the proposed branch and PR #481 for the feature-resolution context; done means both embedded-hal and embedded-io compile with defmt-03 enabled.

Written by the indexing model from the issue text.

Description

Problem

Currently (on master commit 1c585d4), the crate embedded-hal and embedded-io does not compile when enabling the defmt-03 feature. The following command is run :

[./embedded-hal] $ cargo build --features defmt-03;

And these errors are returned :

Errors
error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/i2c.rs:192:41
    |
192 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate through its public re-export
    |
164 + use crate::defmt;
    |

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/i2c.rs:192:41
    |
192 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/i2c.rs:304:41
    |
304 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate through its public re-export
    |
164 + use crate::defmt;
    |

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/i2c.rs:304:41
    |
304 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/spi.rs:201:41
    |
201 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate through its public re-export
    |
174 + use crate::defmt;
    |

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/spi.rs:201:41
    |
201 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/spi.rs:319:41
    |
319 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate through its public re-export
    |
174 + use crate::defmt;
    |

error[E0433]: failed to resolve: could not find `defmt` in the list of imported crates
   --> embedded-hal/src/spi.rs:319:41
    |
319 | #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
    |                                         ^^^^^^^^^^^^^ could not find `defmt` in the list of imported crates
    |
    = note: this error originates in the derive macro `defmt::Format` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0433`.
error: could not compile `embedded-hal` (lib) due to 8 previous errors

This is run by the following Rust version :

cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Arch Linux [64-bit]

Solution

I forked the repository and pushed a branch that successfully compiles embedded-hal and embedded-io in a standalone fashion. It is confirmed to work for our needs.

However, I know this could conflict with a previous discussion on PR https://github.com/rust-embedded/embedded-hal/pull/481.

What is happening in this case ?

Thanks for your help.

Dominant language
Rust
Stars
2.7k
Forks
282
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-embedded/embedded-hal

All issues in rust-embedded/embedded-hal

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.