Revert "Fix cross compile build scripts"

This reverts commit cb02fbaa1e.
This commit is contained in:
Caelan Sayler
2025-05-18 23:10:47 +01:00
committed by Caelan
parent b56f9b8398
commit 4ba66223d5
5 changed files with 57 additions and 49 deletions

View File

@@ -126,4 +126,7 @@ ntest.workspace = true
pretty_assertions.workspace = true
[build-dependencies]
semver.workspace = true
semver.workspace = true
[target.'cfg(windows)'.build-dependencies]
winres.workspace = true

View File

@@ -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

View File

@@ -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");
}