Closed cs-clarence closed 2 weeks ago
@cs-clarence
The TL;DR is that if you wait a couple of weeks or a month (and update to latest Rust nightly and/or esp toolchain), the problem might likely resolve itself because of this and then you won't need the harness = false
workaround anymore.
Elaboration: The problem is very deep actually. Here's the context:
[cfg(test)]
enabled by defaultfn main()
STD entrypoint, which main
is containing code that (a) references all #[cfg(test)]
modules in your app and (b) executes all or one of your #[test]
functions#[cfg(test)]
thing is that cargo - behind the curtains - tries to compile the libNow, what can we do? Maybe a short-term solution and a log-term solution:
libc
and possibly in Rust STD enough "support" for multi-process execution so that at least the compilation of the test harness code does not fail. "support" is in quotes, because there is just no way for the resulting binary to do anything useful, as ESP-IDF is not multi-process. But we can at least "fake" the multi-process aspect of STD (as we already do a bit now) enough for the stuff to at least compile and not bother you. This is exactly what the change by @SergioGasquez from above does for which I suggested you wait a bitharness = false
is inescapable in that you still have to set it (and also set #[embedded_test::tests]
for the embedded-test
harness to actually kick in). There was some talk that the harness
parameter should be target-specific actually, and there are some open bugs in cargo
about that, but nobody is pushing on that front.@ivmarkov thanks for the in-depth reply to this. I don't really get the harness = false
workaround. The minimal reproduction is generated from the template esp-rs/esp-idf-template
which already has the harness = false
set. When the file is only main.rs
the program compiles fine, however once I create the lib.rs
it triggers the clippy error. Initially I thought that it might be my installation is broken but after seeing the github action here https://github.com/cs-clarence/esp-rs-min-repro/actions/runs/11762240597/job/32764909696 I'm convinced that the issue is not just because of my development setup.
@ivmarkov thanks for the in-depth reply to this. I don't really get the
harness = false
workaround. The minimal reproduction is generated from the templateesp-rs/esp-idf-template
which already has theharness = false
set. When the file is onlymain.rs
the program compiles fine, however once I create thelib.rs
it triggers the clippy error.
esp-idf-template
's harness = false
only applies the workaround for binary crates, as that's what esp-idf-template
generates. The moment you put a lib.rs
in your crate, you are in fact creating a mixed crate that is simultaneously a binary one and a library one. So you need to then also add to Cargo.toml
:
[lib]
harness = false
@ivmarkov thanks for the in-depth reply to this. I don't really get the
harness = false
workaround. The minimal reproduction is generated from the templateesp-rs/esp-idf-template
which already has theharness = false
set. When the file is onlymain.rs
the program compiles fine, however once I create thelib.rs
it triggers the clippy error.
esp-idf-template
'sharness = false
only applies the workaround for binary crates, as that's whatesp-idf-template
generates. The moment you put alib.rs
in your crate, you are in fact creating a mixed crate that is simultaneously a binary one and a library one. So you need to then also add toCargo.toml
:[lib] harness = false
Ah I see. I didn't know this one. That fixed it.
Thanks. I'll be closing this now
Reopening for https://github.com/esp-rs/rust/issues/231
Min repro: https://github.com/cs-clarence/esp-rs-min-repro
MCU: esp32s3 Rust Version: 1.82 Edition: 2021
Steps to reproduce:
cargo generate esp-rs/esp-idf-template cargo
lib.rs
in src folderfound a related PR for this https://github.com/esp-rs/rust/pull/232
cc @MabezDev