The key sauce: a brand new Rust code generator
One key to delivering production-grade Home windows software program with Rust is a brand new code technology device for Rust’s compiler, rustc. rustc is designed to make use of completely different code-generation again ends, past the default LLVM. There are already variants that work with GCC and with Cranelift. For those who’ve not come throughout Cranelift, it’s the code generator of the Bytecode Alliance, used as a part of the wasmtime framework. Including a brand new code generator is a matter of constructing a device that connects to the Rust compiler’s APIs, takes its bytecode output, generates native code, and passes it on to your selection of construct pipeline.
That is the position of Microsoft’s rustc_codegen_utc tooling. It’s designed to work with the prevailing MSVC stack, giving Rust entry to a mature, well-tested, confirmed a part of the Home windows improvement platform with no need any modifications to your code (compatibility is baked in). This hyperlinks it on to the again finish of the Visible C++ compiler, a set of instruments marshaled by Microsoft’s construct system to work with advanced initiatives that blend code and libraries.
Microsoft calls this again finish the UTC, for Common Tuple Compiler. You received’t see that identify anyplace, although; the precise code is a DLL, C2.DLL. Code is generated and delivered as .OBJ recordsdata the place it could then be handed to the MSVC linker and delivered as a binary executable. This enables Rust tooling to reap the benefits of the many years of labor Microsoft has put into each its compilers and construct tooling. There’s no want for Microsoft to duplicate that work, making certain that present safety and resilience options carry ahead to the Rust compiler chain. And the ensuing code is appropriate with C and C++ code that has been handed by way of the identical again finish.
