summaryrefslogtreecommitdiff
path: root/cli/napi/sym/README.md
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-07-23 01:01:31 +0100
committerGitHub <noreply@github.com>2024-07-23 00:01:31 +0000
commit3f8efe5289d88097ab49e7a8fcda763c2823376b (patch)
tree736b2f2315a46a81af1ecfec4e5efb4f2a7d3521 /cli/napi/sym/README.md
parent715675565a928a7ac819b89fa40d8b74e7e1c8bc (diff)
Revert "chore: move all node-api impl to ext (#24662)" (#24680)
This reverts commit d00fbd70258a77a267fe20bdd2c4a028c799b693. Reverting because, it caused a failure during v1.45.3 publish: https://github.com/denoland/deno/actions/runs/10048730693/job/27773718095
Diffstat (limited to 'cli/napi/sym/README.md')
-rw-r--r--cli/napi/sym/README.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/cli/napi/sym/README.md b/cli/napi/sym/README.md
new file mode 100644
index 000000000..de08a8e17
--- /dev/null
+++ b/cli/napi/sym/README.md
@@ -0,0 +1,37 @@
+# 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`](./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).