mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2026-02-11 06:15:25 +00:00
macros and improvements
This commit is contained in:
11
main_proc_macro/Cargo.toml
Normal file
11
main_proc_macro/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "main_proc_macro"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.41"
|
||||
syn = "2.0.108"
|
||||
21
main_proc_macro/src/lib.rs
Normal file
21
main_proc_macro/src/lib.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{ItemFn, parse_macro_input};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as ItemFn);
|
||||
let name = &input.sig.ident;
|
||||
|
||||
// ensure we emit _start in the same module as the fn
|
||||
let expanded = quote! {
|
||||
#input
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
#name();
|
||||
}
|
||||
};
|
||||
|
||||
expanded.into()
|
||||
}
|
||||
Reference in New Issue
Block a user