Skip to content

Commit 50dbcba

Browse files
sslime336tshepang
authored andcommitted
Change x.py into x, add explanation for x
1 parent d3034ae commit 50dbcba

File tree

13 files changed

+67
-42
lines changed

13 files changed

+67
-42
lines changed

src/building/bootstrapping.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ to be identical to before, unless something has broken.
107107

108108
### Building the stages
109109

110-
`x.py` tries to be helpful and pick the stage you most likely meant for each subcommand.
110+
`x` tries to be helpful and pick the stage you most likely meant for each subcommand.
111111
These defaults are as follows:
112112

113113
- `check`: `--stage 0`
@@ -152,7 +152,7 @@ bootstrapping the compiler.
152152

153153
This is a detailed look into the separate bootstrap stages.
154154

155-
The convention `x.py` uses is that:
155+
The convention `x` uses is that:
156156

157157
- A `--stage N` flag means to run the stage N compiler (`stageN/rustc`).
158158
- A "stage N artifact" is a build artifact that is _produced_ by the stage N compiler.
@@ -161,7 +161,7 @@ The convention `x.py` uses is that:
161161

162162
#### Build artifacts
163163

164-
Anything you can build with `x.py` is a _build artifact_.
164+
Anything you can build with `x` is a _build artifact_.
165165
Build artifacts include, but are not limited to:
166166

167167
- binaries, like `stage0-rustc/rustc-main`
@@ -243,7 +243,7 @@ artifacts into the appropriate place, skipping the cargo invocation.
243243
For instance, you might want to build an ARM version of rustc using an x86 machine.
244244
Building stage2 `std` is different when you are cross-compiling.
245245

246-
This is because `x.py` uses a trick: if `HOST` and `TARGET` are the same,
246+
This is because `x` uses a trick: if `HOST` and `TARGET` are the same,
247247
it will reuse stage1 `std` for stage2! This is sound because stage1 `std`
248248
was compiled with the stage1 compiler, i.e. a compiler using the source code
249249
you currently have checked out. So it should be identical (and therefore ABI-compatible)
@@ -362,7 +362,7 @@ You can find more discussion about sysroots in:
362362

363363
## Passing flags to commands invoked by `bootstrap`
364364

365-
`x.py` allows you to pass stage-specific flags to `rustc` and `cargo` when bootstrapping.
365+
`x` allows you to pass stage-specific flags to `rustc` and `cargo` when bootstrapping.
366366
The `RUSTFLAGS_BOOTSTRAP` environment variable is passed as `RUSTFLAGS` to the bootstrap stage
367367
(stage0), and `RUSTFLAGS_NOT_BOOTSTRAP` is passed when building artifacts for later stages.
368368
`RUSTFLAGS` will work, but also affects the build of `bootstrap` itself, so it will be rare to want
@@ -395,7 +395,7 @@ If `./stageN/bin/rustc` gives an error about environment variables, that
395395
usually means something is quite wrong -- or you're trying to compile e.g.
396396
`rustc` or `std` or something that depends on environment variables. In
397397
the unlikely case that you actually need to invoke rustc in such a situation,
398-
you can tell the bootstrap shim to print all env variables by adding `-vvv` to your `x.py` command.
398+
you can tell the bootstrap shim to print all env variables by adding `-vvv` to your `x` command.
399399

400400
Finally, bootstrap makes use of the [cc-rs crate] which has [its own
401401
method][env-vars] of configuring C compilers and C flags via environment
@@ -408,7 +408,7 @@ variables.
408408

409409
In this part, we will investigate the build command's stdout in an action
410410
(similar, but more detailed and complete documentation compare to topic above).
411-
When you execute `x.py build --dry-run` command, the build output will be something
411+
When you execute `x build --dry-run` command, the build output will be something
412412
like the following:
413413

