80 breaking releases

new 0.81.0 May 10, 2024
0.79.0 May 1, 2024
0.73.0 Mar 28, 2024
0.59.0 Dec 21, 2023
0.9.0 Nov 24, 2022

#756 in Procedural macros

Download history 258/week @ 2024-01-24 170/week @ 2024-01-31 158/week @ 2024-02-07 639/week @ 2024-02-14 438/week @ 2024-02-21 506/week @ 2024-02-28 346/week @ 2024-03-06 439/week @ 2024-03-13 174/week @ 2024-03-20 533/week @ 2024-03-27 225/week @ 2024-04-03 715/week @ 2024-04-10 172/week @ 2024-04-17 222/week @ 2024-04-24 406/week @ 2024-05-01 471/week @ 2024-05-08

1,496 downloads per month
Used in 5 crates

MIT license

4KB

napi_sym

A proc_macro for Deno's Node-API implementation. It does the following things:

  • Marks the symbol as #[no_mangle] and rewrites it as pub extern "C" $name.
  • Asserts that the function symbol is present in symbol_exports.json.
  • Maps deno_napi::Result to raw napi_result.
use deno_napi::napi_value;
use deno_napi::Env;
use deno_napi::Error;
use deno_napi::Result;

#[napi_sym::napi_sym]
fn napi_get_boolean(
  env: *mut Env,
  value: bool,
  result: *mut napi_value,
) -> Result {
  let _env: &mut Env = env.as_mut().ok_or(Error::InvalidArg)?;
  // *result = ...
  Ok(())
}

symbol_exports.json

A file containing the symbols that need to be put into the executable's dynamic symbol table at link-time.

This is done using /DEF: on Windows, -exported_symbol,_ on macOS and --export-dynamic-symbol= on Linux. See cli/build.rs.

On Windows, you need to generate the .def file by running tools/napi/generate_symbols_lists.js.

Dependencies

~0.7–1.5MB
~34K SLoC