rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/2] rust: crates in other kernel directories
@ 2023-10-27  0:34 Martin Rodriguez Reboredo
  2023-10-27  0:34 ` [RFC PATCH v2 1/2] kbuild: Build Rust crates as libraries Martin Rodriguez Reboredo
  2023-10-27  0:34 ` [RFC PATCH v2 2/2] samples: rust: Add USB sample bindings Martin Rodriguez Reboredo
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-10-27  0:34 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl
  Cc: linux-kbuild, linux-kernel, rust-for-linux

This RFC provides makes possible to have bindings for kernel subsystems
that are compiled as modules.

Previously, if you wanted to have Rust bindings for a subsystem, like
AMBA for example, you had to put it under `rust/kernel/` so it came
part of the `kernel` crate, but this came with many downsides. Namely
if you compiled said subsystem as a module you've a dependency on it
from `kernel`, which is linked directly on `vmlinux`.

So instead of overpopulating `kernel` with a gazillion modules that
throws you into dire straits you should rather have the bindings in the
same directory as the subsystem you want to bind with and link it to
it.

With this patch Rust sources can be compiled into libraries for them to
be consumed. These libraries are ar archives that follow the `.rlib`
structure, namely a libfoo.rlib thin archive with a foo.foo.o object
and a libfoo.rmeta rustc metadata as members. Such Rust crates get
their symbols exposed and the `bindings` crate is made available for
them.

Also included there's a sample usage of this in another patch, but it
is not meant to be merged as it remains as an example.

If you want to use a crate with your Rust module just add a `rust-libs`
variable in your Makefile with a value of the relative directory of
said crate plus its name, e.g.

    # Link with the foo crate
    rust-libs += ../path/to/foo

Martin Rodriguez Reboredo (2):
  kbuild: Build Rust crates as libraries
  samples: rust: Add USB sample bindings

 .gitignore                      |  2 ++
 Makefile                        |  4 +--
 drivers/usb/core/Kconfig        |  7 +++++
 drivers/usb/core/Makefile       |  3 ++
 drivers/usb/core/usb.rs         | 13 +++++++++
 samples/rust/Kconfig            | 10 +++++++
 samples/rust/Makefile           |  3 ++
 samples/rust/rust_usb_simple.rs | 22 +++++++++++++++
 scripts/Makefile.build          | 49 ++++++++++++++++++++++++++++++---
 scripts/Makefile.lib            | 18 ++++++++++--
 scripts/Makefile.modfinal       |  7 ++++-
 11 files changed, 128 insertions(+), 10 deletions(-)
 create mode 100644 drivers/usb/core/usb.rs
 create mode 100644 samples/rust/rust_usb_simple.rs

-- 
2.42.0


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

end of thread, other threads:[~2023-10-27 13:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27  0:34 [RFC PATCH v2 0/2] rust: crates in other kernel directories Martin Rodriguez Reboredo
2023-10-27  0:34 ` [RFC PATCH v2 1/2] kbuild: Build Rust crates as libraries Martin Rodriguez Reboredo
2023-10-27  0:34 ` [RFC PATCH v2 2/2] samples: rust: Add USB sample bindings Martin Rodriguez Reboredo
2023-10-27  3:21   ` Martin Rodriguez Reboredo
2023-10-27  7:15   ` Greg Kroah-Hartman
2023-10-27 13:07     ` Martin Rodriguez Reboredo
2023-10-27 13:08   ` Greg Kroah-Hartman

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).