414414
```text

src/building/compiler-documenting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ like the standard library (std) or the compiler (rustc).
3636
- Document internal rustc items
3737

3838
Compiler documentation is not built by default.
39-
To create it by default with `x.py doc`, modify `config.toml`:
39+
To create it by default with `x doc`, modify `config.toml`:
4040

4141
```toml
4242
[build]

src/building/how-to-build-and-run.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ of a checkout. It also looks up the appropriate version of `python` to use.
108108

109109
You can install it with `cargo install --path src/tools/x`.
110110

111+
Using `x` rather than `x.py` is recommended as:
112+
113+
> `./x` is the most likely to work on every system (on Unix it runs the shell script
114+
> that does python version detection, on Windows it will probably run the
115+
> powershell script - certainly less likely to break than `./x.py` which often just
116+
> opens the file in an editor).[^1]
117+
118+
Notice that this is not absolute, for instance, using Nushell in VSCode on Win10,
119+
typing `x` or `./x` still open the `x.py` in editor rather invoke the program :)
120+
121+
In the rest of documents, we use `x` to represent the straightly usage of `x.py`, which
122+
means the following command:
123+
124+
```bash
125+
./x check
126+
```
127+
128+
could been replaced by:
129+
130+
```bash
131+
./x.py check
132+
```
133+
111134
## Create a `config.toml`
112135

113136
To start, run `./x setup` and select the `compiler` defaults. This will do some initialization
@@ -123,9 +146,9 @@ If you have already built `rustc` and you change settings related to LLVM, then
123146
execute `rm -rf build` for subsequent configuration changes to take effect. Note that `./x
124147
clean` will not cause a rebuild of LLVM.
125148

126-
## Common `x.py` commands
149+
## Common `x` commands
127150

128-
Here are the basic invocations of the `x.py` commands most commonly used when
151+
Here are the basic invocations of the `x` commands most commonly used when
129152
working on `rustc`, `std`, `rustdoc`, and other tools.
130153

131154
| Command | When to use it |
@@ -141,9 +164,9 @@ serious development work. In particular, `./x build` and `./x test`
141164
provide many ways to compile or test a subset of the code, which can save a lot
142165
of time.
143166

144-
Also, note that `x.py` supports all kinds of path suffixes for `compiler`, `library`,
145-
and `src/tools` directories. So, you can simply run `x.py test tidy` instead of
146-
`x.py test src/tools/tidy`. Or, `x.py build std` instead of `x.py build library/std`.
167+
Also, note that `x` supports all kinds of path suffixes for `compiler`, `library`,
168+
and `src/tools` directories. So, you can simply run `x test tidy` instead of
169+
`x test src/tools/tidy`. Or, `x build std` instead of `x build library/std`.
147170

148171
[rust-analyzer]: suggested.html#configuring-rust-analyzer-for-rustc
149172

@@ -156,7 +179,7 @@ Note that building will require a relatively large amount of storage space.
156179
You may want to have upwards of 10 or 15 gigabytes available to build the compiler.
157180

158181
Once you've created a `config.toml`, you are now ready to run
159-
`x.py`. There are a lot of options here, but let's start with what is
182+
`x`. There are a lot of options here, but let's start with what is
160183
probably the best "go to" command for building a local compiler:
161184

162185
```bash
@@ -206,7 +229,7 @@ Instead, you can just build using the bootstrap compiler.
206229
./x build --stage 0 library
207230
```
208231

