mirror of
https://github.com/denoland/deno.git
synced 2024-12-29 18:49:07 -05:00
79a3ad2b95
exposes node-api symbols in denort so that `deno compile` can run native addons.
31 lines
800 B
Rust
31 lines
800 B
Rust
// 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
|
|
}
|
|
})
|
|
}
|