From 79a3ad2b950009f560641cea359d7deb6f7a61ac Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 24 Oct 2024 09:13:54 +0200 Subject: feat: support node-api in denort (#26389) exposes node-api symbols in denort so that `deno compile` can run native addons. --- ext/napi/sym/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ext/napi/sym/lib.rs (limited to 'ext/napi/sym/lib.rs') 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, +} + +#[proc_macro_attribute] +pub fn napi_sym(_attr: TokenStream, item: TokenStream) -> TokenStream { + let func = syn::parse::(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 + } + }) +} -- cgit v1.2.3