2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-10-05 10:06:44 -04:00
|
|
|
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::quote;
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
2022-10-06 23:51:43 -04:00
|
|
|
static NAPI_EXPORTS: &str = include_str!("./symbol_exports.json");
|
2022-10-05 10:06:44 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct SymbolExports {
|
|
|
|
pub symbols: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn napi_sym(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
|
let func = syn::parse::<syn::ItemFn>(item).expect("expected a function");
|
|
|
|
|
|
|
|
let exports: SymbolExports =
|
|
|
|
serde_json::from_str(NAPI_EXPORTS).expect("failed to parse exports");
|
|
|
|
let name = &func.sig.ident;
|
|
|
|
assert!(
|
|
|
|
exports.symbols.contains(&name.to_string()),
|
2024-07-22 20:01:31 -04:00
|
|
|
"cli/napi/sym/symbol_exports.json is out of sync!"
|
2022-10-05 10:06:44 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
TokenStream::from(quote! {
|
2024-06-10 12:20:44 -04:00
|
|
|
crate::napi_wrap! {
|
|
|
|
#func
|
|
|
|
}
|
2022-10-05 10:06:44 -04:00
|
|
|
})
|
|
|
|
}
|