Skip to content

Commit

Permalink
feat(tauri-build): improve Windows GNU toolchain usage, closes #4319 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 12, 2022
1 parent 76d1eaa commit 58a6879
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changes/improve-windows-gnu-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Improve usage of the GNU toolchain on Windows by copying the Webview2Loader.dll file to the target directory.
54 changes: 44 additions & 10 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ fn cfg_alias(alias: &str, has_feature: bool) {
#[derive(Debug, Default)]
pub struct WindowsAttributes {
window_icon_path: Option<PathBuf>,
/// The path to the sdk location. This can be a absolute or relative path. If not supplied
/// this defaults to whatever `winres` crate determines is the best. See the
/// [winres documentation](https://docs.rs/winres/*/winres/struct.WindowsResource.html#method.set_toolkit_path)
/// The path to the sdk location.
///
/// For the GNU toolkit this has to be the path where MinGW put windres.exe and ar.exe.
/// This could be something like: "C:\Program Files\mingw-w64\x86_64-5.3.0-win32-seh-rt_v4-rev0\mingw64\bin"
///
/// For MSVC the Windows SDK has to be installed. It comes with the resource compiler rc.exe.
/// This should be set to the root directory of the Windows SDK, e.g., "C:\Program Files (x86)\Windows Kits\10" or,
/// if multiple 10 versions are installed, set it directly to the corret bin directory "C:\Program Files (x86)\Windows Kits\10\bin\10.0.14393.0\x64"
///
/// If it is left unset, it will look up a path in the registry, i.e. HKLM\SOFTWARE\Microsoft\Windows Kits\Installed Roots
sdk_dir: Option<PathBuf>,
}

Expand Down Expand Up @@ -186,11 +193,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
)?)?
};

#[cfg(windows)]
if std::env::var("STATIC_VCRUNTIME").map_or(false, |v| v == "true") {
static_vcruntime::build();
}

cfg_alias("dev", !has_feature("custom-protocol"));

let mut manifest = Manifest::from_path("Cargo.toml")?;
Expand Down Expand Up @@ -246,9 +248,9 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}

let target_triple = std::env::var("TARGET").unwrap();
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
// TODO: far from ideal, but there's no other way to get the target dir, see <https://github.com/rust-lang/cargo/issues/5457>
let target_dir = Path::new(&out_dir)
let target_dir = out_dir
.parent()
.unwrap()
.parent()
Expand Down Expand Up @@ -344,6 +346,38 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
window_icon_path.display()
)));
}

let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
match target_env.as_str() {
"gnu" => {
let target_arch = match std::env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"x86_64" => Some("x64"),
"x86" => Some("x86"),
"aarch64" => Some("arm64"),
arch => None,
};
if let Some(target_arch) = target_arch {
for entry in std::fs::read_dir(target_dir.join("build"))? {
let path = entry?.path();
let webview2_loader_path = path
.join("out")
.join(target_arch)
.join("WebView2Loader.dll");
if path.to_string_lossy().contains("webview2-com-sys") && webview2_loader_path.exists()
{
std::fs::copy(webview2_loader_path, target_dir.join("WebView2Loader.dll"))?;
break;
}
}
}
}
"msvc" => {
if std::env::var("STATIC_VCRUNTIME").map_or(false, |v| v == "true") {
static_vcruntime::build();
}
}
_ => (),
}
}

Ok(())
Expand Down
5 changes: 0 additions & 5 deletions core/tauri-build/src/static_vcruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
use std::{env, fs, io::Write, path::Path};

pub fn build() {
// Early exit if not msvc or release
if env::var("CARGO_CFG_TARGET_ENV").as_deref() != Ok("msvc") {
return;
}

override_msvcrt_lib();

// Disable conflicting libraries that aren't hard coded by Rust.
Expand Down

0 comments on commit 58a6879

Please sign in to comment.