Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2024 07:36:46 -0600
From:      Alan Somers <asomers@freebsd.org>
To:        ske-89@pkmab.se
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: The Case for Rust (in the base system)
Message-ID:  <CAOtMX2jxm_BCbMKWqypTyoYPJio=AEYVTWNs-pGHxaifKRaBSA@mail.gmail.com>
In-Reply-To: <202409031503.aa12667@berenice.pkmab.se>
References:  <202409031131.483BVdax004602@critter.freebsd.dk> <202409031503.aa12667@berenice.pkmab.se>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Sep 3, 2024 at 7:04=E2=80=AFAM <ske-89@pkmab.se> wrote:
>
> With all this talk about Rust in the OS kernels, can someone
> explain to me why Rust can't simply produce object files that
> can be linked into the kernel like any C object file? (If you
> just avoid calling Rust-specific libraries, just like you don't
> call the C standard library either from within the kernel.)
>
> I haven't worked with Rust, and the introductions to Rust that
> I have read do not discuss this.
>
> /Kristoffer Eriksson

Actually, it can.  You have to take some precautions, of course: many
3rd party libraries are off limits, as is much of the standard
library.  You must disable the usual panic mechanism.  You need to
declare that your module's public API uses the C calling convention.
Probably the biggest limitation is that you can't use the standard
memory allocator.  But you absolutely can do it.  For example:
https://github.com/spookyvision/hello-freebsd-rust .

One of the most interesting features of Rust is #![no_std] .  If you
declare that in your library, then none of the standard library will
be available.  However, there are a dozen or so primitives like memory
allocation and panic handling.  If you implement some of those, then
any parts of the standard library that depend on them will be
available again.  And if you implement all of them, then you can use
virtually the entire standard library.  It's a nice bridge between the
regular world and the embedded world.

-Alan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2jxm_BCbMKWqypTyoYPJio=AEYVTWNs-pGHxaifKRaBSA>