Skip to content

Commit

Permalink
fix(build): don't export all symbols to dynamic symbol table
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Oct 6, 2022
1 parent 0b016a7 commit 22e8386
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ deno_websocket = { version = "0.76.0", path = "../ext/websocket" }
deno_webstorage = { version = "0.66.0", path = "../ext/webstorage" }
regex = "=1.6.0"
serde = { version = "=1.0.144", features = ["derive"] }
serde_json = "1.0.64"
zstd = '=0.11.2'

[target.'cfg(windows)'.build-dependencies]
Expand Down
31 changes: 30 additions & 1 deletion cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,36 @@ fn main() {
);

#[cfg(not(target_os = "windows"))]
println!("cargo:rustc-link-arg-bin=deno=-rdynamic");
{
// 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("../tools/napi/symbol_exports.json").expect(
"Missing tools/napi/symbol_exports.json! This is a bug in napi_sym",
);
let symbols: Symbols = serde_json::from_str(&symbols_json)
.expect("tools/napi/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")]
println!(
"cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol,{}",
symbol
);
}
}

// To debug snapshot issues uncomment:
// op_fetch_asset::trace_serializer();
Expand Down

0 comments on commit 22e8386

Please sign in to comment.