Learning to build+preserve a x-compile toolchain

Hello! TL;DR I'm learning how to build+preserve the Rust toolchain supply-chain for 10+ years. I'm climbing the learning curve and could use a push in the right direction.

Here's the problem I need to solve: building+preserving the rust toolchain. I'd like to bring Rust into our product development portfolio (embedded Linux product line). We always in-house our software supply chain. We use offline build servers. We have a local mirror of Python, JS, etc, software repositories.

We need to be able to build the toolchain and preserve all the artifacts so we can build the toolchain again 10+ years from now. Silly example, if leftpad-rs has a CVE three years from now, we need to be able to integrate only that fix into our toolchain.

We use C/C++ compilers from our chipset vendors. Sometimes we build our own gcc from tarballs using crosstool (and then stash the tarballs and scripts into cold storage). So I need to use our x-compiler to build the Rust x-compiler.

I can't do something as simple as 'run rust-cross and tarball the binary blobs because we need to be able to selectively update the toolchain in the future.

The steps I've taken so far: I'm building rust from source using the instructions How to build and run the compiler - Rust Compiler Development Guide I'm reading Adding a new target - Rust Compiler Development Guide on adding a new target so we can use our chipset vendor C/C++ compiler to Build All the Things.

Am I on the right track with the Build A New Target docs? Or is this an already solved problem? I haven't been able to find much online about this sort of problem with Rust.

Many thanks!

rustc is written in Rust, not C. Therefore, you need a rustc to build rustc. However, every rustc is capable of cross-compilation, so this is all you need — the same rustc can be used for your embedded development and for building new rustcs. Therefore, a possible workflow is:

  1. Obtain a toolchain (rustc, cargo, etc.) from rust-lang.org. Archive this.
  2. Use that toolchain to build a new toolchain (this confirms that you are able to apply patches).
  3. Use your newly built toolchain for development.

Then, if you find that you need to apply a patch to the compiler, you can repeat steps 2 and 3, using either the official toolchain or your newly built toolchain to build the compiler.

You might be on the right track in that adding support for your chipset may involve adding a new target, but I don’t think your chipset vendor’s C/C++ compiler will help you build Rust code. You might use the vendor’s linker, though.

Thank you! I've pulled down https://static.rust-lang.org/dist/rustc-1.95.0-src.tar.xz

I'm going through the instructions. I think I need to learn more about the whole process works before I can find more specific questions.