probe-rs / embedded-test

A test harness and runner for embedded devices
67 stars 10 forks source link

Using `init-log` feature causes builds to fail on targets without atomics support. #45

Closed hdbhm closed 1 week ago

hdbhm commented 1 week ago

When trying to use embedded-test's init-log feature on targets that do not have native atomics support, e.g. esp32c3 (riscv32imc-unknown-none-elf), builds currently fail with an error message similar to the one below:

error[E0425]: cannot find function `set_logger` in crate `log`
    --> .../registry/src/index.crates.io-6f17d22bba15001f/rtt-log-0.3.0/src/lib.rs:44:14
     |
44   |         log::set_logger(&LOGGER).ok();
     |              ^^^^^^^^^^ not found in `log`
     |
note: found an item that was configured out
    --> .../registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1395:8
     |
1395 | pub fn set_logger(logger: &'static dyn Log) -> Result<(), SetLoggerError> {
     |        ^^^^^^^^^^
note: the item is gated behind the `ptr` feature
    --> .../registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1394:7
     |
1394 | #[cfg(target_has_atomic = "ptr")]
     |       ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0425]: cannot find function `set_max_level` in crate `log`
    --> .../registry/src/index.crates.io-6f17d22bba15001f/rtt-log-0.3.0/src/lib.rs:45:14
     |
45   |         log::set_max_level(LOGGER.level_filter);
     |              ^^^^^^^^^^^^^ help: a function with a similar name exists: `max_level`
     |
    ::: .../registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1313:1
     |
1313 | pub fn max_level() -> LevelFilter {
     | --------------------------------- similarly named function `max_level` defined here
     |
note: found an item that was configured out
    --> .../registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1268:8
     |
1268 | pub fn set_max_level(level: LevelFilter) {
     |        ^^^^^^^^^^^^^
note: the item is gated behind the `ptr` feature
    --> .../registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1267:7
     |
1267 | #[cfg(target_has_atomic = "ptr")]
     |       ^^^^^^^^^^^^^^^^^^^^^^^^^

This is actually caused by a bug in rtt-log versions up to v0.4.0 (see sourcebox/rtt-log-rs#2 for details). Since the issue was fixed in version v0.4.0, bumping the dependency version would allow using init-log on targets without atomics. I have already prepared a pull request for this.