133 breaking releases

new 0.134.0 Apr 30, 2025
0.132.0 Apr 18, 2025
0.127.0 Mar 28, 2025
0.114.0 Dec 19, 2024
0.9.0 Nov 24, 2022

#149 in Procedural macros

Download history 937/week @ 2025-01-10 1099/week @ 2025-01-17 854/week @ 2025-01-24 936/week @ 2025-01-31 605/week @ 2025-02-07 1209/week @ 2025-02-14 1605/week @ 2025-02-21 1320/week @ 2025-02-28 1192/week @ 2025-03-07 1249/week @ 2025-03-14 1066/week @ 2025-03-21 1086/week @ 2025-03-28 1306/week @ 2025-04-04 1328/week @ 2025-04-11 1074/week @ 2025-04-18 867/week @ 2025-04-25

4,763 downloads per month
Used in 23 crates (7 directly)

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 unsafe 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.6–1.5MB
~33K SLoC