xref: /linux/rust/macros/export.rs (revision c17ee635fd3a482b2ad2bf5e269755c2eae5f25e)
144e333feSAlice Ryhl // SPDX-License-Identifier: GPL-2.0
244e333feSAlice Ryhl 
3f637bafeSGary Guo use proc_macro2::TokenStream;
4f637bafeSGary Guo use quote::quote;
5f637bafeSGary Guo 
644e333feSAlice Ryhl /// Please see [`crate::export`] for documentation.
7*8db9164bSGary Guo pub(crate) fn export(f: syn::ItemFn) -> TokenStream {
8*8db9164bSGary Guo     let name = &f.sig.ident;
944e333feSAlice Ryhl 
10*8db9164bSGary Guo     quote! {
1144e333feSAlice Ryhl         // This verifies that the function has the same signature as the declaration generated by
12*8db9164bSGary Guo         // bindgen. It makes use of the fact that all branches of an if/else must have the same
13*8db9164bSGary Guo         // type.
1444e333feSAlice Ryhl         const _: () = {
1544e333feSAlice Ryhl             if true {
1644e333feSAlice Ryhl                 ::kernel::bindings::#name
1744e333feSAlice Ryhl             } else {
1844e333feSAlice Ryhl                 #name
1944e333feSAlice Ryhl             };
2044e333feSAlice Ryhl         };
2144e333feSAlice Ryhl 
22*8db9164bSGary Guo         #[no_mangle]
23*8db9164bSGary Guo         #f
24*8db9164bSGary Guo     }
2544e333feSAlice Ryhl }
26