Skip to content

Commit 3b9968b

Browse files
author
imarkov
committed
Update readme with RiscV and Rust STD information
1 parent abb1fae commit 3b9968b

File tree

1 file changed

+79
-9
lines changed

1 file changed

+79
-9
lines changed

README.md

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,97 @@
1-
# The Rust Programming Language For Xtensa processors
1+
# The Rust Programming Language for Espressif chips
22

3-
This fork enables projects to be built for the ESP32 and ESP8266 using [espressif's llvm fork](https://github.com/espressif/llvm-project). The [esp-rs](https://github.com/esp-rs) organization has been formed to develop runtime, pac and hal crates for the esp32 and eventually esp8266.
3+
This fork enables projects to be built for the Xtensa-based ESP32, ESP32-SXX and ESP8266 using [Espressif's llvm fork](https://github.com/espressif/llvm-project). (RiscV chips like ESP32-CXX are already supported in stock Rust.)
4+
5+
Moreover, this fork enables Rust STD support (networking, threads, and filesystem) for all chips in the ESP32 family (Xtensa and RiscV), by optionally linking with the ESP-IDF framework.
6+
7+
The [esp-rs](https://github.com/esp-rs) organization has been formed to develop runtime, pac and hal crates for the Espressif chips (bare-metal as well as ESP-IDF based).
48

59
Join in on the discussion: https://matrix.to/#/#esp-rs:matrix.org!
610

7-
## Using this fork
11+
## Installation
812

9-
The [quickstart repo](https://github.com/MabezDev/xtensa-rust-quickstart) has more information on how to build this fork and use it to build xtensa compatible code.
13+
Espressif offers [pre-built binaries of this fork](https://github.com/espressif/rust-esp32-example/blob/main/docs/rust-on-xtensa.md). Follow the instructions for your operating system.
1014

11-
This is the main source code repository for [Rust]. It contains the compiler,
12-
standard library, and documentation.
15+
## Building
16+
Install [Rustup](https://rustup.rs/).
1317

14-
To build this fork and have xtensa support, you need to make sure you pass in the --experimental-targets=Xtensa to configure as follows:
18+
Build using these steps:
1519
```sh
1620
$ git clone https://github.com/esp-rs/rust
1721
$ cd rust
22+
$ git checkout esp
1823
$ ./configure --experimental-targets=Xtensa
1924
$ ./x.py build --stage 2
2025
```
2126

27+
* **NOTE 1**: Building might take **close to an hour**
28+
* **NOTE 2**: Make sure you are using the `esp` GIT branch of the fork (the default)
29+
* **NOTE 3**: Do NOT rename the directory ('rust') where you've cloned the Rust fork. It must be 'rust' or you might have strange issues later on when using it. You can however place it anywhere in your file tree
30+
31+
### Fix toolchain vendor/ directory, so that building STD with Cargo does work
32+
33+
(Assuming you are still in the rust/ directory):
34+
35+
```sh
36+
$ mkdir vendor
37+
$ cd vendor
38+
$ ln -s ../library/rustc-std-workspace-alloc/ rustc-std-workspace-alloc
39+
$ ln -s ../library/rustc-std-workspace-core/ rustc-std-workspace-core
40+
$ ln -s ../library/rustc-std-workspace-std/ rustc-std-workspace-std
41+
```
42+
43+
Make Rustup aware of the newly built compiler:
44+
45+
```sh
46+
$ rustup toolchain link esp ~/<...>/rust/build/x86_64-unknown-linux-gnu/stage2
47+
```
48+
49+
Switch to the new compiler in Rustup:
50+
51+
```sh
52+
$ rustup default esp
53+
```
54+
55+
Check the compiler:
56+
```sh
57+
$ rustc --print target-list
58+
```
59+
60+
At the end of the printed list of targets you should see:
61+
```
62+
...
63+
xtensa-esp32-none-elf
64+
xtensa-esp8266-none-elf
65+
xtensa-none-elf
66+
```
67+
68+
## Building LLVM clang
69+
70+
You'll need the custom LLVM clang based on the Espressif LLVM fork for Rust STD support. Build as follows:
71+
```sh
72+
$ git clone https://github.com/espressif/llvm-project
73+
$ cd llvm-project
74+
$ mkdir build
75+
$ cd build
76+
$ cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release ../llvm
77+
$ cmake --build .
78+
$ export PATH=`pwd`/bin:$PATH
79+
```
80+
81+
Check that you have the custom clang on your path:
82+
```sh
83+
$ which clang
84+
$ which llvm-config
85+
```
86+
87+
The above should output locations pointing at your custom-built clang toolchain.
88+
89+
* **NOTE 1**: Building LLVM clang might take **even longer** time than building the Rustc toolchain
90+
* **NOTE 2**: You might want to make the PATH modification step from above permanent. Please make sure that the custom Clang compiler is the first on your PATH so that it takes precedence over any clang compiler you might have installed using your distro / OS
91+
2292
## Updating this fork
2393

24-
The patch set can be found [here](https://github.com/MabezDev/rust-xtensa-patches). Checkout from upstream/master, apply the patches on at a time using `git am -3 < path/to/patch.patch`, fixing any conflicts if necessary (remember to PR the changes back to the patches [repo]((https://github.com/MabezDev/rust-xtensa-patches))). Once it builds submit a PR against this repo with the branch name `esp-update-$DATE`.
94+
The patch set can be found [here](https://github.com/MabezDev/rust-xtensa-patches). Checkout from upstream/master, apply the patches on at a time using `git am -3 < path/to/patch.patch`, fixing any conflicts if necessary (remember to PR the changes back to the patches [repo]((https://github.com/MabezDev/rust-xtensa-patches))). Once it builds submit a PR against this repo with the branch name `esp-update-$DATE`.
2595

2696
If the llvm submodule needs to be updated, the following should work:
2797

@@ -58,7 +128,7 @@ Read ["Installation"] from [The Book].
58128
The Rust build system uses a Python script called `x.py` to build the compiler,
59129
which manages the bootstrapping process. It lives in the root of the project.
60130

61-
The `x.py` command can be run directly on most systems in the following format:
131+
The `x.py` command can be run directly on most systems in the following format:
62132

63133
```sh
64134
./x.py <subcommand> [flags]

0 commit comments

Comments
 (0)