From 4e8f5875bc59ddfb84c8b0b26071a547b49823a9 Mon Sep 17 00:00:00 2001 From: Ivancing <648262030@qq.com> Date: Mon, 22 Jul 2024 01:40:42 +0800 Subject: 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. --- cli/build.rs | 47 +++++++++++++++++++++++++++++++++++------------ cli/mainrt.rs | 1 + 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'cli') diff --git a/cli/build.rs b/cli/build.rs index 4fe6fd1ea..f131bc1dc 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -404,16 +404,28 @@ fn main() { ); #[cfg(target_os = "windows")] - println!( - "cargo:rustc-link-arg-bin=deno=/DEF:{}", - symbols_path.display() - ); + { + println!( + "cargo:rustc-link-arg-bin=deno=/DEF:{}", + symbols_path.display() + ); + println!( + "cargo:rustc-link-arg-bin=denort=/DEF:{}", + symbols_path.display() + ); + } #[cfg(target_os = "macos")] - println!( - "cargo:rustc-link-arg-bin=deno=-Wl,-exported_symbols_list,{}", - symbols_path.display() - ); + { + println!( + "cargo:rustc-link-arg-bin=deno=-Wl,-exported_symbols_list,{}", + symbols_path.display() + ); + println!( + "cargo:rustc-link-arg-bin=denort=-Wl,-exported_symbols_list,{}", + symbols_path.display() + ); + } #[cfg(target_os = "linux")] { @@ -426,19 +438,30 @@ fn main() { { println!("cargo:warning=Compiling with all symbols exported, this will result in a larger binary. Please use glibc 2.35 or later for an optimised build."); println!("cargo:rustc-link-arg-bin=deno=-rdynamic"); + println!("cargo:rustc-link-arg-bin=denort=-rdynamic"); } else { println!( "cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol-list={}", symbols_path.display() ); + println!( + "cargo:rustc-link-arg-bin=denort=-Wl,--export-dynamic-symbol-list={}", + symbols_path.display() + ); } } #[cfg(target_os = "android")] - println!( - "cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol-list={}", - symbols_path.display() - ); + { + println!( + "cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol-list={}", + symbols_path.display() + ); + println!( + "cargo:rustc-link-arg-bin=denort=-Wl,--export-dynamic-symbol-list={}", + symbols_path.display() + ); + } // To debug snapshot issues uncomment: // op_fetch_asset::trace_serializer(); diff --git a/cli/mainrt.rs b/cli/mainrt.rs index aafbf7932..ef163dd00 100644 --- a/cli/mainrt.rs +++ b/cli/mainrt.rs @@ -15,6 +15,7 @@ mod errors; mod file_fetcher; mod http_util; mod js; +mod napi; mod node; mod npm; mod resolver; -- cgit v1.2.3