summaryrefslogtreecommitdiff
path: root/cli/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/build.rs')
-rw-r--r--cli/build.rs62
1 files changed, 23 insertions, 39 deletions
diff --git a/cli/build.rs b/cli/build.rs
index 0d683780f..98d044a3e 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -332,56 +332,40 @@ fn main() {
panic!("Cross compiling with snapshot is not supported.");
}
+ let symbols_path = std::path::Path::new(
+ format!("generated_symbol_exports_list_{}.def", env::consts::OS).as_str(),
+ )
+ .canonicalize()
+ .expect(
+ "Missing symbols list! Generate using tools/napi/generate_symbols_lists.js",
+ );
+
#[cfg(target_os = "windows")]
println!(
"cargo:rustc-link-arg-bin=deno=/DEF:{}",
- std::path::Path::new("exports.def")
- .canonicalize()
- .expect(
- "Missing exports.def! Generate using tools/napi/generate_link_win.js"
- )
- .display(),
+ symbols_path.display()
+ );
+
+ #[cfg(target_os = "macos")]
+ println!(
+ "cargo:rustc-link-arg-bin=deno=-Wl,-exported_symbols_list,{}",
+ symbols_path.display()
);
- #[cfg(all(
- not(target_os = "windows"),
- not(all(target_os = "linux", target_arch = "aarch64"))
- ))]
+ #[cfg(target_os = "linux")]
{
- // Load the symbols file generated by the `napi_sym` macro.
- #[derive(serde::Deserialize)]
- struct Symbols {
- symbols: Vec<String>,
- }
- let symbols_json =
- std::fs::read_to_string("./napi_sym/symbol_exports.json").expect(
- "Missing ./napi_sym/symbol_exports.json! This is a bug in napi_sym",
- );
- let symbols: Symbols = serde_json::from_str(&symbols_json)
- .expect("./napi_sym/symbol_exports.json is not valid JSON");
-
- // Don't export all symbols into the dynamic symbol table. -rdynamic exports *all* symbols introducing binary bloat.
- // We only need to export Node API symbols.
- for symbol in symbols.symbols {
- // TODO(@littledivy): We _might_ hit an argument size limit?
- // Maybe use `--export-dynamic-symbol-list` / `--exported_symbols_list` instead? https://reviews.llvm.org/D107317
- #[cfg(target_os = "macos")]
- println!(
- "cargo:rustc-link-arg-bin=deno=-Wl,-exported_symbol,_{}",
- symbol
- );
- #[cfg(target_os = "linux")]
+ let ver = glibc_version::get_version().unwrap();
+ if ver.major <= 2 && ver.minor < 35 {
+ 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");
+ } else {
println!(
- "cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol={}",
- symbol
+ "cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol-list={}",
+ symbols_path.display()
);
}
}
- // Linux + aarch64 does not support a glibc version that supports `--export-dynamic-symbol`.
- #[cfg(all(target_os = "linux", target_arch = "aarch64"))]
- println!("cargo:rustc-link-arg-bin=deno=-rdynamic");
-
// To debug snapshot issues uncomment:
// op_fetch_asset::trace_serializer();