Tool for executing `rustc` based on your current directory


#1

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:

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?


#2

@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.