From 38559da6afb239e271e709588babe7f98195096b Mon Sep 17 00:00:00 2001 From: Guilherme Giacomo Simoes Date: Sun, 9 Mar 2025 14:57:11 -0300 Subject: rust: module: introduce `authors` key In the `module!` macro, the `author` field is currently of type `String`. Since modules can have multiple authors, this limitation prevents specifying more than one. Add an `authors` field as `Option>` to allow creating modules with multiple authors, and change the documentation and all current users to use it. Eventually, the single `author` field may be removed. [ The `modinfo` key needs to still be `author`; otherwise, tooling may not work properly, e.g.: $ modinfo --author samples/rust/rust_print.ko Rust for Linux Contributors I have also kept the original `author` field (undocumented), so that we can drop it more easily in a kernel cycle or two. - Miguel ] Suggested-by: Miguel Ojeda Link: https://github.com/Rust-for-Linux/linux/issues/244 Reviewed-by: Charalampos Mitrodimas Reviewed-by: Alice Ryhl Reviewed-by: Andreas Hindborg Signed-off-by: Guilherme Giacomo Simoes Link: https://lore.kernel.org/r/20250309175712.845622-2-trintaeoitogc@gmail.com [ Fixed `modinfo` key. Kept `author` field. Reworded message accordingly. Updated my email. - Miguel ] Signed-off-by: Miguel Ojeda --- rust/macros/module.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'rust/macros/module.rs') diff --git a/rust/macros/module.rs b/rust/macros/module.rs index cdf94f4982df..42ed16c48b37 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -95,6 +95,7 @@ struct ModuleInfo { license: String, name: String, author: Option, + authors: Option>, description: Option, alias: Option>, firmware: Option>, @@ -108,6 +109,7 @@ impl ModuleInfo { "type", "name", "author", + "authors", "description", "license", "alias", @@ -136,6 +138,7 @@ impl ModuleInfo { "type" => info.type_ = expect_ident(it), "name" => info.name = expect_string_ascii(it), "author" => info.author = Some(expect_string(it)), + "authors" => info.authors = Some(expect_string_array(it)), "description" => info.description = Some(expect_string(it)), "license" => info.license = expect_string_ascii(it), "alias" => info.alias = Some(expect_string_array(it)), @@ -186,6 +189,11 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { if let Some(author) = info.author { modinfo.emit("author", &author); } + if let Some(authors) = info.authors { + for author in authors { + modinfo.emit("author", &author); + } + } if let Some(description) = info.description { modinfo.emit("description", &description); } -- cgit v1.2.3 From dbd5058ba60c3499b24a7133a4e2e24dba6ea77b Mon Sep 17 00:00:00 2001 From: Benno Lossin Date: Sat, 8 Mar 2025 11:05:09 +0000 Subject: rust: make pin-init its own crate Rename relative paths inside of the crate to still refer to the same items, also rename paths inside of the kernel crate and adjust the build system to build the crate. [ Remove the `expect` (and thus the `lint_reasons` feature) since the tree now uses `quote!` from `rust/macros/export.rs`. Remove the `TokenStream` import removal, since it is now used as well. In addition, temporarily (i.e. just for this commit) use an `--extern force:alloc` to prevent an unknown `new_uninit` error in the `rustdoc` target. For context, please see a similar case in: https://lore.kernel.org/lkml/20240422090644.525520-1-ojeda@kernel.org/ And adjusted the message above. - Miguel ] Signed-off-by: Benno Lossin Reviewed-by: Fiona Behrens Tested-by: Andreas Hindborg Link: https://lore.kernel.org/r/20250308110339.2997091-16-benno.lossin@proton.me Signed-off-by: Miguel Ojeda --- rust/macros/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rust/macros/module.rs') diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 42ed16c48b37..46f20682a7a9 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -244,7 +244,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { mod __module_init {{ mod __module_init {{ use super::super::{type_}; - use kernel::init::PinInit; + use pin_init::PinInit; /// The \"Rust loadable module\" mark. // -- cgit v1.2.3 From a0b539ad369fe434fe488faf92d4ae770a27a90f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 10 Feb 2025 09:51:07 -0500 Subject: rust: macros: fix `make rusttest` build on macOS Do not emit `#[link_section = ".modinfo"]` on macOS (i.e. when building userspace tests); .modinfo is not a legal section specifier in mach-o. Before this change tests failed to compile: ---- ../rust/macros/lib.rs - module (line 66) stdout ---- rustc-LLVM ERROR: Global variable '_ZN8rust_out13__module_init13__module_init27__MY_DEVICE_DRIVER_MODULE_017h141f80536770e0d4E' has an invalid section specifier '.modinfo': mach-o section specifier requires a segment and section separated by a comma. Couldn't compile the test. ---- ../rust/macros/lib.rs - module (line 33) stdout ---- rustc-LLVM ERROR: Global variable '_ZN8rust_out13__module_init13__module_init20__MY_KERNEL_MODULE_017h5d79189564b41e07E' has an invalid section specifier '.modinfo': mach-o section specifier requires a segment and section separated by a comma. Couldn't compile the test. Signed-off-by: Tamir Duberstein Link: https://lore.kernel.org/r/20250210-macros-section-v2-1-3bb9ff44b969@gmail.com Signed-off-by: Miguel Ojeda --- rust/macros/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rust/macros/module.rs') diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 46f20682a7a9..8ab4e1f3eb45 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -56,7 +56,7 @@ impl<'a> ModInfoBuilder<'a> { " {cfg} #[doc(hidden)] - #[link_section = \".modinfo\"] + #[cfg_attr(not(target_os = \"macos\"), link_section = \".modinfo\")] #[used] pub static __{module}_{counter}: [u8; {length}] = *{string}; ", -- cgit v1.2.3