diff --git a/.changes/improve-windows-gnu-support.md b/.changes/improve-windows-gnu-support.md new file mode 100644 index 000000000..aeadb5585 --- /dev/null +++ b/.changes/improve-windows-gnu-support.md @@ -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. diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 08800810e..25226ec11 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -89,9 +89,16 @@ fn cfg_alias(alias: &str, has_feature: bool) { #[derive(Debug, Default)] pub struct WindowsAttributes { window_icon_path: Option, - /// 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, } @@ -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")?; @@ -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 - let target_dir = Path::new(&out_dir) + let target_dir = out_dir .parent() .unwrap() .parent() @@ -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(()) diff --git a/core/tauri-build/src/static_vcruntime.rs b/core/tauri-build/src/static_vcruntime.rs index 2d548dca2..11d2752b9 100644 --- a/core/tauri-build/src/static_vcruntime.rs +++ b/core/tauri-build/src/static_vcruntime.rs @@ -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.