Skip to content

Commit f4f46f0

Browse files
committed
revert
1 parent f0b6d2b commit f4f46f0

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

docs/rust-setup.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
---
2+
title: Installation
3+
---
4+
5+
This guide is for reference only, please check the latest information on getting starting with Substrate
6+
[here](https://docs.substrate.io/main-docs/install/).
7+
8+
This page will guide you through the **2 steps** needed to prepare a computer for **Substrate** development.
9+
Since Substrate is built with [the Rust programming language](https://www.rust-lang.org/), the first
10+
thing you will need to do is prepare the computer for Rust development - these steps will vary based
11+
on the computer's operating system. Once Rust is configured, you will use its toolchains to interact
12+
with Rust projects; the commands for Rust's toolchains will be the same for all supported,
13+
Unix-based operating systems.
14+
15+
## Build dependencies
16+
17+
Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples
18+
in the [Substrate Docs](https://docs.substrate.io) use Unix-style terminals to demonstrate how to
19+
interact with Substrate from the command line.
20+
21+
### Ubuntu/Debian
22+
23+
Use a terminal shell to execute the following commands:
24+
25+
```bash
26+
sudo apt update
27+
# May prompt for location information
28+
sudo apt install -y git clang curl libssl-dev llvm libudev-dev
29+
```
30+
31+
### Arch Linux
32+
33+
Run these commands from a terminal:
34+
35+
```bash
36+
pacman -Syu --needed --noconfirm curl git clang
37+
```
38+
39+
### Fedora
40+
41+
Run these commands from a terminal:
42+
43+
```bash
44+
sudo dnf update
45+
sudo dnf install clang curl git openssl-devel
46+
```
47+
48+
### OpenSUSE
49+
50+
Run these commands from a terminal:
51+
52+
```bash
53+
sudo zypper install clang curl git openssl-devel llvm-devel libudev-devel
54+
```
55+
56+
### macOS
57+
58+
> **Apple M1 ARM**
59+
> If you have an Apple M1 ARM system on a chip, make sure that you have Apple Rosetta 2
60+
> installed through `softwareupdate --install-rosetta`. This is only needed to run the
61+
> `protoc` tool during the build. The build itself and the target binaries would remain native.
62+
63+
Open the Terminal application and execute the following commands:
64+
65+
```bash
66+
# Install Homebrew if necessary https://brew.sh/
67+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
68+
69+
# Make sure Homebrew is up-to-date, install openssl
70+
brew update
71+
brew install openssl
72+
```
73+
74+
### Windows
75+
76+
**_PLEASE NOTE:_** Native Windows development of Substrate is _not_ very well supported! It is _highly_
77+
recommend to use [Windows Subsystem Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
78+
(WSL) and follow the instructions for [Ubuntu/Debian](#ubuntudebian).
79+
Please refer to the separate
80+
[guide for native Windows development](https://docs.substrate.io/main-docs/install/windows/).
81+
82+
## Rust developer environment
83+
84+
This guide uses <https://rustup.rs> installer and the `rustup` tool to manage the Rust toolchain.
85+
First install and configure `rustup`:
86+
87+
```bash
88+
# Install
89+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
90+
# Configure
91+
source ~/.cargo/env
92+
```
93+
94+
Configure the Rust toolchain to default to the latest stable version, add nightly and the nightly wasm target:
95+
96+
```bash
97+
rustup default stable
98+
rustup update
99+
rustup update nightly
100+
rustup target add wasm32-unknown-unknown --toolchain nightly
101+
```
102+
103+
## Test your set-up
104+
105+
Now the best way to ensure that you have successfully prepared a computer for Substrate
106+
development is to follow the steps in [our first Substrate tutorial](https://docs.substrate.io/tutorials/v3/create-your-first-substrate-chain/).
107+
108+
## Troubleshooting Substrate builds
109+
110+
Sometimes you can't get the Substrate node template
111+
to compile out of the box. Here are some tips to help you work through that.
112+
113+
### Rust configuration check
114+
115+
To see what Rust toolchain you are presently using, run:
116+
117+
```bash
118+
rustup show
119+
```
120+
121+
This will show something like this (Ubuntu example) output:
122+
123+
```text
124+
Default host: x86_64-unknown-linux-gnu
125+
rustup home: /home/user/.rustup
126+
127+
installed toolchains
128+
--------------------
129+
130+
stable-x86_64-unknown-linux-gnu (default)
131+
nightly-2020-10-06-x86_64-unknown-linux-gnu
132+
nightly-x86_64-unknown-linux-gnu
133+
134+
installed targets for active toolchain
135+
--------------------------------------
136+
137+
wasm32-unknown-unknown
138+
x86_64-unknown-linux-gnu
139+
140+
active toolchain
141+
----------------
142+
143+
stable-x86_64-unknown-linux-gnu (default)
144+
rustc 1.50.0 (cb75ad5db 2021-02-10)
145+
```
146+
147+
As you can see above, the default toolchain is stable, and the
148+
`nightly-x86_64-unknown-linux-gnu` toolchain as well as its `wasm32-unknown-unknown` target is installed.
149+
You also see that `nightly-2020-10-06-x86_64-unknown-linux-gnu` is installed, but is not used unless explicitly defined as illustrated in the [specify your nightly version](#specifying-nightly-version)
150+
section.
151+
152+
### WebAssembly compilation
153+
154+
Substrate uses [WebAssembly](https://webassembly.org) (Wasm) to produce portable blockchain
155+
runtimes. You will need to configure your Rust compiler to use
156+
[`nightly` builds](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) to allow you to
157+
compile Substrate runtime code to the Wasm target.
158+
159+
> There are upstream issues in Rust that need to be resolved before all of Substrate can use the stable Rust toolchain.
160+
> [This is our tracking issue](https://github.com/paritytech/substrate/issues/1252) if you're curious as to why and how this will be resolved.
161+
162+
#### Latest nightly for Substrate `master`
163+
164+
Developers who are building Substrate _itself_ should always use the latest bug-free versions of
165+
Rust stable and nightly. This is because the Substrate codebase follows the tip of Rust nightly,
166+
which means that changes in Substrate often depend on upstream changes in the Rust nightly compiler.
167+
To ensure your Rust compiler is always up to date, you should run:
168+
169+
```bash
170+
rustup update
171+
rustup update nightly
172+
rustup target add wasm32-unknown-unknown --toolchain nightly
173+
```
174+
175+
> NOTE: It may be necessary to occasionally rerun `rustup update` if a change in the upstream Substrate
176+
> codebase depends on a new feature of the Rust compiler. When you do this, both your nightly
177+
> and stable toolchains will be pulled to the most recent release, and for nightly, it is
178+
> generally _not_ expected to compile WASM without error (although it very often does).
179+
> Be sure to [specify your nightly version](#specifying-nightly-version) if you get WASM build errors
180+
> from `rustup` and [downgrade nightly as needed](#downgrading-rust-nightly).
181+
182+
#### Rust nightly toolchain
183+
184+
If you want to guarantee that your build works on your computer as you update Rust and other
185+
dependencies, you should use a specific Rust nightly version that is known to be
186+
compatible with the version of Substrate they are using; this version will vary from project to
187+
project and different projects may use different mechanisms to communicate this version to
188+
developers. For instance, the Polkadot client specifies this information in its
189+
[release notes](https://github.com/paritytech/polkadot/releases).
190+
191+
```bash
192+
# Specify the specific nightly toolchain in the date below:
193+
rustup install nightly-<yyyy-MM-dd>
194+
```
195+
196+
#### Wasm toolchain
197+
198+
Now, configure the nightly version to work with the Wasm compilation target:
199+
200+
```bash
201+
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
202+
```
203+
204+
### Specifying nightly version
205+
206+
Use the `WASM_BUILD_TOOLCHAIN` environment variable to specify the Rust nightly version a Substrate
207+
project should use for Wasm compilation:
208+
209+
```bash
210+
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --release
211+
```
212+
213+
> Note that this only builds _the runtime_ with the specified nightly. The rest of project will be
214+
> compiled with **your default toolchain**, i.e. the latest installed stable toolchain.
215+
216+
### Downgrading Rust nightly
217+
218+
If your computer is configured to use the latest Rust nightly and you would like to downgrade to a
219+
specific nightly version, follow these steps:
220+
221+
```bash
222+
rustup uninstall nightly
223+
rustup install nightly-<yyyy-MM-dd>
224+
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
225+
```

0 commit comments

Comments
 (0)