rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Check Rust signatures at compile time
@ 2025-02-28 12:39 Alice Ryhl
  2025-02-28 12:39 ` [PATCH v2 1/5] rust: fix signature of rust_fmt_argument Alice Ryhl
                   ` (7 more replies)
  0 siblings, 8 replies; 29+ messages in thread
From: Alice Ryhl @ 2025-02-28 12:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Miguel Ojeda
  Cc: Petr Mladek, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
	Sergey Senozhatsky, Andrew Morton, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, linux-kernel, rust-for-linux,
	dri-devel, Alice Ryhl

Rust has two different tools for generating function declarations to
call across the FFI boundary:

* bindgen. Generates Rust declarations from a C header.
* cbindgen. Generates C headers from Rust declarations.

In the kernel, we only use bindgen. This is because cbindgen assumes a
cargo-based buildsystem, so it is not compatible with the kernel's build
system. This means that when C code calls a Rust function by name, its
signature must be duplicated in both Rust code and a C header, and the
signature needs to be kept in sync manually.

To eliminate this manual checking, introduce a new macro that verifies
at compile time that the two function declarations use the same
signature. The idea is to run the C declaration through bindgen, and
then have rustc verify that the function pointers have the same type.

The main commit of this series is "rust: add #[export] macro". Please
see its commit message for more details.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v2:
- Various improvements to documentation.
- Split out quote! changes into its own commit.
- Link to v1: https://lore.kernel.org/r/20250227-export-macro-v1-0-948775fc37aa@google.com

---
Alice Ryhl (5):
      rust: fix signature of rust_fmt_argument
      rust: macros: support additional tokens in quote!
      rust: add #[export] macro
      print: use new #[export] macro for rust_fmt_argument
      panic_qr: use new #[export] macro

 drivers/gpu/drm/drm_panic.c     |  5 -----
 drivers/gpu/drm/drm_panic_qr.rs | 15 +++++++++++----
 include/drm/drm_panic.h         |  7 +++++++
 include/linux/sprintf.h         |  3 +++
 lib/vsprintf.c                  |  3 ---
 rust/bindings/bindings_helper.h |  4 ++++
 rust/kernel/prelude.rs          |  2 +-
 rust/kernel/print.rs            | 10 +++++-----
 rust/macros/export.rs           | 28 ++++++++++++++++++++++++++++
 rust/macros/helpers.rs          | 19 ++++++++++++++++++-
 rust/macros/lib.rs              | 24 ++++++++++++++++++++++++
 rust/macros/quote.rs            | 21 +++++++++++++++++++--
 12 files changed, 120 insertions(+), 21 deletions(-)
---
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
change-id: 20250227-export-macro-9aa9f1016d8c

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


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

end of thread, other threads:[~2025-03-03  8:52 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 12:39 [PATCH v2 0/5] Check Rust signatures at compile time Alice Ryhl
2025-02-28 12:39 ` [PATCH v2 1/5] rust: fix signature of rust_fmt_argument Alice Ryhl
2025-02-28 15:13   ` Tamir Duberstein
2025-02-28 12:39 ` [PATCH v2 2/5] rust: macros: support additional tokens in quote! Alice Ryhl
2025-02-28 15:25   ` Tamir Duberstein
2025-03-03  8:17     ` Alice Ryhl
2025-02-28 18:51   ` Andreas Hindborg
2025-02-28 12:39 ` [PATCH v2 3/5] rust: add #[export] macro Alice Ryhl
2025-02-28 15:40   ` Tamir Duberstein
2025-02-28 15:49     ` Miguel Ojeda
2025-02-28 15:51       ` Tamir Duberstein
2025-03-03  8:28     ` Alice Ryhl
2025-02-28 18:53   ` Andreas Hindborg
2025-02-28 12:39 ` [PATCH v2 4/5] print: use new #[export] macro for rust_fmt_argument Alice Ryhl
2025-02-28 15:36   ` Andy Shevchenko
2025-02-28 17:11     ` Alice Ryhl
2025-02-28 15:48   ` Tamir Duberstein
2025-02-28 12:39 ` [PATCH v2 5/5] panic_qr: use new #[export] macro Alice Ryhl
2025-02-28 15:34   ` Andy Shevchenko
2025-02-28 17:06     ` Alice Ryhl
2025-02-28 15:54   ` Tamir Duberstein
2025-02-28 17:08     ` Alice Ryhl
2025-02-28 17:15       ` Tamir Duberstein
2025-03-03  8:52         ` Alice Ryhl
2025-02-28 17:06   ` Simona Vetter
2025-02-28 12:45 ` [PATCH v2 0/5] Check Rust signatures at compile time Andy Shevchenko
2025-02-28 13:12 ` Miguel Ojeda
2025-02-28 13:17   ` Alice Ryhl
2025-03-01  4:43 ` 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).