diff options
author | snek <snek@deno.com> | 2024-07-22 11:41:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-22 11:41:59 -0700 |
commit | 92abdb7669d81b656ae0505cf923fca3b7feea01 (patch) | |
tree | 51b69d12fc67351f979246d86fc9cfdf369dde48 /ext/napi/sym/lib.rs | |
parent | a459b43d59d2f8f055f3ecda30d1cf0fed2e181f (diff) |
chore: move all node-api impl to ext (#24662)
these symbols are re-exported from runtime/cli using `build.rs`, so we
don't need them in the same crate.
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..21edaa289 --- /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()), + "ext/napi/sym/symbol_exports.json is out of sync!" + ); + + TokenStream::from(quote! { + crate::napi_wrap! { + #func + } + }) +} |