Files
linux-stable-mirror/rust/macros/export.rs
Gary Guo 8db9164b76 rust: macros: convert #[export] to use syn
This eliminates the custom `function_name` helper.

Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260112170919.1888584-7-gary@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2026-01-28 00:55:25 +01:00

26 lines
644 B
Rust

// SPDX-License-Identifier: GPL-2.0
use proc_macro2::TokenStream;
use quote::quote;
/// Please see [`crate::export`] for documentation.
pub(crate) fn export(f: syn::ItemFn) -> TokenStream {
let name = &f.sig.ident;
quote! {
// This verifies that the function has the same signature as the declaration generated by
// bindgen. It makes use of the fact that all branches of an if/else must have the same
// type.
const _: () = {
if true {
::kernel::bindings::#name
} else {
#name
};
};
#[no_mangle]
#f
}
}