summaryrefslogtreecommitdiff
path: root/ext/napi/sym/README.md
blob: 66eb4bff26c1be5d06d6d270726859d98e70f2f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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`](./symbol_exports.json).
- Maps `deno_napi::Result` to raw `napi_result`.

```rust
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`](../build.rs).

On Windows, you need to generate the `.def` file by running
[`tools/napi/generate_symbols_lists.js`](../../tools/napi/generate_symbols_lists.js).