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

Use atomic polyfill for core::sync::atomic. #1278

Closed
wants to merge 1 commit into from

Conversation

royb3
Copy link
Contributor

@royb3 royb3 commented Mar 14, 2023

Hi, I ran into an issue with building embassy for the riscv32i-unknown-none-elf target.

This target's core lib does not contain sync::atomic, or it's empty. The imports to atomic-polyfill fixes the issue, and has been done for other parts of Embassy too.

@Dirbaio
Copy link
Member

Dirbaio commented Mar 14, 2023

I'm sorry, but this is not the right fix for the problem. See previous discussion in #1240, #745 (comment), rust-lang/rust#99668

@Dirbaio Dirbaio closed this Mar 14, 2023
@royb3
Copy link
Contributor Author

royb3 commented Mar 14, 2023

Thanks for pointing me in that direction. For now we seems to have a workaround. Our Risc V implementation actually has the I A and M extensions, but the C extension is not implemented.

Copying these rustflags from https://github.com/esp-rs/riscv-atomic-emulation-trap, and building the core lib with -Zbuild-std=core seems to do the trick

[target.riscv32i-unknown-none-elf]
rustflags = [
  "-C", "link-arg=-Tmemory.x",
  "-C", "link-arg=-Tlink.x",
  "-C", "link-arg=-Tdefmt.x",
  "-C", "target-feature=+m",
  "-C", "target-feature=+a",
  # tell the core library have atomics even though it's not specified in the target definition
  "--cfg", "target_has_atomic_load_store",
  "--cfg", 'target_has_atomic_load_store="8"',
  "--cfg", 'target_has_atomic_load_store="16"',
  "--cfg", 'target_has_atomic_load_store="32"',
  "--cfg", 'target_has_atomic_load_store="ptr"',
  # enable cas
  "--cfg", "target_has_atomic",
  "--cfg", 'target_has_atomic="8"',
  "--cfg", 'target_has_atomic="16"',
  "--cfg", 'target_has_atomic="32"',
  "--cfg", 'target_has_atomic="ptr"',
]

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

Successfully merging this pull request may close these issues.

2 participants