Bootstrapping Rust Considered Harmful

birdculture1 pts0 comments

Bootstrapping Rust Considered Harmful - NTECS Consulting

Have you ever tried to build Rust from source? Why, you might ask?

Maybe because Rust is not available via rustup for your operating system

Maybe because you don't trust binary downloads

Maybe purely out of curiosity

It shouldn't be that hard, right? Well... this article tries to answer that question, and why I think Rust needs to change its bootstrapping process significantly. Before we dive into the details, let's<br>see how long it took me to build Rust 1.81 on DragonFly BSD in comparison to other languages (thanks to R and ggplot2 for the diagram):

Warning : This is a "rant" about Rust! Not the language - Rust is beautiful -<br>but its current implementation. More precisely, it is a rant about the<br>bootstrapping process of Rust's official implementation (not the gcc one) and<br>the huge amount of dependencies that are required to build Rust from source.<br>If you write "minimalist" software - anything that runs on the terminal -<br>please be aware of this "bloat" and consider the possibility of using a less<br>dependency-rich and resource-hungry language - or wait for a more lightweight "gcc" version of<br>Rust. Thank you!

OCaml serves as a reference point in this article, not because it is a better<br>language or anything like that. OCaml is comparably complex, yet its bootstrap<br>process is well implemented: A complete OCaml toolchain can be brought up to<br>life from source in just three minutes using ./configure && make && make<br>install.

Installing Rust from Source

Quoting Rust's README.md<br>about "Installing from Source":

If you really want to install from source (though this is not recommended), see INSTALL.md.

Despite this warning, I download the sources for Rust 1.84.1<br>rustc-1.84.1-src.tar.gz (note that in the figure above I show the build-time for Rust 1.81.1, as I was unable to build Rust 1.84.1). The compressed tarball is negligible 699 MB in size.<br>Hey, would that still fit on a single CD-ROM? No, it would not!

For comparison, OCaml's sources (version 5.4.0) are 6.0 MB compressed, two orders of<br>magnitudes, I hear you cry! Two orders of magnitudes...

To be fair, these 699 MB worth of source code contain all the sources required to build Rust, including some 10 million lines of LLVM code and three different versions of OpenSSL.

Well, it's true. All the sources are included, but not the binary Rust compiler (and the cargo binary), both of which are required to build Rust from<br>source!!! Wait, what? Isn't there a chicken and egg problem? We are actually trying to<br>build Rust from source...!? Yes, there is. Let's talk about this later...

Let's continue and unpack this big beautiful tarball. 2 minutes and 14<br>seconds later, tar xvzf rustc-1.84.1-src.tar.gz finishes. Side note: That's<br>roughly one minute quicker than it would take to build the whole OCaml toolchain on the same machine. The uncompressed source tree is now at 1.9 GB. That's<br>already more bytes than living Indians on this planet.

Let's continue and open up README.md again, this time from the source tree<br>that we just decompressed. It still states that "Building From Source [...]<br>is not recommended [...] see INSTALL.md", but sadly, that INSTALL.md it<br>refers to didn't make it into the tarball. Well, we've already got 1.9 GB worth<br>of source code, so it seems there was not enough space left to include the install document -<br>Prioritiiiiiies! We've told you that building from source is not recommended!

Counting the Lines of Code

Before we start building Rust (something I try to procrastinate), let's "quickly" run cloc on the Rust source<br>tree...

Quickly as in:

... it's still counting the files...

... still counting... aaaaand... still counting...

... over a minute has passed by and it says 351365 text files...

... now it seems to count unique files...

... another two minutes later it says 276326<br>unique files... wow...

... and it's still counting, whatever it is counting, maybe lines this time...

... holy cow, the CPU fan now goes full speed, 7 minutes<br>have passed...

... to be fair, Perl (cloc) might not be the best choice here...

... we'd need tokei implemented in Rust for that...

... 8 minutes have now passed by...

... if this takes longer I might have to plug in the power supply...

... 9 minutes (or 3 times OCaml)... and 3-2-1...

... last offer... 10 minutes and we are done!

That was rather quick, wasn't it? Apart from getting a ton of "Line count, exceeded<br>timeout:" lines and 81443 files ignored, the cloc output is truly impressive:

files<br>language<br>blank<br>comment<br>code

68005<br>Rust<br>1251355<br>2413958<br>20734039

51146<br>C++<br>1435178<br>2396405<br>7685767

71995<br>1083792<br>2936843<br>5724464

...<br>...<br>...<br>...<br>...

19<br>Pest<br>226<br>289<br>849

...<br>...<br>...<br>...<br>...

Brainfuck<br>10

sed

276326<br>SUM<br>6345959<br>10746776<br>50771605

A truely remarkable list of languages! I had to cut 101 lines from the output to make it fit.<br>What the hell is "Pest" and "SnakeMake"??? Haha, at least there are 10 lines of Brainfuck!

Okay, that's a...

rust source from build minutes ocaml

Related Articles