209-
If you choose the `library` profile when running `x.py setup`, you can omit `--stage 0` (it's the
232+
If you choose the `library` profile when running `x setup`, you can omit `--stage 0` (it's the
210233
default).
211234

212235
## Creating a rustup toolchain
@@ -241,7 +264,7 @@ LLVM version: 11.0
241264
```
242265

243266
The rustup toolchain points to the specified toolchain compiled in your `build` directory,
244-
so the rustup toolchain will be updated whenever `x.py build` or `x.py test` are run for
267+
so the rustup toolchain will be updated whenever `x build` or `x test` are run for
245268
that toolchain/stage.
246269

247270
**Note:** the toolchain we've built does not include `cargo`. In this case, `rustup` will
@@ -262,7 +285,7 @@ want to build this component:
262285
## Building targets for cross-compilation
263286

264287
To produce a compiler that can cross-compile for other targets,
265-
pass any number of `target` flags to `x.py build`.
288+
pass any number of `target` flags to `x build`.
266289
For example, if your host platform is `x86_64-unknown-linux-gnu`
267290
and your cross-compilation target is `wasm32-wasi`, you can build with:
268291

@@ -274,7 +297,7 @@ Note that if you want the resulting compiler to be able to build crates that
274297
involve proc macros or build scripts, you must be sure to explicitly build target support for the
275298
host platform (in this case, `x86_64-unknown-linux-gnu`).
276299

277-
If you want to always build for other targets without needing to pass flags to `x.py build`,
300+
If you want to always build for other targets without needing to pass flags to `x build`,
278301
you can configure this in the `[build]` section of your `config.toml` like so:
279302

280303
```toml
@@ -303,9 +326,9 @@ then once you have built your compiler you will be able to use it to cross-compi
303326
cargo +stage1 build --target wasm32-wasi
304327
```
305328

306-
## Other `x.py` commands
329+
## Other `x` commands
307330

308-
Here are a few other useful `x.py` commands. We'll cover some of them in detail
331+
Here are a few other useful `x` commands. We'll cover some of them in detail
309332
in other sections:
310333

311334
- Building things:
@@ -335,3 +358,5 @@ everything up then you only need to run one command!
335358

336359
`rm -rf build` works too, but then you have to rebuild LLVM, which can take
337360
a long time even on fast computers.
361+
362+
[^1]: issue[#1707](https://github.com/rust-lang/rustc-dev-guide/issues/1707)

src/building/suggested.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ You can also install the hook as a step of running `./x setup`!
2626
`rust-analyzer` can help you check and format your code whenever you save
2727
a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt`
2828
commands, but you can override these commands to use more adapted versions
29-
of these tools when hacking on `rustc`. For example, `x.py setup vscode` will prompt
29+
of these tools when hacking on `rustc`. For example, `x setup vscode` will prompt
3030
you to create a `.vscode/settings.json` file which will configure Visual Studio code.
3131
This will ask `rust-analyzer` to use `./x check` to check the sources, and the
3232
stage 0 rustfmt to format them.
3333
The recommended `rust-analyzer` settings live at [`src/etc/rust_analyzer_settings.json`].
3434

35-
If you have enough free disk space and you would like to be able to run `x.py` commands while
35+
If you have enough free disk space and you would like to be able to run `x` commands while
3636
rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the
37-
`overrideCommand` to avoid x.py locking.
37+
`overrideCommand` to avoid x locking.
3838

3939
If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a
4040
`.vim/coc-settings.json` and copy the settings from [`src/etc/rust_analyzer_settings.json`].
@@ -73,7 +73,7 @@ Rust-Analyzer to already be configured with Neovim. Steps for this can be
7373
[found here](https://rust-analyzer.github.io/manual.html#nvim-lsp).
7474

7575
1. First install the plugin. This can be done by following the steps in the README.
76-
2. Run `x.py setup`, which will have a prompt for it to create a `.vscode/settings.json` file.
76+
2. Run `x setup`, which will have a prompt for it to create a `.vscode/settings.json` file.
7777
`neoconf` is able to read and update Rust-Analyzer settings automatically when the project is
7878
opened when this file is detected.
7979

@@ -141,11 +141,11 @@ directories you have [setup a worktree for]. You may need to use the pinned
141141
nightly version from `src/stage0.json`, but often the normal `nightly` channel
142142
will work.
143143

144-
**Note** see [the section on vscode] for how to configure it with this real rustfmt `x.py` uses,
144+
**Note** see [the section on vscode] for how to configure it with this real rustfmt `x` uses,
145145
and [the section on rustup] for how to setup `rustup` toolchain for your bootstrapped compiler
146146

147147
**Note** This does _not_ allow you to build `rustc` with cargo directly. You
148-
still have to use `x.py` to work on the compiler or standard library, this just
148+
still have to use `x` to work on the compiler or standard library, this just
149149
lets you use `cargo fmt`.
150150

151151
[installing a nightly toolchain]: https://rust-lang.github.io/rustup/concepts/channels.html?highlight=nightl#working-with-nightly-rust

src/git.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ You might also notice conflicts in the web UI:
139139
![conflict in src/tools/cargo](./img/submodule-conflicts.png)
140140

141141
The most common cause is that you rebased after a change and ran `git add .` without first running
142-
`x.py` to update the submodules. Alternatively, you might have run `cargo fmt` instead of `x fmt`
142+
`x` to update the submodules. Alternatively, you might have run `cargo fmt` instead of `x fmt`
143143
and modified files in a submodule, then committed the changes.
144144

145145
To fix it, do the following things:
@@ -248,7 +248,7 @@ out if you're using `download-ci-llvm`. To avoid having to keep fetching its hi
248248

249249
Note that, as of <!-- date-check --> Aug 2022,
250250
there is a [bug][#77620] if you use worktrees,
251-
submodules, and `x.py` in a commit hook.
251+
submodules, and `x` in a commit hook.
252252
If you run into an error like the following,
253253
it's not anything you did wrong:
254254

@@ -314,7 +314,7 @@ Generally, resolving the conflict consists of two steps: First, fix the
314314
particular conflict. Edit the file to make the changes you want and remove the
315315
`<<<<<<<`, `=======` and `>>>>>>>` lines in the process. Second, check the
316316
surrounding code. If there was a conflict, its likely there are some logical
317-
errors lying around too! It's a good idea to run `x.py check` here to make sure
317+
errors lying around too! It's a good idea to run `x check` here to make sure
318318
there are no glaring errors.
319319

320320
Once you're all done fixing the conflicts, you need to stage the files that had
@@ -558,7 +558,7 @@ commit, which doesn't change unless modified manually. If you use `git checkout
558558
in the `llvm-project` directory and go back to the `rust` directory, you can stage this
559559
change like any other, e.g. by running `git add src/llvm-project`. (Note that if
560560
you *don't* stage the change to commit, then you run the risk that running
561-
`x.py` will just undo your change by switching back to the previous commit when
561+
`x` will just undo your change by switching back to the previous commit when
562562
it automatically "updates" the submodules.)
563563

564564
This version selection is usually done by the maintainers of the project, and

src/profiling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension in LLVM bitcode format.
4141
Example usage:
4242
```
4343
cargo install cargo-llvm-lines
44-
# On a normal crate you could now run `cargo llvm-lines`, but `x.py` isn't normal :P
44+
# On a normal crate you could now run `cargo llvm-lines`, but `x` isn't normal :P
4545
4646
# Do a clean before every run, to not mix in the results from previous runs.
4747
./x clean

src/profiling/wpa_profiling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ we'll need to build a stage 1 compiler and then a stage 2 compiler ourselves.
4747
To do this, make sure you have set `debuginfo-level = 1` in your `config.toml` file. This tells
4848
rustc to generate debug information which includes stack frames when bootstrapping.
4949

50-
Now you can build the stage 1 compiler: `python x.py build --stage 1 -i library` or however
50+
Now you can build the stage 1 compiler: `x build --stage 1 -i library` or however
5151
else you want to build the stage 1 compiler.
5252

5353
Now that the stage 1 compiler is built, we can record the stage 2 build. Go back to WPR, click the
54-
"start" button and build the stage 2 compiler (e.g., `python x build --stage=2 -i library`).
54+
"start" button and build the stage 2 compiler (e.g., `x build --stage=2 -i library`).
5555
When this process finishes, stop the recording.
5656

5757
Click the Save button and once that process is complete, click the "Open in WPA" button which

src/rustdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
4141

4242
## Cheat sheet
4343

44-
* Run `./x setup tools` before getting started. This will configure `x.py`
44+
* Run `./x setup tools` before getting started. This will configure `x`
4545
with nice settings for developing rustdoc and other tools, including
4646
downloading a copy of rustc rather than building it.
4747
* Use `./x check src/tools/rustdoc` to quickly check for compile errors.

src/tests/compiletest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ set a baseline for optimizations:
330330

331331
The test should be annotated with `// EMIT_MIR` comments that specify files that
332332
will contain the expected MIR output.
333-
You can use `x.py test --bless` to create the initial expected files.
333+
You can use `x test --bless` to create the initial expected files.
334334

335335
There are several forms the `EMIT_MIR` comment can take:
336336

src/tests/headers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ The following header commands will check rustc build settings and target setting
145145
(AddressSanitizer, hardware-assisted AddressSanitizer, LeakSanitizer,
146146
MemorySanitizer or ThreadSanitizer respectively)
147147
* `needs-run-enabled` — ignores if it is a test that gets executed, and
148-
running has been disabled. Running tests can be disabled with the `x.py test
148+
running has been disabled. Running tests can be disabled with the `x test
149149
--run=never` flag, or running on fuchsia.
150150
* `needs-unwind` — ignores if the target does not support unwinding
151151
* `needs-rust-lld` — ignores if the rust lld support is not enabled

src/tests/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The [Compiletest chapter][compiletest] goes into detail on how to use this tool.
2929
The standard library and many of the compiler packages include typical Rust `#[test]`
3030
unit tests, integration tests, and documentation tests.
3131
You can pass a path to `x.py` to almost any package in the `library` or `compiler` directory,
32-
and `x.py` will essentially run `cargo test` on that package.
32+
and `x` will essentially run `cargo test` on that package.
3333

3434
Examples:
3535

src/tests/running.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- toc -->
44

5-
You can run the tests using `x.py`. The most basic command – which
5+
You can run the tests using `x`. The most basic command – which
66
you will almost never want to use! – is as follows:
77

88
```bash
@@ -122,7 +122,7 @@ But unfortunately, it's impossible. You should invoke following instead:
122122
Another common thing that people want to do is to run an **individual
123123
test**, often the test they are trying to fix. As mentioned earlier,
124124
you may pass the full file path to achieve this, or alternatively one
125-
may invoke `x.py` with the `--test-args` option:
125+
may invoke `x` with the `--test-args` option:
126126

127127
```bash
128128
./x test tests/ui --test-args issue-1234
@@ -247,7 +247,7 @@ pong
247247
```
248248

249249
To run tests using the remote runner, set the `TEST_DEVICE_ADDR` environment
250-
variable then use `x.py` as usual. For example, to run `ui` tests for a RISC-V
250+
variable then use `x` as usual. For example, to run `ui` tests for a RISC-V
251251
machine with the IP address `1.2.3.4` use
252252
```sh
253253
export TEST_DEVICE_ADDR="1.2.3.4:12345"
@@ -273,7 +273,7 @@ run "/tmp/work/test1018/a"
273273
[...]
274274
```
275275

276-
Tests are built on the machine running `x.py` not on the remote machine. Tests
276+
Tests are built on the machine running `x` not on the remote machine. Tests
277277
which fail to build unexpectedly (or `ui` tests producing incorrect build
278278
output) may fail without ever running on the remote machine.
279279

src/tests/ui.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ Then, it applies the suggestion and compares against `.fixed` (they must match).
485485
Finally, the fixed source is compiled, and this compilation is required to succeed.
486486

487487
Usually when creating a rustfix test you will generate the `.fixed` file
488-
automatically with the `x.py test --bless` option.
488+
automatically with the `x test --bless` option.
489489

490490
The `run-rustfix` header will cause *all* suggestions to be applied, even
491491
if they are not [`MachineApplicable`](../diagnostics.md#suggestions).

0 commit comments

Comments
 (0)