diff --git a/.changes/static-vcruntime.md b/.changes/static-vcruntime.md new file mode 100644 index 000000000..816549303 --- /dev/null +++ b/.changes/static-vcruntime.md @@ -0,0 +1,8 @@ +--- +"tauri-build": patch +"tauri-bundler": patch +"cli.rs": patch +"cli.js": patch +--- + +Statically link the Visual C++ runtime instead of using a merge module on the installer. diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index f2ba731e3..e8102e004 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -12,6 +12,8 @@ use std::path::{Path, PathBuf}; #[cfg(feature = "codegen")] mod codegen; +#[cfg(windows)] +mod static_vcruntime; #[cfg(feature = "codegen")] #[cfg_attr(doc_cfg, doc(cfg(feature = "codegen")))] @@ -184,6 +186,9 @@ pub fn try_build(attributes: Attributes) -> Result<()> { )?)? }; + #[cfg(windows)] + static_vcruntime::build(); + cfg_alias("dev", !has_feature("custom-protocol")); let mut manifest = Manifest::from_path("Cargo.toml")?; diff --git a/core/tauri-build/src/static_vcruntime.rs b/core/tauri-build/src/static_vcruntime.rs new file mode 100644 index 000000000..2d548dca2 --- /dev/null +++ b/core/tauri-build/src/static_vcruntime.rs @@ -0,0 +1,63 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +// taken from https://github.com/ChrisDenton/static_vcruntime/ +// we're not using static_vcruntime directly because we want this for debug builds too + +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. + println!("cargo:rustc-link-arg=/NODEFAULTLIB:libvcruntimed.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:vcruntime.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:vcruntimed.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:libcmtd.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:msvcrt.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:msvcrtd.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:libucrt.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:libucrtd.lib"); + // Set the libraries we want. + println!("cargo:rustc-link-arg=/DEFAULTLIB:libcmt.lib"); + println!("cargo:rustc-link-arg=/DEFAULTLIB:libvcruntime.lib"); + println!("cargo:rustc-link-arg=/DEFAULTLIB:ucrt.lib"); +} + +/// Override the hard-coded msvcrt.lib by replacing it with a (mostly) empty object file. +fn override_msvcrt_lib() { + // Get the right machine type for the empty library. + let arch = std::env::var("CARGO_CFG_TARGET_ARCH"); + let machine: &[u8] = if arch.as_deref() == Ok("x86_64") { + &[0x64, 0x86] + } else if arch.as_deref() == Ok("x86") { + &[0x4C, 0x01] + } else { + return; + }; + let bytes: &[u8] = &[ + 1, 0, 94, 3, 96, 98, 60, 0, 0, 0, 1, 0, 0, 0, 0, 0, 132, 1, 46, 100, 114, 101, 99, 116, 118, + 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 10, 16, 0, 46, 100, 114, 101, 99, 116, 118, 101, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 4, 0, 0, 0, + ]; + + // Write the empty "msvcrt.lib" to the output directory. + let out_dir = env::var("OUT_DIR").unwrap(); + let path = Path::new(&out_dir).join("msvcrt.lib"); + let f = fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(&path); + if let Ok(mut f) = f { + f.write_all(machine).unwrap(); + f.write_all(bytes).unwrap(); + } + // Add the output directory to the native library path. + println!("cargo:rustc-link-search=native={}", out_dir); +} diff --git a/core/tests/app-updater/build.rs b/core/tests/app-updater/build.rs index 71557e5b9..03f0ee177 100644 --- a/core/tests/app-updater/build.rs +++ b/core/tests/app-updater/build.rs @@ -2,6 +2,4 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -fn main() { - tauri_build::build() -} +fn main() {} diff --git a/core/tests/app-updater/tests/update.rs b/core/tests/app-updater/tests/update.rs index 3b47b459a..e6d7f8a13 100644 --- a/core/tests/app-updater/tests/update.rs +++ b/core/tests/app-updater/tests/update.rs @@ -57,8 +57,7 @@ fn get_cli_bin_path(cli_dir: &Path, debug: bool) -> Option { fn build_app(cli_bin_path: &Path, cwd: &Path, config: &Config, bundle_updater: bool) { let mut command = Command::new(&cli_bin_path); command - .arg("build") - .arg("--debug") + .args(["build", "--debug", "--verbose"]) .arg("--config") .arg(serde_json::to_string(config).unwrap()) .current_dir(&cwd); diff --git a/examples/updater/src-tauri/Cargo.lock b/examples/updater/src-tauri/Cargo.lock index 9e9a0eca6..5df1e96be 100644 --- a/examples/updater/src-tauri/Cargo.lock +++ b/examples/updater/src-tauri/Cargo.lock @@ -1511,6 +1511,15 @@ dependencies = [ "syn", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -2539,7 +2548,7 @@ dependencies = [ [[package]] name = "tauri" -version = "1.0.0-rc.11" +version = "1.0.0-rc.13" dependencies = [ "anyhow", "attohttpc", @@ -2577,6 +2586,7 @@ dependencies = [ "tauri-utils", "tempfile", "thiserror", + "time", "tokio", "url", "uuid 1.0.0", @@ -2588,10 +2598,11 @@ dependencies = [ [[package]] name = "tauri-build" -version = "1.0.0-rc.9" +version = "1.0.0-rc.11" dependencies = [ "anyhow", "cargo_toml", + "heck 0.4.0", "quote", "semver 1.0.9", "serde_json", @@ -2610,6 +2621,7 @@ dependencies = [ "png 0.17.5", "proc-macro2", "quote", + "semver 1.0.9", "serde", "serde_json", "sha2", @@ -2633,7 +2645,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "0.5.1" +version = "0.6.0" dependencies = [ "gtk", "http", @@ -2650,7 +2662,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "0.5.2" +version = "0.6.0" dependencies = [ "cocoa", "gtk", @@ -2680,6 +2692,7 @@ dependencies = [ "phf 0.10.1", "proc-macro2", "quote", + "semver 1.0.9", "serde", "serde_json", "serde_with", @@ -2748,6 +2761,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" +dependencies = [ + "itoa 1.0.2", + "libc", + "num_threads", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/tooling/bundler/src/bundle/windows/templates/main.wxs b/tooling/bundler/src/bundle/windows/templates/main.wxs index 7ea8a7211..fe3a2ac93 100644 --- a/tooling/bundler/src/bundle/windows/templates/main.wxs +++ b/tooling/bundler/src/bundle/windows/templates/main.wxs @@ -26,8 +26,8 @@ SummaryCodepage="!(loc.TauriCodepage)"/> - - + + {{#if allow_downgrades}} diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index d8e2ca335..291f295f4 100644 --- a/tooling/cli/Cargo.lock +++ b/tooling/cli/Cargo.lock @@ -2805,6 +2805,7 @@ dependencies = [ "memchr", "phf 0.10.1", "schemars", + "semver", "serde", "serde_json", "serde_with", diff --git a/tooling/cli/Cargo.toml b/tooling/cli/Cargo.toml index c6296a4e2..3174ff1ee 100644 --- a/tooling/cli/Cargo.toml +++ b/tooling/cli/Cargo.toml @@ -15,7 +15,6 @@ description = "Command line interface for building Tauri apps" include = [ "src/", "/templates", - "MergeModules/", "scripts/", "*.json", "*.rs", diff --git a/tooling/cli/MergeModules/Microsoft_VC142_CRT_x64.msm b/tooling/cli/MergeModules/Microsoft_VC142_CRT_x64.msm deleted file mode 100644 index 0681b2680..000000000 Binary files a/tooling/cli/MergeModules/Microsoft_VC142_CRT_x64.msm and /dev/null differ diff --git a/tooling/cli/MergeModules/Microsoft_VC142_CRT_x86.msm b/tooling/cli/MergeModules/Microsoft_VC142_CRT_x86.msm deleted file mode 100644 index b65780f05..000000000 Binary files a/tooling/cli/MergeModules/Microsoft_VC142_CRT_x86.msm and /dev/null differ diff --git a/tooling/cli/src/build.rs b/tooling/cli/src/build.rs index 81f0ec5e9..7e88a892d 100644 --- a/tooling/cli/src/build.rs +++ b/tooling/cli/src/build.rs @@ -240,43 +240,6 @@ pub fn command(options: Options) -> Result<()> { } if config_.tauri.bundle.active { - // move merge modules to the out dir so the bundler can load it - #[cfg(windows)] - { - let target = options - .target - .clone() - .unwrap_or_else(|| std::env::consts::ARCH.into()); - let arch = if target.starts_with("x86_64") { - "x86_64" - } else if target.starts_with('i') || target.starts_with("x86") { - "x86" - } else if target.starts_with("arm") { - "arm" - } else if target.starts_with("aarch64") { - "aarch64" - } else { - panic!( - "Unexpected target architecture {}", - target.split('_').next().unwrap() - ) - }; - let (filename, vcruntime_msm) = if arch == "x86" { - let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x64.msm")); - ( - "Microsoft_VC142_CRT_x86.msm", - include_bytes!("../MergeModules/Microsoft_VC142_CRT_x86.msm").to_vec(), - ) - } else { - let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x86.msm")); - ( - "Microsoft_VC142_CRT_x64.msm", - include_bytes!("../MergeModules/Microsoft_VC142_CRT_x64.msm").to_vec(), - ) - }; - std::fs::write(out_dir.join(filename), vcruntime_msm)?; - } - let package_types = if let Some(names) = options.bundles { let mut types = vec![]; for name in names {