@@ -10,8 +10,188 @@ If you want to mention something in [the next newsletter], make sure to leave a
10
10
[ Embedded WG ] : https://github.com/rust-lang-nursery/embedded-wg
11
11
12
12
## Highlights
13
+ ## The embedded WG at Rust All Hands
14
+
15
+ This week ~ 15 Rust teams / working groups met for the Rust All Hands event. Some members of the
16
+ embedded WG were present and we had a chance to talk to the compiler, core and infra teams. These
17
+ are the highlights of our talks:
18
+
19
+ ### Embedded Rust on stable
20
+
21
+ We had previously identified 3 unstable features / issues that tie embedded development to the
22
+ nightly channel in https://github.com/japaric/stable-embedded-rust . We talk to the other Rust teams
23
+ about the possibility of addressing these issues in time for the 2018 edition release and the
24
+ conclusion was that they thought that the timeline was possible. These are the 3 unstable features
25
+ we are referring to:
26
+
27
+ - ~ Xargo~
28
+
29
+ We'll ship a rust-std component (pre-compiled core+compiler-builtins) for the thumb* and msp430
30
+ targets. This removes the need for Xargo so people will be able to do, for example, `rustup target
31
+ add thumb7m-none-eabi; cargo build --target thumbv7m-none-eabi` to cross compile to ARM Cortex-M.
32
+
33
+ Tracking issue: [ rust-lang/rust #49382 ] .
34
+
35
+ [ rust-lang/rust#49382 ] : https://github.com/rust-lang/rust/issues/49382
36
+
37
+ - ` compiler-builtins `
38
+
39
+ ` extern crate compiler_builtins ` is unstable to directly use. The fix we have decided on is to
40
+ inject that as part of the prelude you get from ` #![no_std] ` .
41
+
42
+ So, today ` #![no_std] ` expands to something like this:
43
+
44
+ ``` rust
45
+ #![no_std]
46
+ extern crate core;
47
+ ```
48
+
49
+ With our change the expansion will run like this:
50
+
51
+ ``` rust
52
+ #![no_std]
53
+ extern crate core;
54
+ extern crate compiler_builtins; // but this doesn't #![feature(compiler_builtins_lib)]
55
+ ```
56
+
57
+ In the future we might want to merge ` compiler-builtins ` into ` core ` but that requires more effort
58
+ and can still be done if we do the ` #![no_std] ` prelude approach right now.
59
+
60
+ Tracking issue: [ rust-lang/rust #49380 ]
61
+
62
+ [ rust-lang/rust#49380 ] : https://github.com/rust-lang/rust/issues/49380
63
+
64
+ - ` panic_fmt `
65
+
66
+ There's an accepted RFC (#2070 ) for a stable mechanism to select the behavior of ` panic! ` in
67
+ ` no_std ` context, and there's a know issue where the arguments of ` panic_fmt ` are kept in the binary
68
+ even when they are unused by the ` panic_fmt ` implementation (cf. [ rust-lang/embedded-wg #41 ] ).
69
+
70
+ [ rust-lang/embedded-wg#41 ] : https://github.com/rust-lang-nursery/embedded-wg/issues/41
71
+
72
+ The main concern here was whether we'll be able to fix the binary size problem with the accepted
73
+ design or if we'll need some new design. The compiler team thinks that this can be fixed with the
74
+ existing design using MIR only rlibs but it's unlikely this will get fixed in time for the edition
75
+ release. @nagisa will likely propose an alternate solution that involves having Cargo select the
76
+ panic provider crate.
77
+
78
+ ### Non critical unstable features
79
+
80
+ There are some other unstable features that although don't prevent you from doing embedded
81
+ development they come up often when doing no-std development. We had a chat with people on the
82
+ compiler team about them.
83
+
84
+ - ` const fn `
85
+
86
+ This feature has been proposed for stabilization (cf. [ rust-lang/rust #24111 ] ).
87
+
88
+ [ rust-lang/rust#24111 ] : https://github.com/rust-lang/rust/issues/24111#issuecomment-376649804
89
+
90
+ - ` asm! `
91
+
92
+ Background: Some assembly operations can be implemented as external assembly files that are then
93
+ called into using FFI; other ops though do need to be inlined into the function from which they are
94
+ called to prevent losing semantics. Using external assembly file can be done on the stable channel.
95
+ The second type of operation requires the unstable ` asm! ` macro.
96
+
97
+ The compiler team is not 100% sure on whether they want to stabilize inline assembly for the edition
98
+ release. The embedded WG has proposed an alternative proposal: expose * some* assembly operations
99
+ that need to be inlined as "Rust intrinsics" -- in a similar fashion to how SIMD is being
100
+ implemented; these intrinsics would be in the ` core::asm::$ARCH ` module and they could either be
101
+ implemented by lowering to a LLVM intrinsics or using inline assembly. For example:
102
+
103
+ ``` rust
104
+ pub mod asm {
105
+ pub mod arm {
106
+ #[inline(always)]
107
+ pub fn cpsid () {
108
+ unsafe {
109
+ asm! (" cpsid i" :: : " memory" : " volatile" );
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ These would be stable APIs with an unstable implementation. If LLVM assembler syntax the
117
+ implementations of these functions would have to be updated.
118
+
119
+ The embedded WG will submit an RFC proposing the ` asm ` module and that will include a list of
120
+ assembly operations that (a) are common and (b) need to be inlined for different architectures.
121
+
122
+ - ` #[used] `
123
+
124
+ This experimental feature has been in the compiler for a while and it's required in some scenarios
125
+ when using LTO to prevent the compiler some function / ` static ` that needs to be in the final
126
+ binary.
127
+
128
+ We'll try to get it stabilized by the edition release but it's not a high priority feature.
129
+
130
+ ### Stability of the embedded targets
131
+
132
+ We don't only want to make embedded Rust possible on stable; we also want to make sure the embedded
133
+ targets don't regress. So we are going to add tests to rust-lang/rust CI to make sure regression
134
+ block PRs from landing.
135
+
136
+ That effectively will make some of the embedded targets into the tier 1 platform. The core team is
137
+ fine with adding the thumb* targets (ARM Cortex-M) to tier 1; less maintained, still in
138
+ development and not fully mature targets like AVR, MSP430 and RISCV will become tier 3 -- they'll be
139
+ tested but won't block PRs and rust-std binaries will be produced but it's not guaranteed there will
140
+ be binaries available for all nightly / beta / stable releases.
141
+
142
+ We'll open an issue to discuss with the infra team the exact tests we want to add and track progress
143
+ on that, but have already told them about the kind of tests we want to add and they thought those
144
+ kind of tests are possible to implement. The kind of tests we discussed were:
145
+
146
+ - It compiles and links
147
+ - Runs the cross compiled binary in QEMU doesn't crash and exits with exit code 0.
148
+ - Tracking the binary size of a program compiled with ` -Os ` / ` -Oz ` and notify someone or fail the
149
+ build if the size regresses by 5% / 10% or something.
150
+
151
+ ### LLVM backends that are not yet in rustc
152
+
153
+ There are two embedded LLVM backends that have not yet been enabled in rustc for different reasons:
154
+ AVR and RISCV.
155
+
156
+ In the case of AVR the main reason is that some LLVM codegen bugs prevent you from building core for
157
+ AVR. These bugs are related to 128-bit integers and formatting floats. The libs team discussed this
158
+ some time ago and they decided they are fine with landing arch specific ` #[cfg] ` attributes to
159
+ remove 128-bit integers and other things like float APIs.
160
+
161
+ In the case of RISCV the LLVM backend is currently under active development and our current version
162
+ of LLVM doesn't fully support RISCV. We would have to backport several patches to make RISCV work on
163
+ our LLVM version. The core team feels OK with backporting those patches as long as they have already
164
+ landed in upstream LLVM, and are not still under review.
165
+
166
+ ### Tooling
167
+
168
+ Getting tooling for e.g. binary inspection (e.g. ` objdump ` ) can be hard on some platforms (e.g.
169
+ Windows) specially for architecture which currently are not too widely used (e.g. RISCV). We can
170
+ improve the situation here by shipping llvm tools with the Rust toolchain -- with one set of those
171
+ tools you can inspect all the architectures that Rust supports. These are the thoughts of the core /
172
+ infra team regarding this:
173
+
174
+ - We put these tools in the sysroot and have them always shipped with the Rust toolchain so no
175
+ ` rustup component add ` required -- this is already the case with ` lld ` . It might not be possible
176
+ to provide these tools on all platforms but it's very likely they'll be available on tier 1
177
+ platforms.
178
+
179
+ - We do * not* add these tools to the user ` $PATH ` . Instead some Cargo subcommand will be created by
180
+ the embedded WG (e.g. ` cargo objdump ` ) and that subcommand will look for ` llvm-objdump ` in the
181
+ sysroot and do the right thing.
182
+
183
+ - We make no guarantees about the semantics and interface of these tools being preserved over time
184
+ (e.g. CLI changes, user facing output format changes, etc.).
185
+
186
+ ### The embedded Rust book
187
+
188
+ We decided on an initial audience for the embedded book; we will be targeting people that know some
189
+ embedded stuff * and* some Rust. The main reason for this is that if someone knows one and not the
190
+ other then they can go and read existing Rust documentation or the Discovery book and then read the
191
+ embedded book. For more details check [ rust-lang-nursery/embedded-wg #56 ] .
192
+
193
+ [ rust-lang-nursery/embedded-wg#56 ] : https://github.com/rust-lang-nursery/embedded-wg/issues/56
13
194
14
- > TODO: More specific stuff from Rust All Hands?
15
195
16
196
* [ japaric] , [ hannobraun] , and [ jamesmunns] from the [ Embedded WG] attended the 2018 Rust All Hands in Berlin, working on our goal to make [ stable embedded rust development] possible in 2018!
17
197
* [ drbgn] has kicked off an investigation on how to [ mock embedded-hal] to make testing sensors easier
0 commit comments