Skip to content

Commit 261d1bc

Browse files
authored
feat(bundler): load WiX extensions used on fragments, closes #4546 (#4656)
1 parent ac72800 commit 261d1bc

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

.changes/load-wix-extension.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Automatically load WiX extensions referenced in fragments.

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ fn run_candle(
285285
settings: &Settings,
286286
wix_toolset_path: &Path,
287287
cwd: &Path,
288-
wxs_file_path: &Path,
288+
wxs_file_path: PathBuf,
289+
extensions: Vec<PathBuf>,
289290
) -> crate::Result<()> {
290291
let arch = match settings.binary_arch() {
291292
"x86_64" => "x64",
@@ -317,7 +318,12 @@ fn run_candle(
317318
let candle_exe = wix_toolset_path.join("candle.exe");
318319

319320
info!(action = "Running"; "candle for {:?}", wxs_file_path);
320-
Command::new(&candle_exe)
321+
let mut cmd = Command::new(&candle_exe);
322+
for ext in extensions {
323+
cmd.arg("-ext");
324+
cmd.arg(ext);
325+
}
326+
cmd
321327
.args(&args)
322328
.current_dir(cwd)
323329
.output_ok()
@@ -331,6 +337,7 @@ fn run_light(
331337
wix_toolset_path: &Path,
332338
build_path: &Path,
333339
arguments: Vec<String>,
340+
extensions: &Vec<PathBuf>,
334341
output_path: &Path,
335342
) -> crate::Result<()> {
336343
let light_exe = wix_toolset_path.join("light.exe");
@@ -344,11 +351,14 @@ fn run_light(
344351
output_path.display().to_string(),
345352
];
346353

347-
for p in arguments {
348-
args.push(p);
349-
}
354+
args.extend(arguments);
350355

351-
Command::new(&light_exe)
356+
let mut cmd = Command::new(&light_exe);
357+
for ext in extensions {
358+
cmd.arg("-ext");
359+
cmd.arg(ext);
360+
}
361+
cmd
352362
.args(&args)
353363
.current_dir(build_path)
354364
.output_ok()
@@ -732,15 +742,24 @@ pub fn build_wix_app_installer(
732742
let main_wxs_path = output_path.join("main.wxs");
733743
write(&main_wxs_path, handlebars.render("main.wxs", &data)?)?;
734744

735-
let mut candle_inputs = vec!["main.wxs".into()];
745+
let mut candle_inputs = vec![("main.wxs".into(), Vec::new())];
736746

737747
let current_dir = std::env::current_dir()?;
748+
let extension_regex = Regex::new("\"http://schemas.microsoft.com/wix/(\\w+)\"")?;
738749
for fragment_path in fragment_paths {
739-
candle_inputs.push(current_dir.join(fragment_path));
750+
let fragment_path = current_dir.join(fragment_path);
751+
let fragment = read_to_string(&fragment_path)?;
752+
let mut extensions = Vec::new();
753+
for cap in extension_regex.captures_iter(&fragment) {
754+
extensions.push(wix_toolset_path.join(format!("Wix{}.dll", &cap[1])));
755+
}
756+
candle_inputs.push((fragment_path, extensions));
740757
}
741758

742-
for wxs in &candle_inputs {
743-
run_candle(settings, wix_toolset_path, &output_path, wxs)?;
759+
let mut fragment_extensions = Vec::new();
760+
for (path, extensions) in candle_inputs {
761+
fragment_extensions.extend(extensions.clone());
762+
run_candle(settings, wix_toolset_path, &output_path, path, extensions)?;
744763
}
745764

746765
let mut output_paths = Vec::new();
@@ -814,7 +833,13 @@ pub fn build_wix_app_installer(
814833

815834
info!(action = "Running"; "light to produce {}", msi_path.display());
816835

817-
run_light(wix_toolset_path, &output_path, arguments, &msi_output_path)?;
836+
run_light(
837+
wix_toolset_path,
838+
&output_path,
839+
arguments,
840+
&fragment_extensions,
841+
&msi_output_path,
842+
)?;
818843
rename(&msi_output_path, &msi_path)?;
819844
try_sign(&msi_path)?;
820845
output_paths.push(msi_path);

0 commit comments

Comments
 (0)