# Tool for executing \`rustc\` based on your current directory

**URL:** <https://internals.rust-lang.org/t/tool-for-executing-rustc-based-on-your-current-directory/5105>\
**Category:** compiler\
**Created:** [April 17, 2017, 10:35am UTC](https://internals.rust-lang.org/t/tool-for-executing-rustc-based-on-your-current-directory/5105 "2017-04-17T10:35:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [April 17, 2017, 10:35am UTC](https://internals.rust-lang.org/t/tool-for-executing-rustc-based-on-your-current-directory/5105/1 "2017-04-17T10:35:03Z")

</div>

I've noticed that when newcomers come to hack on `rustc`, one of the first obstacles they hit is the question of "How do I execute the compiler I just built?" Over the years it seems like every rustc dev has crafted their own custom solution to this. I decided to package up my particular solution (a script I've been using since like 2011...) so that other people could reuse it:

> **[nikomatsakis/rustc-mux](https://github.com/nikomatsakis/rustc-mux)**
>
> A rustup-compatible rustc toolchain that selects which version of \`rustc\` to use based on your local directory. - nikomatsakis/rustc-mux

It's now packaged up as a rustup toolchain, but the basic idea is that -- once you set it up -- you can do `rustc ...` and it will check your current directory, find your current root directory, and execute the rustc that you built. You can select which stage to use via `rustc --stage1` or `rustc --stage2` and so forth.

I'm curious to get feedback before I publicize this more widely. Does this work for people? Is there some better way to do it that I'm just unaware of?

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [April 17, 2017, 1:04pm UTC](https://internals.rust-lang.org/t/tool-for-executing-rustc-based-on-your-current-directory/5105/2 "2017-04-17T13:04:12Z")

</div>

@eddyb points out that one could simply make a toolchain per rustc clone and let rustup do the multiplexing. This seems fine, though it can’t support `--stage1` or `--stage2` unless you make two clones. The main reasons I didn’t do that:

- I have a lot of working directories (typically `rust-[123456789]`) and it would be tedious to have a toolchain (or two) for each one.
- It can’t support the other options easily.
- I’ve had this script lying around for years. =)

But I’m definitely game for a more seamless solution. In my ideal world, there’d be no setup at all, rustup would just know that if you are in a clone of Rust, you probably want to execute the Rust you built. (Or perhaps it would have builtin “magic toolchains” like `stage1` and `stage2`?)

Anyway, I’m open to really any solution, but let’s document some easy setup steps and run with it.

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [March 25, 2019, 8:28am UTC](https://internals.rust-lang.org/t/tool-for-executing-rustc-based-on-your-current-directory/5105/3 "2019-03-25T08:28:23Z")

</div>

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