# \`cargo x\` for rustc dev

**URL:** <https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172>\
**Category:** Uncategorized\
**Created:** [February 18, 2022, 9:02pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172 "2022-02-18T21:02:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [February 18, 2022, 9:02pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/1 "2022-02-18T21:02:03Z")

</div>

In the vein of [Make your own make](https://matklad.github.io//2018/01/03/make-your-own-make.html) (@matklad) and [`cargo xtask`](https://github.com/matklad/cargo-xtask)...

(Disclaimer: it's been a good while since I've compiler hacked)

As I currently understand it, `x.py`'s job is to download the bootstrap compiler (the most recent beta?) and run the bootstrap crate, which then handles the rest of nearly everything `x.py` does. (The python side may handle some early outs for some things to avoid the compiler download.)

The eventual pie-in-the-sky goal for stdlib dev at least (which doesn't need _as much_ of a bootstrap as the compiler or core) is for `cargo build` to just work, given an appropriate (nightly or `RUSTC_BOOTSTRAP`) default cargo/rustc version. (We could even provide a `rustup-toolchain.toml` to have rustup manage the "bootstrap version" here.)

In the shorter term, though, perhaps we could make `x` runnable with rustup cargo via a cargo alias of `cargo x`? Or is that not possible for reasons I'm missing?

---

<div class="post-metadata">

**Author:** ![chrisd](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/chrisd/32/7232_2.png) [@chrisd](https://internals.rust-lang.org/u/chrisd)\
**Post date:** [February 18, 2022, 9:23pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/2 "2022-02-18T21:23:02Z")

</div>

We already have the [x binary](https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#running-xpy-slightly-more-conveniently) and custom cargo commands are just [`cargo-something`](https://doc.rust-lang.org/book/ch14-05-extending-cargo.html). So `cargo-x` should work right now if you rename `x` and it's added to `PATH`?

The way x is installed right now is:

`cargo install --path src/tools/x`

We could maybe change that to:

`cargo install --path src/tools/cargo-x`

[note: this is all hypothetical, I haven't actually tested any of this]

---

<div class="post-metadata">

**Author:** ![jkugelman](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jkugelman/32/8572_2.png) [@jkugelman](https://internals.rust-lang.org/u/jkugelman)\
**Post date:** [February 18, 2022, 9:26pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/3 "2022-02-18T21:26:11Z")

</div>

Why is it named `x.py`, anyway? How about `cargo bootstrap` for this new feature?

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [February 18, 2022, 10:31pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/4 "2022-02-18T22:31:07Z")

</div>

> [@jkugelman](#):
>
> Why is it named `x.py` , anyway?

`x` is short and stands for "execute". It's actually kind of interesting...

`/src/tools/x` is a rust binary to execute `/x.py` from anywhere in a rust-lang/rust checkout.

`/x.py` is a python pseudo symlink to `/src/bootstrap/bootstrap.py`.

`/src/bootstrap/bootstrap.py` is a python script to download the bootstrap compiler and use it to build and run the rust crate `/src/bootstrap`, which does the actual work of managing the bootstrap process.

I'm curious in the practicality of skipping this process, and building and running the `/src/bootstrap` crate with a rustup managed toolchain, rather than one managed by `/src/bootstrap/bootstrap.py`.

Obviously the rustup toolchain has to be recent enough (I believe beta?) but that seems reasonable enough of a requirement. The part which I don't know specifically is whether the rustbuild setup gets in the way of allowing `cargo x` to `cargo run --manifest-path src/bootstrap/Cargo.toml --all --of --the --other --flags`. I suppose one could be that the build dir is set in `config.toml`, which wouldn't be usable in the xtask pattern.

---

<div class="post-metadata">

**Author:** ![chrisd](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/chrisd/32/7232_2.png) [@chrisd](https://internals.rust-lang.org/u/chrisd)\
**Post date:** [February 18, 2022, 11:01pm UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/5 "2022-02-18T23:01:35Z")

</div>

I mean, it shouldn't really matter how "cargo-x" is implemented? That can change under the hood at any time. Cargo subcommands are literally just any old executable with a magic "cargo-" prefix.

And jyn514 has been doing some good work (e.g. [#92260](https://github.com/rust-lang/rust/pull/92260)) to move more logic from python to rust. I think it basically just needs more people help out.

---

<div class="post-metadata">

**Author:** ![tschuett](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tschuett/32/8380_2.png) [@tschuett](https://internals.rust-lang.org/u/tschuett)\
**Post date:** [February 19, 2022, 12:25am UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/6 "2022-02-19T00:25:35Z")

</div>

Is it possible to maintain a `rust-toolchain.toml` at the top and use the standard cargo build/run workflow?

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [February 19, 2022, 7:58am UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/7 "2022-02-19T07:58:37Z")

</div>

x.py now verifies the hashes of bootstrap toolchain components. This is something rustup can't do. x.py also has git submodule handling as cargo refuses to build anything inside a workspace if any git submodule part of the workspace is not yet initialized.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [May 20, 2022, 7:59am UTC](https://internals.rust-lang.org/t/cargo-x-for-rustc-dev/16172/8 "2022-05-20T07:59:29Z")

</div>

Closed on May 20, 2022, 7:59am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
