Skip to content

Commit 757e0c3

Browse files
Merge #16
16: Review compiler support r=japaric a=andre-richter Co-authored-by: Andre Richter <andre-richter@users.noreply.github.com>
2 parents 60e2ec3 + cfee48f commit 757e0c3

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/compiler-support.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# A note on compiler support
22

33
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`].
55

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
710
need to take into account the different levels of support that Rust provides for (compilation)
811
targets.
912

1013
## LLVM support
1114

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
1316
minimal level of support Rust provides for an architecture is having its LLVM backend enabled in
1417
`rustc`. You can see all the architectures that `rustc` supports, through LLVM, by running the
1518
following command:
@@ -52,18 +55,18 @@ LLVM (http://llvm.org/):
5255
x86-64 - 64-bit X86: EM64T and AMD64
5356
```
5457

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
5760
enabling it. The first two commits of PR [rust-lang/rust#52787] give you an idea of the required
5861
changes.
5962

6063
[rust-lang/rust#52787]: https://github.com/rust-lang/rust/pull/52787
6164

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.
6568

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
6770
using [`mrustc`], an unofficial Rust compiler, to translate your Rust program into C code and then
6871
compile that using GCC.
6972

@@ -72,8 +75,8 @@ compile that using GCC.
7275
## Built-in target
7376

7477
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.
7780

7881
[specification]: https://github.com/rust-lang/rfcs/blob/master/text/0131-target-specification.md
7982

@@ -159,20 +162,17 @@ $ rustc +nightly -Z unstable-options --print target-spec-json --target thumbv7m-
159162
}
160163
```
161164

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].
171171

172172
[the compiler source code]: https://github.com/rust-lang/rust/blob/1.27.2/src/librustc_target/spec/mod.rs#L376-L400
173173

174174
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`.
176176

177177
``` console
178178
$ rustc +nightly -Z unstable-options --print target-spec-json \
@@ -240,7 +240,7 @@ mips-unknown-linux-gnu x86_64-unknown-netbsd
240240
mips-unknown-linux-musl x86_64-unknown-redox
241241
```
242242

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
244244
to use a tool like [Xargo] to have Cargo compile the `core` crate on the fly. Note that Xargo
245245
requires a nightly toolchain; the long term plan is to upstream Xargo's functionality into Cargo
246246
and eventually have that functionality available on stable.

0 commit comments

Comments
 (0)