Skip to content

Embedded development on stable #42

Closed
@japaric

Description

@japaric

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 opting
into 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 functionality
in 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.

A pre-rfc on this topic is being discussed.

Upstream tracking issue rust-lang/rust#29722

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 stable extern crate compiler_builtins so you won't require opting into the compiler_builtins_lib feature gate

A 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 link
to the compiler-builtins crate.

  • start and termination lang items Can be worked around using unmangled symbols at the cost of not supporting the standard main interface. See stable-embedded-rust for an example.

These are required to support the standard main function interface.

  • linkage(weak) Can be worked around by using 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.

  • global_asm! Weak aliases can be implemented using 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 broke
the 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions