Fix cross compile build scripts

This commit is contained in:
Caelan Sayler
2025-05-18 21:20:56 +01:00
committed by Caelan
parent cf68dcb0ea
commit b16fdf6983
5 changed files with 49 additions and 57 deletions

21
Cargo.lock generated
View File

@@ -321,7 +321,7 @@ dependencies = [
"serde_json", "serde_json",
"syn 2.0.101", "syn 2.0.101",
"tempfile", "tempfile",
"toml 0.8.22", "toml",
] ]
[[package]] [[package]]
@@ -2050,15 +2050,6 @@ dependencies = [
"zerovec", "zerovec",
] ]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.22" version = "0.8.22"
@@ -2327,7 +2318,6 @@ dependencies = [
"walkdir", "walkdir",
"webview2-com-sys", "webview2-com-sys",
"windows", "windows",
"winres",
"winsafe", "winsafe",
"zip", "zip",
"zstd", "zstd",
@@ -2843,15 +2833,6 @@ dependencies = [
"memchr", "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]] [[package]]
name = "winsafe" name = "winsafe"
version = "0.0.20" version = "0.0.20"

View File

@@ -61,7 +61,6 @@ sha1_smol = "1.0"
time = "0.3" time = "0.3"
os_info = "3.8" os_info = "3.8"
neon = "1" neon = "1"
winres = "0.1"
tempfile = "3.9" tempfile = "3.9"
ntest = "0.9" ntest = "0.9"
pretty_assertions = "1.4" pretty_assertions = "1.4"

View File

@@ -127,6 +127,3 @@ pretty_assertions.workspace = true
[build-dependencies] [build-dependencies]
semver.workspace = true semver.workspace = true
[target.'cfg(windows)'.build-dependencies]
winres.workspace = true

View File

@@ -1,33 +1,31 @@
#![allow(unused_variables)] #![allow(unused_variables)]
use std::env; use std::{env, path::Path};
fn main() { fn main() {
#[cfg(target_os = "windows")]
delay_load();
let version = env!("CARGO_PKG_VERSION"); let version = env!("CARGO_PKG_VERSION");
let ver = semver::Version::parse(&version).expect("Unable to parse ngbv output as semver 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 ver: u64 = ver.major << 48 | ver.minor << 32 | ver.patch << 16;
let desc = format!("Velopack {}", version); let desc = format!("Velopack {}", version);
println!("cargo:rustc-env=NGBV_VERSION={}", version); println!("cargo:rustc-env=NGBV_VERSION={}", version);
#[cfg(target_os = "windows")] let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
winres::WindowsResource::new() if target_os == "windows" {
.set_manifest_file("app.manifest") delay_load();
.set_version_info(winres::VersionInfo::PRODUCTVERSION, ver) link_manifest_msvc(Path::new("app.manifest"));
.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();
} }
#[cfg(target_os = "windows")] 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");
}
fn delay_load() { fn delay_load() {
let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default(); let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default();
if features.contains("crt-static") { if features.contains("crt-static") {
@@ -42,7 +40,6 @@ fn delay_load() {
} }
// https://github.com/rust-lang/rustup/blob/master/build.rs#L45 // https://github.com/rust-lang/rustup/blob/master/build.rs#L45
#[cfg(target_os = "windows")]
fn delay_load_exe(bin_name: &str) { fn delay_load_exe(bin_name: &str) {
// Only search system32 for DLLs // Only search system32 for DLLs
// This applies to DLLs loaded at load time. However, this setting is ignored // This applies to DLLs loaded at load time. However, this setting is ignored

View File

@@ -3,6 +3,21 @@ extern crate cbindgen;
use std::env; use std::env;
fn main() { 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(); let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::Builder::new() cbindgen::Builder::new()
.with_crate(crate_dir) .with_crate(crate_dir)
@@ -15,4 +30,7 @@ fn main() {
.generate() .generate()
.expect("Unable to generate bindings") .expect("Unable to generate bindings")
.write_to_file("include/Velopack.h"); .write_to_file("include/Velopack.h");
} else {
println!("cargo:warning=Skipping cbindgen during cross-compilation (host OS: {}, target OS: {})", host_os, target_os);
}
} }