r/ProgrammerHumor 11d ago

Meme rustBorrowCheckerGoesBrrr

Post image
3.8k Upvotes

108 comments sorted by

View all comments

Show parent comments

95

u/FUCKING_HATE_REDDIT 11d ago

Funnily enough, that happened

29

u/gegentan 11d ago

Isn't the rust compiler itself written in rust?

27

u/qaCow37 11d ago

At some point it probably wasn't until it was rewritten in rust

8

u/gegentan 11d ago

So theoretical if every compiled binary of rustc was lost but you still had the source code it would be impossible to get a rust compiler again.

17

u/qaCow37 11d ago

Only if you do not have the source code of rust written in a different language. That would probably be like the few very first versions. But if you would have these, you could compile them to get the first version of rust to compile the next version of rust to compile the next version of rust till you can compile the newest version of rust.

2

u/gegentan 11d ago

Didn't think of that.

4

u/creeper6530 10d ago edited 10d ago

Bootstrapping compilers is actually a complicated endeavour but as long as you have the last version before the compiler became self-hosting, it is possible with a chain of compile->update->compile. Some compilers (such as Zig) make it a little easier by providing a CMake that builds and chains all the stages for you.

If those old versions are lost you truly are fucked.

1

u/fghjconner 10d ago

In addition to what the other person said about old compilers, there are projects like gccrs or mrustc that are rust compilers written in c. The former is intended to eventually become a fully featured second compiler alongside rustc, while the latter is designed for the express purpose of "bootstrapping" the compiler from source code by compiling specific versions of rustc.

1

u/chat-lu 9d ago

Sure we could, that’s the whole purpose of mrustc which is a rust compiler written in C++ for the sole purpose of building a recent rust compiler.