rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question about compilation
@ 2021-10-20 22:56 Amy Parker
  2021-10-20 23:24 ` Miguel Ojeda
  0 siblings, 1 reply; 4+ messages in thread
From: Amy Parker @ 2021-10-20 22:56 UTC (permalink / raw)
  To: rust-for-linux; +Cc: ojeda

Hello! I'm (somewhat) new to Rust for Linux.

Where/how do the Rust parts of the kernel on the Rust tree get
compiled in? I don't see a Kconfig for `rust/`, and I can't seem to
trace how they get controlled elsewhere. If there's any explanations
or guides on how this is done for substituting in Rust, please let me
know! I've been trying to figure it out as I'm aiming to translate a C
module into Rust.

Thank you so much!


    - amyip

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question about compilation
  2021-10-20 22:56 Question about compilation Amy Parker
@ 2021-10-20 23:24 ` Miguel Ojeda
  2021-10-21  1:55   ` Amy Parker
  0 siblings, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2021-10-20 23:24 UTC (permalink / raw)
  To: Amy Parker; +Cc: rust-for-linux, Miguel Ojeda

Hi Amy,

On Thu, Oct 21, 2021 at 12:56 AM Amy Parker
<apark0006@student.cerritos.edu> wrote:
>
> Where/how do the Rust parts of the kernel on the Rust tree get
> compiled in? I don't see a Kconfig for `rust/`, and I can't seem to
> trace how they get controlled elsewhere. If there's any explanations
> or guides on how this is done for substituting in Rust, please let me
> know! I've been trying to figure it out as I'm aiming to translate a C
> module into Rust.

There is no individual control at the moment, i.e. if you have a
feature enabled in the kernel, it will get enabled for C as well as
for Rust (if Rust support is enabled).

Then we use conditional compilation in the `kernel` crate, e.g.
`#[cfg(CONFIG_FOO)]` may guard a `pub mod foo;`.

Note that the organization of what is now the `kernel` crate (and its
bindings) may change in the future, e.g. we may move to a model where
subsystems have the Rust code in their folders etc.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question about compilation
  2021-10-20 23:24 ` Miguel Ojeda
@ 2021-10-21  1:55   ` Amy Parker
  2021-10-21 17:02     ` Miguel Ojeda
  0 siblings, 1 reply; 4+ messages in thread
From: Amy Parker @ 2021-10-21  1:55 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: rust-for-linux, Miguel Ojeda

Hi!

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?

Thank you so much Miguel!

    - amyip

On Wed, Oct 20, 2021 at 4:24 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> Hi Amy,
>
> On Thu, Oct 21, 2021 at 12:56 AM Amy Parker
> <apark0006@student.cerritos.edu> wrote:
> >
> > Where/how do the Rust parts of the kernel on the Rust tree get
> > compiled in? I don't see a Kconfig for `rust/`, and I can't seem to
> > trace how they get controlled elsewhere. If there's any explanations
> > or guides on how this is done for substituting in Rust, please let me
> > know! I've been trying to figure it out as I'm aiming to translate a C
> > module into Rust.
>
> There is no individual control at the moment, i.e. if you have a
> feature enabled in the kernel, it will get enabled for C as well as
> for Rust (if Rust support is enabled).
>
> Then we use conditional compilation in the `kernel` crate, e.g.
> `#[cfg(CONFIG_FOO)]` may guard a `pub mod foo;`.
>
> Note that the organization of what is now the `kernel` crate (and its
> bindings) may change in the future, e.g. we may move to a model where
> subsystems have the Rust code in their folders etc.
>
> Cheers,
> Miguel



-- 
Amy Iris Parker
Please refer to me using she/her pronouns.
CIS Major
Dual Enrollment with WHS co2025

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question about compilation
  2021-10-21  1:55   ` Amy Parker
@ 2021-10-21 17:02     ` Miguel Ojeda
  0 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2021-10-21 17:02 UTC (permalink / raw)
  To: Amy Parker; +Cc: rust-for-linux, Miguel Ojeda

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-21 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).