13
Self-host your compiler, you cowards!
(blog.goodanser.com)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
That's actually a disadvantage of Rust: Because the Rust compiler is written in Rust, it is hard to bootstrap on new platforms. Which is for a systems language used to build kernel device drivers a serious limitation, and also makes it harder to tackle Thompon's "Trusting Trust" problem.
Better to compile the new language to C first, which compiles and runs even on a smart lightbulb.
This does work well. It is how C++ was created, and even some Lisp implementations go this way.
Rustc is built atop llvm, and there's been a lot of work on the GCC front-end. Your comment makes the situation sound worse than it is
I don't see how LLVM helps with bootstrapping.
Yes, it helps with supporting newer platforms, since LLVM is a big project and will probably have support for the new platforms relatively fast.
But as long as any part of the whole process is in rust, it means that you need a rust compiler to build the rust compiler, thus needing to solve the bootstrapping problem.
Of course, every compiler has this issue (even if not self-hosted, you still have to bootstrap the compiler of the language your language is written in).
The only solution for this is to have a compiler-chain where the first level is a simple compiler that can be relatively easily written in the assembly language of the new platform.
EDIT: or of course I could've read any other comment. Of course you can use one of the intermediate representations that are portable to build the first compiler. In which case you don't need a rust compiler, just need LLVM. Makes sense then.