Skip to content

Commit 34e01d5

Browse files
Add clarification about build-std and using newer instructions.
1 parent b787fc0 commit 34e01d5

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

src/doc/rustc/src/platform-support/sparc-unknown-none-elf.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,31 @@ list in `config.toml`:
3939
```toml
4040
[build]
4141
build-stage = 1
42-
target = ["sparc-unknown-none-elf"]
42+
host = ["<target for your host>"]
43+
target = ["<target for your host>", "sparc-unknown-none-elf"]
4344
```
4445

46+
Replace `<target for your host>` with `x86_64-unknown-linux-gnu` or whatever
47+
else is appropriate for your host machine.
48+
4549
## Building Rust programs
4650

47-
```text
51+
To build with this target, pass it to the `--target` argument, like:
52+
53+
```console
4854
cargo build --target sparc-unknown-none-elf
4955
```
5056

5157
This target uses GCC as a linker, and so you will need an appropriate GCC
52-
compatible `sparc-unknown-none` toolchain.
58+
compatible `sparc-unknown-none` toolchain. The default linker binary is
59+
`sparc-elf-gcc`, but you can override this in your project configuration, as
60+
follows:
5361

54-
The default linker name is `sparc-elf-gcc`, but you can override this in your
55-
project configuration.
62+
`.cargo/config.toml`:
63+
```toml
64+
[target.sparc-unknown-none-elf]
65+
linker = "sparc-custom-elf-gcc"
66+
```
5667

5768
## Testing
5869

@@ -74,6 +85,26 @@ something like:
7485
linker = "sparc-gaisler-elf-gcc"
7586
runner = "tsim-leon3"
7687

88+
[build]
89+
target = ["sparc-unknown-none-elf"]
90+
rustflags = "-Ctarget-cpu=leon3"
91+
```
92+
93+
With this configuration, running `cargo run` will compile your code for the
94+
SPARC V8 compatible Gaisler Leon3 processor and then start the `tsim-leon3`
95+
simulator. The `libcore` was pre-compiled as part of the `rustc` compilation
96+
process using the SPARC V7 baseline, but if you are using a nightly toolchain
97+
you can use the
98+
[`-Z build-std=core`](https://doc.rust-lang.org/cargo/reference/unstable.html#build-std)
99+
option to rebuild `libcore` from source. This may be useful if you want to
100+
compile it for SPARC V8 and take advantage of the extra instructions.
101+
102+
`.cargo/config.toml`:
103+
```toml
104+
[target.sparc-unknown-none-elf]
105+
linker = "sparc-gaisler-elf-gcc"
106+
runner = "tsim-leon3"
107+
77108
[build]
78109
target = ["sparc-unknown-none-elf"]
79110
rustflags = "-Ctarget-cpu=leon3"
@@ -82,16 +113,16 @@ rustflags = "-Ctarget-cpu=leon3"
82113
build-std = ["core"]
83114
```
84115

85-
With this configuration, running `cargo run` will compile your code for the
86-
SPARC V8 compatible Gaisler Leon3 processor and then start the `tsim-leon3`
87-
simulator. Once the simulator is running, simply enter the command
88-
`run` to start the code executing in the simulator.
116+
Either way, once the simulator is running, simply enter the command `run` to
117+
start the code executing in the simulator.
89118

90119
The default C toolchain libraries are linked in, so with the Gaisler [BCC2]
91120
toolchain, and using its default Leon3 BSP, you can use call the C `putchar`
92-
function and friends to output to the simulator console.
121+
function and friends to output to the simulator console. The default linker
122+
script is also appropriate for the Leon3 simulator, so no linker script is
123+
required.
93124

94-
Here's a complete example:
125+
Here's a complete example using the above config file:
95126

96127
```rust,ignore (cannot-test-this-because-it-assumes-special-libc-functions)
97128
#![no_std]

0 commit comments

Comments
 (0)