generate.rs

verification/proofs/startup-admission/native/generate.rs

generate.rs25 lines← SDK documentation
1//! Execute the exact SDK macro generator; select actual emitted functions.2use quote::{quote,ToTokens};3use std::{env,fs,path::Path};4#[path = "../../../../cdk-rsx/crates/cdk-rsx-macros/src/root.rs"]5mod root;6mod wrappers;7fn main() {8    let out=env::args().nth(1).expect("output directory");let out=Path::new(&out);9    fs::create_dir_all(out).unwrap();10    let memory=syn::parse_str::<syn::ItemMod>(include_str!("memory.rs")).unwrap();11    let generated=root::expand(quote!(state=App,error=Error,init=install,restore=reopen,previous=[memory::v1::Memory]),memory.into_token_stream()).unwrap();12    fs::write(out.join("root.rs"),generated.to_string()).unwrap();13    let parsed=syn::parse2::<syn::File>(generated).unwrap();14    let mut selected=String::new();15    for item in parsed.items {16        match &item {17            syn::Item::Fn(f) if f.sig.ident=="__cdk_rsx_admit_digest" => selected.push_str(&item.to_token_stream().to_string()),18            syn::Item::Macro(m) if m.mac.path.segments.last().unwrap().ident=="thread_local" && m.mac.tokens.to_string().contains("__CDK_RSX_ADMITTED") => selected.push_str(&item.to_token_stream().to_string()),19            _=>{},20        }21    }22    fs::write(out.join("admission.rs"),selected).unwrap();23    wrappers::emit(out);24    println!("STARTUP_GENERATED_OK");25}