-
Notifications
You must be signed in to change notification settings - Fork 99
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
Embedded development on stable #42
Comments
Does anyone have experience with Unicorn, which has what looks to be a fairly solid Rust binding in unicorn-rs? It wouldn't be able to test peripheral-dependent crates without someone mocking the peripherals themselves, but could it be useful for testing Rust codegen and linking for other no-std libs? |
As I was writing the embedonomicon (cf. #59) I explored the possibility of making embedded no-std The conclusion of my exploration was that there are only three unstable features that prevent us
(*) There's a stable workaround for the unstable The question is whether we want to push for having this form -- take a close look to the linked Making this stable will not only mean dealing with these 3 unstable features but also with making Thoughts? cc @hannobraun @jamesmunns @jcsoo @thejpster |
Just wanted to say, I read through this and it's excellent. Great work! Can't wait to apply some of these changes to stellaris-launchpad. |
I have ported this repository for MSP430. (link) There are a couple of things that I learned in the process:
|
@pftbest Yeah, |
@pftbest Yeah, that's using |
Some updates after Rust All Hands:
We'll be producing rust-std components for ARM Cortex-M and MSP430, and eventually for AVR and RISCV once they are more mature. Once those components are in place you'll be able to use Cargo, instead of Xargo, for embedded development by first doing Tracking issue: rust-lang/rust#49382 PR for building rust-std for ARM Cortex-M: rust-lang/rust#49563
We'll open a RFC to stabilize some assembly operations as "Rust intrinsics" that live in core. See #63 for details.
Has been proposed for stabilization in rust-lang/rust#24111 (comment)
We discussed the binary size problem (see #41). We decided that we'll go ahead and land the accepted RFC (2070), and that we'll fix the binary size problem in the future using pure MIR rlibs (not yet implemented).
We discussed merging the A PR implementing this has been submitted: rust-lang/rust#49503
I have submitted an RFC proposing the stabilization of this experimental feature: rust-lang/rfcs#2386 |
This is done. See PSA: You no longer need Xargo to do ARM Cortex-M development.
This is done. Thanks @oli-obk! See PSA: [breaking-change] |
I had totally forgotten about unstable compiler flags. The most used unstable flag is
I think the way forward here is to ask for I thought it might be possible to get away with not having to stabilize that flag and still be able Is there any other unstable compiler flag that comes often in embedded development? |
Actually that seems to be the default. I tried changing it to ld.lld initially but that failed, simply removing |
$ rustc -Z unstable-options --target thumbv7m-none-eabi --print target-spec-json | grep link
"linker": "arm-none-eabi-gcc",
"linker-flavor": "gcc", You need both |
@japaric Interesting. At least that explains why I was seeing a difference between no
I wrongly assumed it would be using |
Update: We now have a preview of embedded Rust on stable at rust-embedded/cortex-m-quickstart#29. The preview only requires a single unstable feature: Quite a few pieces need to land before you can try out this using crates.io releases but we would greatly appreciate if you could try the quickstart PR now and let us know what you think (please comment in the quickstart PR). In particular we would love your input on these unresolved questions. |
I have open a PR to stabilize |
This landed 2 weeks ago.
Check out the announcement! You may experience some (planned) breakage. Once that feature is stabilized |
Update: |
As the only thing left to do here is rust-lang/rust#44489 I'm going to close this in favor of that upstream issue, which I have assigned to the RC1 milestone. |
Triage(2018-07-15): This is only waiting on #[panic_implementation] being stabilized. Proposal for FCP.
Development of
no_std
applications is relegated to the nightly channel because it requires optinginto several unstable features. This makes Rust hard to sell to C developers; they'd rather stick to
their stable vendor provided toolchains instead of having to deal with constant breakage /
regressions.
It may not be possible to stabilize all the features needed for application development this year,
but the following unstable features are widely used in library development and it might be possible
to stabilize them this year:
Xargo.rust-std components for embedded targets.Once those are in place you'll be able to use Cargo as you normally would by first doing
rustup target add thumbv7m-none-eabi
.Tracking issue rust-lang/rust#49382
Xargo requires the nightly channel to build the core crate / std facade. Having that functionalityin stable Cargo would make Xargo unnecessary.
The Cargo team said they'll work on this this year.I wrote how to land the functionality in Cargo.We'll RFC "Stable assembly operations" instead of stabilizingasm!
asm!
. See Stable assembly operations #63 for detailsA pre-rfc on this topic is being discussed.Upstream tracking issue rust-lang/rust#29722const fn
Has been proposed for stabilization in const fn tracking issue (RFC 911) rust-lang/rust#24111 (comment)The old const evaluator is going to be replaced with miri (cf. rust-lang/rust#46882). This fixes a
bunch of bugs and removes several restrictions the old const eval had. It's more likely this feature
will be stabilized once miri is in place.
Upstream tracking issue rust-lang/rust#24111
panic_fmt
#[panic_implementation]
If we want to support the use case of linking a Rust library into a C program then setting a
no_std
panic handler must be possible on stable.An RFC on this topic has been accepted (tracking issue rust-lang/rust#44489) and part of the
implementation has landed in rust-lang/rust#47687
If we want to be able to build pure Rust no-std applications then a lot of other unstable features
are needed. It's unclear whether we can stabilize any of them this year.
compiler_builtins_lib
#![no_std]
expansion will include a stableextern crate compiler_builtins
so you won't require opting into thecompiler_builtins_lib
feature gateA PR implementing this has been submitted: rust-lang/rust#49503
Ideally these builtins should be shipped with core and it shouldn't be necessary to explicitly linkto the
compiler-builtins
crate.Can be worked around using unmangled symbols at the cost of not supporting the standardstart
andtermination
lang itemsmain
interface. See stable-embedded-rust for an example.These are required to support the standardmain
function interface.Can be worked around by usinglinkage(weak)
PROVIDE
in a linker script. See stable-embedded-rust for an example.Used to define a weak interrupt table with a default catch all handler while still allowing the user
to override any handler in the table.
Weak aliases can be implemented usingglobal_asm!
PROVIDE
in a linker script. See stable-embedded-rust for an example.Used to implement weak aliases; a feature which is not supported in the language.
#[used]
Used to force the compiler to preserve some "unused" symbols that are required at link time (like
the interrupt table).
Tracking issue: rust-lang/rust#40289
RFC for stabilization: rust-lang/rfcs#2386
There's other aspect to stability here and that's the lack of CI testing for no-std targets in
rust-lang/rust. The consequence of this is that changes unrelated to unstable features can break
these targets. This happened twice last year: changes in the
core
crate related to atomics brokethe
thumbv6m-none-eabi
target.This issue can be addressed by having no-std targets being tested as part of CI testing. As we don't
want to block rust-lang/rust development on codegen / LLVM bugs it should be possible to easily
disable testing on these no-std targets; a mechanism for this is already in place for tooling like
clippy and miri. Here we should define how much testing we want to do: just building core (simpler),
or also testing that linking no-std applications works (more involved as it requires several
unstable features).
#52 tracks testing embedded targets in rust-lang/rust CI.
cc @pftbest
The text was updated successfully, but these errors were encountered: