rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Amy Parker <apark0006@student.cerritos.edu>
Cc: rust-for-linux <rust-for-linux@vger.kernel.org>,
	Miguel Ojeda <ojeda@kernel.org>
Subject: Re: Question about compilation
Date: Thu, 21 Oct 2021 19:02:29 +0200	[thread overview]
Message-ID: <CANiq72n-VjdRdT3Lgk3Yni4QYN5tzNHV7_yN_XUaUFRJkZNexA@mail.gmail.com> (raw)
In-Reply-To: <CAPOgqxGvV3n5eC6kvU1uRXCOpxpz8n-rwVZZ5Q3eXcKVH_h4GA@mail.gmail.com>

On Thu, Oct 21, 2021 at 3:56 AM Amy Parker
<apark0006@student.cerritos.edu> wrote:
>
> So how do the Rust versions get linked over the C editions? How does
> it become that the Rust variant is the one actually executing at
> runtime?

If you are asking about the code inside `rust/`, then there is no
override happening, i.e. that code is, for the most part, not a
substitute for C code. Instead, they are wrappers ("abstractions")
over the C APIs so that other Rust code (outside `rust/`) can safely
use those facilities (for the most part). For instance,
`rust/kernel/sync/mutex.rs` is implemented using the C `struct mutex`.

If you are asking about code outside `rust/`, e.g. a driver module,
then yes, you may have a substitute for a C one. For that, you can use
Kconfig as usual (e.g. via separate option, or with a sub-option
toggle if they are exclusive or perhaps a `choice`, etc.). So no
special magic here -- an `.rs` file in e.g. `obj-y` will get compiled
as the root crate for your module.

Hope that clarifies!

Cheers,
Miguel

      reply	other threads:[~2021-10-21 17:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20 22:56 Question about compilation Amy Parker
2021-10-20 23:24 ` Miguel Ojeda
2021-10-21  1:55   ` Amy Parker
2021-10-21 17:02     ` Miguel Ojeda [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANiq72n-VjdRdT3Lgk3Yni4QYN5tzNHV7_yN_XUaUFRJkZNexA@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=apark0006@student.cerritos.edu \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).