1
1
# A note on compiler support
2
2
3
3
This book makes use of a built-in * compiler* target, the ` thumbv7m-none-eabi ` , for which the Rust
4
- team distributes a ` rust-std ` component, a pre-compiled version of the ` core ` crate .
4
+ team distributes a ` rust-std ` component, which is a pre-compiled collection of crates like [ ` core ` ] and [ ` std ` ] .
5
5
6
- If you want to attempt replicating the contents of this book for a different target architecture you
6
+ [ `core` ] : https://doc.rust-lang.org/core/index.html
7
+ [ `std` ] : https://doc.rust-lang.org/std/index.html
8
+
9
+ If you want to attempt replicating the contents of this book for a different target architecture, you
7
10
need to take into account the different levels of support that Rust provides for (compilation)
8
11
targets.
9
12
10
13
## LLVM support
11
14
12
- As of Rust 1.28 official Rust compiler, ` rustc ` , uses LLVM for (machine) code generation. The
15
+ As of Rust 1.28, the official Rust compiler, ` rustc ` , uses LLVM for (machine) code generation. The
13
16
minimal level of support Rust provides for an architecture is having its LLVM backend enabled in
14
17
` rustc ` . You can see all the architectures that ` rustc ` supports, through LLVM, by running the
15
18
following command:
@@ -52,18 +55,18 @@ LLVM (http://llvm.org/):
52
55
x86-64 - 64-bit X86: EM64T and AMD64
53
56
```
54
57
55
- If LLVM supports the architecture you are interested in but ` rustc ` is built with the backend
56
- disabled (which is the case of AVR as of Rust 1.28) then you will need to modify the Rust source
58
+ If LLVM supports the architecture you are interested in, but ` rustc ` is built with the backend
59
+ disabled (which is the case of AVR as of Rust 1.28), then you will need to modify the Rust source
57
60
enabling it. The first two commits of PR [ rust-lang/rust #52787 ] give you an idea of the required
58
61
changes.
59
62
60
63
[ rust-lang/rust#52787 ] : https://github.com/rust-lang/rust/pull/52787
61
64
62
- On the other hand, if LLVM doesn't support the architecture but a fork of LLVM does you will have to
63
- built ` rustc ` against the fork. The Rust build system allows this and in principle should just
64
- require changing the ` llvm ` submodule to point to the fork.
65
+ On the other hand, if LLVM doesn't support the architecture, but a fork of LLVM does, you will have
66
+ to replace the original version of LLVM with the fork before building ` rustc ` . The Rust build system
67
+ allows this and in principle it should just require changing the ` llvm ` submodule to point to the fork.
65
68
66
- If your target architecture is only supported by some vendor provided GCC you have the option of
69
+ If your target architecture is only supported by some vendor provided GCC, you have the option of
67
70
using [ ` mrustc ` ] , an unofficial Rust compiler, to translate your Rust program into C code and then
68
71
compile that using GCC.
69
72
@@ -72,8 +75,8 @@ compile that using GCC.
72
75
## Built-in target
73
76
74
77
A compilation target is more than just its architecture. Each target has a [ specification]
75
- associated to it that describes its architecture, its operating system, the default linker among
76
- other things .
78
+ associated to it that describes, among other things, its architecture, its operating system
79
+ and the default linker .
77
80
78
81
[ specification ] : https://github.com/rust-lang/rfcs/blob/master/text/0131-target-specification.md
79
82
@@ -159,20 +162,17 @@ $ rustc +nightly -Z unstable-options --print target-spec-json --target thumbv7m-
159
162
}
160
163
```
161
164
162
- If none of these built-in targets seems appropriate for your target system you'll have to create a
163
- custom target by writing a target specification file. A target specification file is a JSON file
164
- that contains the specification of a compilation target. The output of the `rustc --print
165
- target-spec-json` command from before is the target specification in JSON format.
166
-
167
- The recommended way to write a target specification file is to dump the specification of a built-in
168
- target that's similar to your target system into a file and then tweak it to match the properties of
169
- your target system. As of Rust 1.28, there's no up to date documentation on what each of the fields
170
- of a target specification mean, other than [ the compiler source code] .
165
+ If none of these built-in targets seems appropriate for your target system, you'll have to create a
166
+ custom target by writing your own target specification file in JSON format. The recommended way is to
167
+ dump the specification of a built-in target that's similar to your target system into a file and then
168
+ tweak it to match the properties of your target system. To do so, use the previously shown command,
169
+ ` rustc --print target-spec-json ` . As of Rust 1.28, there's no up to date documentation on what each of
170
+ the fields of a target specification mean, other than [ the compiler source code] .
171
171
172
172
[ the compiler source code ] : https://github.com/rust-lang/rust/blob/1.27.2/src/librustc_target/spec/mod.rs#L376-L400
173
173
174
174
Once you have a target specification file you can refer to it by its path or by its name if its in
175
- the current directory or in ` $RUST_TARGET_PATH ` .
175
+ the current directory or in ` $RUST_TARGET_PATH ` .
176
176
177
177
``` console
178
178
$ rustc +nightly -Z unstable-options --print target-spec-json \
@@ -240,7 +240,7 @@ mips-unknown-linux-gnu x86_64-unknown-netbsd
240
240
mips-unknown-linux-musl x86_64-unknown-redox
241
241
```
242
242
243
- If there's no ` rust-std ` component for your target or you are using a custom target then you'll have
243
+ If there's no ` rust-std ` component for your target or you are using a custom target, then you'll have
244
244
to use a tool like [ Xargo] to have Cargo compile the ` core ` crate on the fly. Note that Xargo
245
245
requires a nightly toolchain; the long term plan is to upstream Xargo's functionality into Cargo
246
246
and eventually have that functionality available on stable.
0 commit comments