|
1 | 1 | # How to Build and Run the Compiler
|
2 | 2 |
|
3 | 3 | The compiler is built using a tool called `x.py`. You will need to
|
4 |
| -have Python installed to run it. But before we get to that, if you're going to |
5 |
| -be hacking on `rustc`, you'll want to tweak the configuration of the compiler. |
6 |
| -The default configuration is oriented towards running the compiler as a user, |
7 |
| -not a developer. |
| 4 | +have Python installed to run it. |
8 | 5 |
|
9 | 6 | For instructions on how to install Python and other prerequisites,
|
10 | 7 | see [the next page](./prerequisites.md).
|
@@ -223,6 +220,50 @@ fall back to using `cargo` from the installed `nightly`, `beta`, or `stable` too
|
223 | 220 | `rustup install nightly` if you haven't already. See the
|
224 | 221 | [rustup documentation on custom toolchains](https://rust-lang.github.io/rustup/concepts/toolchains.html#custom-toolchains).
|
225 | 222 |
|
| 223 | +## Building targets for cross-compilation |
| 224 | + |
| 225 | +To produce a compiler that can cross-compile for other targets, |
| 226 | +pass any number of `target` flags to `x.py build`. |
| 227 | +For example, if your host platform is `x86_64-unknown-linux-gnu` |
| 228 | +and your cross-compilation target is `wasm32-wasi`, you can build with: |
| 229 | + |
| 230 | +```bash |
| 231 | +./x.py build --target x86_64-unknown-linux-gnu --target wasm32-wasi |
| 232 | +``` |
| 233 | + |
| 234 | +Note that if you want the resulting compiler to be able to build crates that |
| 235 | +involve proc macros or build scripts, you must be sure to explicitly build target support for the |
| 236 | +host platform (in this case, `x86_64-unknown-linux-gnu`). |
| 237 | + |
| 238 | +If you want to always build for other targets without needing to pass flags to `x.py build`, |
| 239 | +then you can configure this in the `[build]` section of your `config.toml` like so: |
| 240 | + |
| 241 | +```toml |
| 242 | +[build] |
| 243 | +target = ["x86_64-unknown-linux-gnu", "wasm32-wasi"] |
| 244 | +``` |
| 245 | + |
| 246 | +Note that building for some targets requires having external dependencies installed |
| 247 | +(e.g. building musl targets requires a local copy of musl). |
| 248 | +Any target-specific configuration (e.g. the path to a local copy of musl) |
| 249 | +will need to be provided by your `config.toml`. |
| 250 | +Please see `config.toml.example` for information on target-specific configuration keys. |
| 251 | + |
| 252 | +For examples of the complete configuration necessary to build a target, please visit |
| 253 | +[the rustc book](https://doc.rust-lang.org/rustc/platform-support.html), |
| 254 | +select any target under the "Platform Support" heading on the left, |
| 255 | +and see the section related to building a compiler for that target. |
| 256 | +For targets without a corresponding page in the rustc book, |
| 257 | +it may be useful to [inspect the Dockerfiles](/tests/docker.md) |
| 258 | +that the Rust infrastructure itself uses to set up and configure cross-compilation. |
| 259 | + |
| 260 | +If you have followed the directions from the prior section on creating a rustup toolchain, |
| 261 | +then once you have built your compiler you will be able to use it to cross-compile like so: |
| 262 | + |
| 263 | +```bash |
| 264 | +cargo +stage1 build --target wasm32-wasi |
| 265 | +``` |
| 266 | + |
226 | 267 | ## Other `x.py` commands
|
227 | 268 |
|
228 | 269 | Here are a few other useful `x.py` commands. We'll cover some of them in detail
|
|
0 commit comments