Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unresolved import std::sync::atomic::AtomicUsize in no_std environment #526

Closed
mutantbob opened this issue Aug 19, 2022 · 7 comments
Closed

Comments

@mutantbob
Copy link

I am trying to port an app to an atmega2560 (avr architecture).

The embedded-svc crate uses log with this clause

[dependencies.log]
version = "0.4"
default-features = false

This should make the log crate no_std

lib.rs:321: #![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

However, I still get the following compile error:

error[E0432]: unresolved import `std::sync::atomic::AtomicUsize`
   --> /home/thoth/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.17/src/lib.rs:348:25
    |
348 | use std::sync::atomic::{AtomicUsize, Ordering};
    |                         ^^^^^^^^^^^ no `AtomicUsize` in `sync::atomic`

Shouldn't a no_std build avoid pulling things from std? Other crates use the atomic-polyfill crate in this situation. Maybe switching to core::sync would work, but I'm not sure which version of rust stabilized that.

@Thomasdezeeuw
Copy link
Collaborator

@mutantbob you might have to add the target to the build script:

log/build.rs

Lines 24 to 42 in 63d7747

fn target_has_atomic_cas(target: &str) -> bool {
match target {
"thumbv6m-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => false,
_ => true,
}
}
fn target_has_atomics(target: &str) -> bool {
match target {
"thumbv4t-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => false,
_ => true,
}
}

IIRC if it's added their it should build, build you'll only have access to log::set_logger_racy, which is not thread safe. But I assume that's not a problem for the atmega, or does it have threads?

@ryankurte
Copy link

i think there's an underlying issue here expecting TARGET to be a viable tuple when this could also be a json file for a more specific target.

it seems like the best way to solve this would be to attempt to ask rustc for the Target object (via rustc -Z unstable-options --print target-spec-json so RUST_TARGET_PATH etc. are considered), perhaps with a fallback to this manual approach in case of failure?

@KodrAus
Copy link
Contributor

KodrAus commented Aug 31, 2022

Ideally we'd use target_has_atomic_load_store for this, but it's still unstable. In the meantime, adding new platforms as they appear to that build script is something we're happy to do.

@ryankurte
Copy link

Ideally we'd use rust-lang/rust#94039 for this

ahh how nice that'll be! fyi there's similar logic in heapless that might serve as a point of reference for some missing options.

have y'all considered gating the atomics with a feature and inverting this logic so it is still possible to disable em if reqired?

introducing such would be breaking for anyone using --no-default-features though one could automatically -enable- cas based on a list of supported platforms rather than -disabling- on unsupported to mitigate this (and unrecognised platforms could still opt in).

@KodrAus
Copy link
Contributor

KodrAus commented Apr 13, 2023

I think we should be able to close this one once #552 lands, right?

@MarkGhebrial
Copy link

Yes, I've confirmed that #552 resolves this

@Thomasdezeeuw
Copy link
Collaborator

Closing as resolved based on #526 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants