tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.19k stars 677 forks source link

Compile error on Raspberry Pi Pico (target = thumbv6m-none-eabi) #2909

Open ValouBambou opened 4 months ago

ValouBambou commented 4 months ago

Bug Report

When compiling the library in a no_std environment for a rp2040 I got the following errors:

error[E0599]: no method named `swap` found for struct `AtomicUsize` in the current scope
   --> /home/val/Coding/tracing/tracing-core/src/metadata.rs:747:19
    |
747 |         MAX_LEVEL.swap(val, Ordering::AcqRel);
    |                   ^^^^ method not found in `AtomicUsize`

error[E0599]: no method named `compare_exchange` found for struct `AtomicUsize` in the current scope
  --> /home/val/Coding/tracing/tracing-core/src/spin/once.rs:77:39
   |
77 |             status = match self.state.compare_exchange(
   |                            -----------^^^^^^^^^^^^^^^^ method not found in `AtomicUsize`

error[E0599]: no method named `compare_exchange` found for struct `AtomicPtr` in the current scope
   --> /home/val/Coding/tracing/tracing-core/src/callsite.rs:446:29
    |
446 |             match self.head.compare_exchange(
    |                   ----------^^^^^^^^^^^^^^^^ method not found in `AtomicPtr<Registration>`

error[E0599]: no method named `compare_exchange` found for struct `AtomicUsize` in the current scope
   --> /home/val/Coding/tracing/tracing-core/src/dispatch.rs:335:10
    |
334 |       if GLOBAL_INIT
    |  ________-
335 | |         .compare_exchange(
    | |         -^^^^^^^^^^^^^^^^ method not found in `AtomicUsize`
    | |_________|
    |

Version

cargo tree output with my local clone of the master branch:

tracing v0.2.0 (/home/val/Coding/tracing/tracing)
    ├── pin-project-lite v0.2.13
    ├── tracing-attributes v0.2.0 (proc-macro) (/home/val/Coding/tracing/tracing-attributes)
    │   ├── proc-macro2 v1.0.78 (*)
    │   ├── quote v1.0.35 (*)
    │   └── syn v2.0.52 (*)
    └── tracing-core v0.2.0 (/home/val/Coding/tracing/tracing-core)

Platform

The target is a microcontroller: the Raspberry Pi Pico (target = thumbv6m-none-eabi).

Description

The issue is that the core crate doesn't define swap and compare_exchange for this target. This happens because of the conditional compilation flag #[cfg(target_has_atomic = "8")] in core which failed cause the rp2040 doesn't support such atomic operations.