diff options
author | Ivancing <648262030@qq.com> | 2024-07-22 01:40:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-21 10:40:42 -0700 |
commit | 4e8f5875bc59ddfb84c8b0b26071a547b49823a9 (patch) | |
tree | ecee05a99e9be182a196dad035dfab79280bab92 /tests/integration/compile_tests.rs | |
parent | bb1c6c49bb30a6518ca4dbd3b3f7ec52f5861b76 (diff) |
fix(cli): add NAPI support in standalone mode (#24642)
Currently, importing Node-Addons modules in a standalone binary results
in a `missing symbol called` error
(https://github.com/denoland/deno/issues/24614). Because the NAPI
symbols are not exported in this mode. This PR should fix the issue.
Diffstat (limited to 'tests/integration/compile_tests.rs')
-rw-r--r-- | tests/integration/compile_tests.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/integration/compile_tests.rs b/tests/integration/compile_tests.rs index 17054637e..cd6e429b3 100644 --- a/tests/integration/compile_tests.rs +++ b/tests/integration/compile_tests.rs @@ -1283,3 +1283,66 @@ fn standalone_jsr_dynamic_import() { output.assert_exit_code(0); output.assert_matches_text("Hello world\n"); } + +#[test] +fn standalone_require_node_addons() { + #[cfg(not(target_os = "windows"))] + { + let context = TestContextBuilder::for_jsr().build(); + let dir = context.temp_dir(); + let libout = dir.path().join("module.node"); + + let cc = context + .new_command() + .name("cc") + .current_dir(util::testdata_path()); + + #[cfg(not(target_os = "macos"))] + let c_module = cc + .arg("./compile/napi/module.c") + .arg("-shared") + .arg("-o") + .arg(&libout); + + #[cfg(target_os = "macos")] + let c_module = { + cc.arg("./compile/napi/module.c") + .arg("-undefined") + .arg("dynamic_lookup") + .arg("-shared") + .arg("-Wl,-no_fixup_chains") + .arg("-dynamic") + .arg("-o") + .arg(&libout) + }; + let c_module_output = c_module.output().unwrap(); + + assert!(c_module_output.status.success()); + + let exe = if cfg!(windows) { + dir.path().join("main.exe") + } else { + dir.path().join("main") + }; + + context + .new_command() + .env("NPM_CONFIG_REGISTRY", "https://registry.npmjs.org/") + .args_vec([ + "compile", + "--allow-read", + "--allow-ffi", + "--output", + &exe.to_string_lossy(), + "./compile/napi/main.ts", + ]) + .run() + .skip_output_check() + .assert_exit_code(0); + + let output = context.new_command().name(&exe).arg(&libout).run(); + + output.assert_exit_code(0); + output.assert_matches_text("{}\n"); + } +} |