Skip to content

Commit ba5fef3

Browse files
authored
Merge pull request #1443 from codeart1st/split-linked-modules
feat: allow bindgen-cli --split-linked-modules #1092
2 parents 513feba + 4ea2a23 commit ba5fef3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

docs/src/cargo-toml-configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ demangle-name-section = true
2929
dwarf-debug-info = false
3030
# Should we omit the default import path?
3131
omit-default-module-path = false
32+
# 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.
33+
split-linked-modules = false
3234

3335
[package.metadata.wasm-pack.profile.profiling]
3436
wasm-opt = ['-O']

src/bindgen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub fn wasm_bindgen_build(
9292
if profile.wasm_bindgen_omit_default_module_path() {
9393
cmd.arg("--omit-default-module-path");
9494
}
95+
if profile.wasm_bindgen_split_linked_modules() {
96+
cmd.arg("--split-linked-modules");
97+
}
9598

9699
child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
97100
Ok(())

src/manifest/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ struct CargoWasmPackProfileWasmBindgen {
127127

128128
#[serde(default, rename = "omit-default-module-path")]
129129
omit_default_module_path: Option<bool>,
130+
131+
#[serde(default, rename = "split-linked-modules")]
132+
split_linked_modules: Option<bool>,
130133
}
131134

132135
/// Struct for storing information received from crates.io
@@ -283,6 +286,7 @@ impl CargoWasmPackProfile {
283286
demangle_name_section: Some(true),
284287
dwarf_debug_info: Some(false),
285288
omit_default_module_path: Some(false),
289+
split_linked_modules: Some(false),
286290
},
287291
wasm_opt: None,
288292
}
@@ -295,6 +299,7 @@ impl CargoWasmPackProfile {
295299
demangle_name_section: Some(true),
296300
dwarf_debug_info: Some(false),
297301
omit_default_module_path: Some(false),
302+
split_linked_modules: Some(false),
298303
},
299304
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
300305
}
@@ -307,6 +312,7 @@ impl CargoWasmPackProfile {
307312
demangle_name_section: Some(true),
308313
dwarf_debug_info: Some(false),
309314
omit_default_module_path: Some(false),
315+
split_linked_modules: Some(false),
310316
},
311317
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
312318
}
@@ -319,6 +325,7 @@ impl CargoWasmPackProfile {
319325
demangle_name_section: Some(true),
320326
dwarf_debug_info: Some(false),
321327
omit_default_module_path: Some(false),
328+
split_linked_modules: Some(false),
322329
},
323330
wasm_opt: Some(CargoWasmPackProfileWasmOpt::Enabled(true)),
324331
}
@@ -370,6 +377,7 @@ impl CargoWasmPackProfile {
370377
d!(wasm_bindgen.demangle_name_section);
371378
d!(wasm_bindgen.dwarf_debug_info);
372379
d!(wasm_bindgen.omit_default_module_path);
380+
d!(wasm_bindgen.split_linked_modules);
373381

374382
if self.wasm_opt.is_none() {
375383
self.wasm_opt = defaults.wasm_opt.clone();
@@ -396,6 +404,11 @@ impl CargoWasmPackProfile {
396404
self.wasm_bindgen.omit_default_module_path.unwrap()
397405
}
398406

407+
/// Get this profile's configured `[wasm-bindgen.split-linked-modules]` value.
408+
pub fn wasm_bindgen_split_linked_modules(&self) -> bool {
409+
self.wasm_bindgen.split_linked_modules.unwrap()
410+
}
411+
399412
/// Get this profile's configured arguments for `wasm-opt`, if enabled.
400413
pub fn wasm_opt_args(&self) -> Option<Vec<String>> {
401414
match self.wasm_opt.as_ref()? {

0 commit comments

Comments
 (0)