

Bootstrapping Rust - bluehex
http://aidancully.blogspot.com/2014/12/bootstrapping-rust.html

======
JonathonW
How important is breaking the circular dependency for the compiler, really?

To use a more common language and tool as an example: I can't build GCC
without already having a working C++ compiler. Granted, GCC will accept any
reasonably conformant C++98 compiler, but still... If I'm bootstrapping GCC on
Linux (or almost any other major *nix), that compiler's almost always going to
be another copy of GCC.

If getting started with Rust on another platform is indeed so difficult, I'd
think it would be a better use of their resources to make sure that cross-
compilation is functional, rather than messing around with distributing LLVM
IR and stuff. If I'm building a C/C++ build environment for a new platform, a
cross-compile of my tools is probably how I'd start.

~~~
jensnockert
Cross-compilation is functional, and it's how you would bootstrap it. But in
theory you could also bootstrap from the old compiler written in ocaml, but
that would take ages due to needing a gazillion builds of rustc.

~~~
kibwen
We can determine exactly how many builds you'd need by looking at the master
snapshot file: [https://github.com/rust-
lang/rust/blob/master/src/snapshots....](https://github.com/rust-
lang/rust/blob/master/src/snapshots.txt)

According to this, there have been 290 snapshots in total. And keep in mind
that you would also need to rebuild LLVM quite a few times as well during this
process, as Rust has continually upgraded its custom LLVM fork over the years.

------
aidenn0
"The dependency of the compiler on itself can be broken by distributing the
bootstrap compiler as LLVM IR code. Then use LLVM's IR assembler, and other
tools, to re-link the stage0 Rust compiler on the target platform."

LLVM IR is target architecture dependent, so it's not portable between machine
types.

~~~
Ygg2
That seems contrary to what IR is supposed to do and how LLLVM was designed.
Any links or explanations?

~~~
Rusky
LLVM IR isn't supposed to be target independent in any way. It's an internal
representation for a compiler backend- it has to be able to represent target-
specific semantics at some point.

------
rejschaap
I managed to build the rust compiler with a little effort on FreeBSD. I
thought I was home free, but when I tried to build Cargo it insisted on
downloading and building the rust compiler itself (which fails, obviously). So
I was more than a little dissapointed after going through the trouble of
getting the compiler working and I gave up on cargo.

I'm hacking away happily with rust now though, I quite like it so far and am
curious to see where it will go from here.

~~~
Argorak
This is an unfortunate situation currently, but better then the alternative.
cargo doesn't tie into the rust compiler (just uses it as a program it calls),
but it wants to be always available. Because of that, it builds with a known-
good version of Rust to make sure `cargo` can be used in the most recent
version on all (supported) platforms. This is due to the instability of Rust.

Before that, cargo was always broken, if you didn't have the correct version
for building it.

This will certainly change once Rust stable released.

As all things Rust, the whole ecosystem still has a huge label "in
construction". The things that are supported and intended to be kept stable
are quite stable, though!

------
kibwen
As others have mentioned, Rust does indeed support cross-compilation (and has
from day one). Sadly we still need to document it fully, though our spotty
docs haven't stopped community members from getting Rust code running on
FreeBSD and iOS and all sorts of ARM things. For the moment it may be
enlightening to read the recently-implemented Flexible Target Specification
RFC ([https://github.com/rust-
lang/rfcs/blob/master/text/0131-targ...](https://github.com/rust-
lang/rfcs/blob/master/text/0131-target-specification.md)), which you may have
seen in action via Rust on the PSP ([https://github.com/luqmana/rust-psp-
hello](https://github.com/luqmana/rust-psp-hello)).

