From 4ba66223d5289e7c75917ecf89dec30a80c585e3 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sun, 18 May 2025 23:10:47 +0100 Subject: [PATCH] Revert "Fix cross compile build scripts" This reverts commit cb02fbaa1efa2c5a3a96d8049892c88f852e5984. --- Cargo.lock | 21 ++++++++++++++++++++- Cargo.toml | 1 + src/bins/Cargo.toml | 5 ++++- src/bins/build.rs | 35 +++++++++++++++++++---------------- src/lib-cpp/build.rs | 44 +++++++++++++------------------------------- 5 files changed, 57 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1baf3b68..7e0d5ec1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,7 +321,7 @@ dependencies = [ "serde_json", "syn 2.0.101", "tempfile", - "toml", + "toml 0.8.22", ] [[package]] @@ -2050,6 +2050,15 @@ dependencies = [ "zerovec", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "toml" version = "0.8.22" @@ -2318,6 +2327,7 @@ dependencies = [ "walkdir", "webview2-com-sys", "windows", + "winres", "winsafe", "zip", "zstd", @@ -2833,6 +2843,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winres" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" +dependencies = [ + "toml 0.5.11", +] + [[package]] name = "winsafe" version = "0.0.20" diff --git a/Cargo.toml b/Cargo.toml index 398341e6..3f2bcfaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ sha1_smol = "1.0" time = "0.3" os_info = "3.8" neon = "1" +winres = "0.1" tempfile = "3.9" ntest = "0.9" pretty_assertions = "1.4" diff --git a/src/bins/Cargo.toml b/src/bins/Cargo.toml index c01ef1c3..6bdbd77d 100644 --- a/src/bins/Cargo.toml +++ b/src/bins/Cargo.toml @@ -126,4 +126,7 @@ ntest.workspace = true pretty_assertions.workspace = true [build-dependencies] -semver.workspace = true \ No newline at end of file +semver.workspace = true + +[target.'cfg(windows)'.build-dependencies] +winres.workspace = true diff --git a/src/bins/build.rs b/src/bins/build.rs index 606e4c9a..8c055252 100644 --- a/src/bins/build.rs +++ b/src/bins/build.rs @@ -1,31 +1,33 @@ #![allow(unused_variables)] -use std::{env, path::Path}; +use std::env; fn main() { + #[cfg(target_os = "windows")] + delay_load(); + let version = env!("CARGO_PKG_VERSION"); let ver = semver::Version::parse(&version).expect("Unable to parse ngbv output as semver version"); let ver: u64 = ver.major << 48 | ver.minor << 32 | ver.patch << 16; let desc = format!("Velopack {}", version); + println!("cargo:rustc-env=NGBV_VERSION={}", version); - let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); - if target_os == "windows" { - delay_load(); - link_manifest_msvc(Path::new("app.manifest")); - } + #[cfg(target_os = "windows")] + winres::WindowsResource::new() + .set_manifest_file("app.manifest") + .set_version_info(winres::VersionInfo::PRODUCTVERSION, ver) + .set_version_info(winres::VersionInfo::FILEVERSION, ver) + .set("CompanyName", "Velopack") + .set("ProductName", "Velopack") + .set("ProductVersion", &version) + .set("FileDescription", &desc) + .set("LegalCopyright", "Caelan Sayler (c) 2023, Velopack Ltd. (c) 2024") + .compile() + .unwrap(); } -fn link_manifest_msvc(manifest_path: &Path) { - println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); - println!( - "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", - manifest_path.canonicalize().unwrap().display() - ); - println!("cargo:rustc-link-arg-bins=/MANIFESTUAC:NO"); -} - - +#[cfg(target_os = "windows")] fn delay_load() { let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default(); if features.contains("crt-static") { @@ -40,6 +42,7 @@ fn delay_load() { } // https://github.com/rust-lang/rustup/blob/master/build.rs#L45 +#[cfg(target_os = "windows")] fn delay_load_exe(bin_name: &str) { // Only search system32 for DLLs // This applies to DLLs loaded at load time. However, this setting is ignored diff --git a/src/lib-cpp/build.rs b/src/lib-cpp/build.rs index 0ce2c645..0b712a61 100644 --- a/src/lib-cpp/build.rs +++ b/src/lib-cpp/build.rs @@ -3,34 +3,16 @@ extern crate cbindgen; use std::env; fn main() { - let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); - let host_triple = env::var("HOST").unwrap_or_default(); - - // Extract host OS from the host triple - let host_os = if host_triple.contains("linux") { - "linux" - } else if host_triple.contains("windows") { - "windows" - } else if host_triple.contains("macos") || host_triple.contains("darwin") { - "macos" - } else { - "unknown" - }; - - if host_os == target_os { - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - cbindgen::Builder::new() - .with_crate(crate_dir) - .with_documentation(true) - .with_language(cbindgen::Language::C) - .with_autogen_warning("/* THIS FILE IS AUTO-GENERATED - DO NOT EDIT */") - .with_include_guard("VELOPACK_H") - .with_cpp_compat(true) - .with_include_version(true) - .generate() - .expect("Unable to generate bindings") - .write_to_file("include/Velopack.h"); - } else { - println!("cargo:warning=Skipping cbindgen during cross-compilation (host OS: {}, target OS: {})", host_os, target_os); - } -} + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_documentation(true) + .with_language(cbindgen::Language::C) + .with_autogen_warning("/* THIS FILE IS AUTO-GENERATED - DO NOT EDIT */") + .with_include_guard("VELOPACK_H") + .with_cpp_compat(true) + .with_include_version(true) + .generate() + .expect("Unable to generate bindings") + .write_to_file("include/Velopack.h"); +} \ No newline at end of file