Skip to content

Commit

Permalink
Merge pull request #1443 from codeart1st/split-linked-modules
Browse files Browse the repository at this point in the history
feat: allow bindgen-cli --split-linked-modules #1092
  • Loading branch information
drager authored Nov 2, 2024
2 parents 513feba + 4ea2a23 commit ba5fef3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/cargo-toml-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ demangle-name-section = true
dwarf-debug-info = false
# Should we omit the default import path?
omit-default-module-path = false
# Controls whether wasm-bindgen will split linked modules out into their own files. Enabling this is recommended, because it allows lazy-loading the linked modules and setting a stricter Content Security Policy. Only available in wasm-bindgen 0.2.95 and later.
split-linked-modules = false

[package.metadata.wasm-pack.profile.profiling]
wasm-opt = ['-O']
Expand Down
3 changes: 3 additions & 0 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub fn wasm_bindgen_build(
if profile.wasm_bindgen_omit_default_module_path() {
cmd.arg("--omit-default-module-path");
}
if profile.wasm_bindgen_split_linked_modules() {
cmd.arg("--split-linked-modules");
}

child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
Ok(())
Expand Down
13 changes: 13 additions & 0 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ struct CargoWasmPackProfileWasmBindgen {

#[serde(default, rename = "omit-default-module-path")]
omit_default_module_path: Option<bool>,

#[serde(default, rename = "split-linked-modules")]
split_linked_modules: Option<bool>,
}

/// Struct for storing information received from crates.io
Expand Down Expand Up @@ -283,6 +286,7 @@ impl CargoWasmPackProfile {
demangle_name_section: Some(true),
dwarf_debug_info: Some(false),
omit_default_module_path: Some(false),
split_linked_modules: Some(false),
},
wasm_opt: None,
}
Expand All @@ -295,6 +299,7 @@ impl CargoWasmPackProfile {
demangle_name_section: Some(true),
dwarf_debug_info: Some(false),
omit_default_module_path: Some(false),
split_linked_modules: Some(false),
},
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
}
Expand All @@ -307,6 +312,7 @@ impl CargoWasmPackProfile {
demangle_name_section: Some(true),
dwarf_debug_info: Some(false),
omit_default_module_path: Some(false),
split_linked_modules: Some(false),
},
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
}
Expand All @@ -319,6 +325,7 @@ impl CargoWasmPackProfile {
demangle_name_section: Some(true),
dwarf_debug_info: Some(false),
omit_default_module_path: Some(false),
split_linked_modules: Some(false),
},
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
}
Expand Down Expand Up @@ -370,6 +377,7 @@ impl CargoWasmPackProfile {
d!(wasm_bindgen.demangle_name_section);
d!(wasm_bindgen.dwarf_debug_info);
d!(wasm_bindgen.omit_default_module_path);
d!(wasm_bindgen.split_linked_modules);

if self.wasm_opt.is_none() {
self.wasm_opt = defaults.wasm_opt.clone();
Expand All @@ -396,6 +404,11 @@ impl CargoWasmPackProfile {
self.wasm_bindgen.omit_default_module_path.unwrap()
}

/// Get this profile's configured `[wasm-bindgen.split-linked-modules]` value.
pub fn wasm_bindgen_split_linked_modules(&self) -> bool {
self.wasm_bindgen.split_linked_modules.unwrap()
}

/// Get this profile's configured arguments for `wasm-opt`, if enabled.
pub fn wasm_opt_args(&self) -> Option<Vec<String>> {
match self.wasm_opt.as_ref()? {
Expand Down

0 comments on commit ba5fef3

Please sign in to comment.