rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] rust: crates in other kernel directories
@ 2023-10-06 15:57 Martin Rodriguez Reboredo
  2023-10-06 15:57 ` [RFC PATCH 1/1] scripts: Build per module Rust crates Martin Rodriguez Reboredo
  2023-10-06 21:13 ` [RFC PATCH 0/1] rust: crates in other kernel directories Miguel Ojeda
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-10-06 15:57 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, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: rust-for-linux, llvm

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.

For now I don't have a completely working example but I have an MWE as
following...

    # Add this line to drivers/usb/core/Kconfig
    config USB_RUST
    	bool "Rust USB bindings"
    	depends on USB && RUST
    	default n
    	help
    	  Enables Rust bindings for USB.

    # Add this line to drivers/usb/core/Makefile
    usbcore-$(CONFIG_USB_RUST)		+= usb.rlib

    # Create this file drivers/usb/core/usb.rs
    // SPDX-License-Identifier: GPL-2.0
    
    //! USB devices and drivers.
    //!
    //! C header: [`include/linux/usb.h`](../../../../include/linux/usb.h)
    
    use kernel::bindings;
    
    /// Check if USB is disabled.
    pub fn disabled() -> bool {
        // SAFETY: FFI call.
        unsafe { bindings::usb_disabled() != 0 }
    }

    # Compile the .rlib with
    make drivers/usb/core/usb.rlib LLVM=1

If everything went well then you should have
`drivers/usb/core/usb.rlib` ready to be linked.

As of now this PR won't compile the kernel fully as it serves as an
starting point and it's going to change in the future.

Martin Rodriguez Reboredo (1):
  scripts: Build per module Rust crates

 Makefile               |  4 ++--
 scripts/Makefile.build | 10 +++++++++-
 scripts/Makefile.lib   | 19 +++++++++++++------
 3 files changed, 24 insertions(+), 9 deletions(-)

-- 
2.42.0


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

end of thread, other threads:[~2023-10-23  0:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 15:57 [RFC PATCH 0/1] rust: crates in other kernel directories Martin Rodriguez Reboredo
2023-10-06 15:57 ` [RFC PATCH 1/1] scripts: Build per module Rust crates Martin Rodriguez Reboredo
2023-10-22 16:21   ` Masahiro Yamada
2023-10-22 16:30     ` Miguel Ojeda
2023-10-23  0:45     ` Martin Rodriguez Reboredo
2023-10-06 21:13 ` [RFC PATCH 0/1] rust: crates in other kernel directories Miguel Ojeda
2023-10-06 23:07   ` Martin Rodriguez Reboredo
2023-10-09 12:01     ` Miguel Ojeda
2023-10-22 18:19       ` Masahiro Yamada

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