diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /ext/napi/sym/lib.rs | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'ext/napi/sym/lib.rs')
-rw-r--r-- | ext/napi/sym/lib.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ext/napi/sym/lib.rs b/ext/napi/sym/lib.rs new file mode 100644 index 000000000..e2826306b --- /dev/null +++ b/ext/napi/sym/lib.rs @@ -0,0 +1,31 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use proc_macro::TokenStream; +use quote::quote; +use serde::Deserialize; + +static NAPI_EXPORTS: &str = include_str!("./symbol_exports.json"); + +#[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()), + "cli/napi/sym/symbol_exports.json is out of sync!" + ); + + TokenStream::from(quote! { + crate::napi_wrap! { + #func + } + }) +} |