Skip to content

Commit a00ac02

Browse files
authored
fix(bundler) webview dll not being bundled, fixes #875 (#889)
1 parent bbccad4 commit a00ac02

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

.changes/webview-dll.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+
Bundling every DLL file on the binary directory.

cli/tauri-bundler/src/bundle/wix.rs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ impl ResourceDirectory {
123123
}
124124
directories.push_str(wix_string.as_str());
125125
}
126-
let wix_string = format!(
127-
r#"<Directory Id="{name}" Name="{name}">{contents}</Directory>"#,
128-
name = self.name,
129-
contents = format!("{}{}", files, directories)
130-
);
126+
let wix_string = if self.name == "" {
127+
format!("{}{}", files, directories)
128+
} else {
129+
format!(
130+
r#"<Directory Id="{name}" Name="{name}">{contents}</Directory>"#,
131+
name = self.name,
132+
contents = format!("{}{}", files, directories)
133+
)
134+
};
131135

132136
Ok((wix_string, file_ids))
133137
}
@@ -215,7 +219,7 @@ fn app_installer_dir(settings: &Settings) -> crate::Result<PathBuf> {
215219
}
216220

217221
/// Extracts the zips from Wix and VC_REDIST into a useable path.
218-
fn extract_zip(data: &Vec<u8>, path: &Path) -> crate::Result<()> {
222+
fn extract_zip(data: &[u8], path: &Path) -> crate::Result<()> {
219223
let cursor = Cursor::new(data);
220224

221225
let mut zipa = ZipArchive::new(cursor)?;
@@ -377,7 +381,7 @@ fn run_light(
377381
];
378382

379383
for p in wixobjs {
380-
args.push(p.to_string());
384+
args.push((*p).to_string());
381385
}
382386

383387
let mut cmd = Command::new(&light_exe);
@@ -488,13 +492,13 @@ pub fn build_wix_app_installer(
488492
let temp = HANDLEBARS.render("main.wxs", &data)?;
489493

490494
if output_path.exists() {
491-
remove_dir_all(&output_path).or_else(|e| Err(e))?;
495+
remove_dir_all(&output_path)?;
492496
}
493497

494-
create_dir_all(&output_path).or_else(|e| Err(e))?;
498+
create_dir_all(&output_path)?;
495499

496500
let main_wxs_path = output_path.join("main.wxs");
497-
write(&main_wxs_path, temp).or_else(|e| Err(e))?;
501+
write(&main_wxs_path, temp)?;
498502

499503
let input_basenames = vec!["main"];
500504

@@ -565,6 +569,40 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
565569
let mut resources = ResourceMap::new();
566570
let regex = Regex::new(r"[^\w\d\.]")?;
567571
let cwd = std::env::current_dir()?;
572+
573+
let mut dlls = vec![];
574+
for dll in glob::glob(
575+
settings
576+
.project_out_directory()
577+
.join("*.dll")
578+
.to_string_lossy()
579+
.to_string()
580+
.as_str(),
581+
)? {
582+
let path = dll?;
583+
let filename = path
584+
.file_name()
585+
.expect("failed to extract resource filename")
586+
.to_os_string()
587+
.into_string()
588+
.expect("failed to convert resource filename to string");
589+
dlls.push(ResourceFile {
590+
guid: generate_guid(filename.as_bytes()).to_string(),
591+
path: path.to_string_lossy().to_string(),
592+
id: regex.replace_all(&filename, "").to_string(),
593+
});
594+
}
595+
if !dlls.is_empty() {
596+
resources.insert(
597+
"".to_string(),
598+
ResourceDirectory {
599+
name: "".to_string(),
600+
directories: vec![],
601+
files: dlls,
602+
},
603+
);
604+
}
605+
568606
for src in settings.resource_files() {
569607
let src = src?;
570608

cli/tauri-bundler/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn run() -> crate::Result<()> {
119119
if !output_str.contains("win32webviewhost_cw5n1h2txyewy") {
120120
println!("Running Loopback command");
121121
Command::new("powershell")
122-
.args(&vec![
122+
.args(&[
123123
"CheckNetIsolation LoopbackExempt -a -n=\"Microsoft.Win32WebViewHost_cw5n1h2txyewy\"",
124124
])
125125
.force_prompt(true)

0 commit comments

Comments
 (0)