Re: [TECH TOPIC] Rust for Linux

Miguel Ojeda
2021-07-07T15:28:46Z

On Wed, Jul 7, 2021 at 4:32 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> I suppose using this for building kernels is actually easier than doing
> an architecture port for user space, because it does not have to
> wrap the syscall interface, right?

What do you mean by architecture port? Do you mean native vs. cross-compiling?

> I've had a quick look at what it would take to integrate this into the prebuilt
> toolchains on kernel.org to give developers the chance to try their rust
> code across architectures. I've managed to cross-build the patched
> gcc sources for rustc_codegen_gcc, but haven't actually figured out how
> to build rustc_codegen_gcc itself.

I discussed with Konstantin a while back about having the Rust
toolchain in kernel.org too -- so I am glad you are looking into this.

On `rustc_codegen_gcc`, it is early days -- I think all these projects
just got accelerated a lot thanks to the possibility of Rust being in
the kernel. But you can find information on this Compiler Explorer
issue because they are also trying to set it up [1]. The author looks
quite open to help us, so you may want to contact him too.

[1] https://github.com/compiler-explorer/compiler-explorer/issues/2683

> Before I look at this further, can you clarify what the version dependencies
> are? I.e. if I want to build this for five gcc versions, 27 target
> architectures,
> and seven versions of rustc as shipped by the most common distros, can
> I do this with a single rustc_codegen_gcc binary, or do I need to build
> 5*27*7=945 versions of the binary, or something inbetween?

I have not yet used `rustc_codegen_gcc` since it is not ready for our
purposes. But:

- Only a single version of `rustc` is supported per kernel release
(until we stop using unstable features), so that at the very least
would cut down things by 7.

- I would imagine the patched GCC of `rustc_codegen_gcc` only
supports the latest GCC release, do we really want to try to use it in
all GCC versions supported by the kernel? Of course, it would be great
if that means we can support Rust everywhere, do not get me wrong!

- I don't know how stable the `libgccjit` interface is -- if it is,
then we only need a single one, as you say. I would ask the author.

- We could try to get upstream GCC to accept the patches needed to
make `rustc_codegen_gcc` work, though I am not sure how well they
would be received, since they are working on their GCC Rust frontend
too.

Cheers,
Miguel