M1 primary view: wx-rs patched+extended (Linux/GTK3 build, widget bridge), vendored wx 3.3.3 + asic-rs in thirdparty/, UI-SPEC table+KPIs+dialogs, build scripts

This commit is contained in:
2026-09-15 13:59:55 -06:00
parent 165d899fd8
commit b264cdd6d1
16316 changed files with 4932188 additions and 58 deletions
+259
View File
@@ -0,0 +1,259 @@
//! A [`Cargo` build script](http://doc.crates.io/build-script.html) library to handle compilation and inclusion of Windows
//! resources in the most resilient fashion imaginable
//!
//! # Background
//!
//! Including Windows resources seems very easy at first, despite the build scripts' abhorrent documentation:
//! [compile with `windres`, then make linkable with
//! `ar`](https://github.com/nabijaczleweli/cargo-update/commit/ef4346c#diff-a7b0a2dee0126cddf994326e705a91ea).
//!
//! I was very happy with that solution until it was brought to my attention, that [MSVC uses something
//! different](https://github.com/nabijaczleweli/cargo-update/commit/f57e9c3#diff-a7b0a2dee0126cddf994326e705a91ea),
//! and now either `windres`-`ar` combo or `RC.EXE` would be used, which was OK.
//!
//! Later it transpired, that [MSVC is even more incompatible with everything
//! else](https://github.com/nabijaczleweli/cargo-update/commit/39fa758#diff-a7b0a2dee0126cddf994326e705a91ea)
//! by way of not having `RC.EXE` in `$PATH` (because it would only be reasonable to do so),
//! so another MSVC artisan made the script [find the most likely places for `RC.EXE` to
//! be](https://github.com/nabijaczleweli/cargo-update/pull/22), and the script grew yet again,
//! now standing at 100 lines and 3.2 kB.
//!
//! After [copying the build script in its
//! entirety](https://github.com/thecoshman/http/commit/98205a4#diff-a7b0a2dee0126cddf994326e705a91ea)
//! and realising how error-prone that was, then being [nudged by
//! Shepmaster](https://chat.stackoverflow.com/transcript/message/35378953#35378953)
//! to extract it to a crate, here we are.
//!
//! # Usage
//!
//! For the purposes of the demonstration we will assume that the resource file's name
//! is "checksums.rc", but it can be any name relative to the crate root.
//!
//! In `Cargo.toml`:
//!
//! ```toml
//! # The general section with crate name, license, etc.
//! build = "build.rs"
//!
//! [build-dependencies]
//! embed-resource = "1.8"
//! ```
//!
//! In `build.rs`:
//!
//! ```rust,no_run
//! extern crate embed_resource;
//!
//! fn main() {
//! embed_resource::compile("checksums.rc");
//! }
//! ```
//!
//! ## Errata
//!
//! If no `cargo:rerun-if-changed` annotations are generated, Cargo scans the entire build root by default.
//! Because the first step in building a manifest is an unspecified C preprocessor step with-out the ability to generate the equivalent of `cc -MD`, we do *not* output said annotation.
//!
//! If scanning is prohibitively expensive, or you have something else that generates the annotations, you may want to spec the full non-system dependency list for your manifest manually, so:
//! ```rust
//! println!("cargo:rerun-if-changed=app-name-manifest.rc");
//! embed_resource::compile("app-name-manifest.rc");
//! ```
//! for the above example (cf. [#41](https://github.com/nabijaczleweli/rust-embed-resource/issues/41)).
//!
//! # Cross-compilation
//!
//! It is possible to embed resources in Windows executables built on non-Windows hosts. There are two ways to do this:
//!
//! When targetting `*-pc-windows-gnu`, `*-w64-mingw32-windres` is attempted by default, for `*-pc-windows-msvc` it's `llvm-rc`,
//! this can be overriden by setting `RC_$TARGET`, `RC_${TARGET//-/_}`, or `RC` environment variables.
//!
//! When compiling with LLVM-RC, an external C compiler is used to preprocess the resource,
//! preloaded with configuration from
//! [`cc`](https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables).
//!
//! # Credit
//!
//! In chronological order:
//!
//! [@liigo](https://github.com/liigo) -- persistency in pestering me and investigating problems where I have failed
//!
//! [@mzji](https://github.com/mzji) -- MSVC lab rat
//!
//! [@TheCatPlusPlus](https://github.com/TheCatPlusPlus) -- knowledge and providing first iteration of manifest-embedding code
//!
//! [@azyobuzin](https://github.com/azyobuzin) -- providing code for finding places where RC.EXE could hide
//!
//! [@retep998](https://github.com/retep998) -- fixing MSVC support
//!
//! [@SonnyX](https://github.com/SonnyX) -- Windows cross-compilation support and testing
//!
//! [@MSxDOS](https://github.com/MSxDOS) -- finding and supplying RC.EXE its esoteric header include paths
//!
//! [@roblabla](https://github.com/roblabla) -- cross-compilation to Windows MSVC via LLVM-RC
//!
//! # Special thanks
//!
//! To all who support further development on [Patreon](https://patreon.com/nabijaczleweli), in particular:
//!
//! * ThePhD
//! * Embark Studios
//! * Lars Strojny
#[cfg(any(not(target_os = "windows"), all(target_os = "windows", target_env = "msvc")))]
extern crate cc;
extern crate toml;
#[cfg(all(target_os = "windows", target_env = "msvc"))]
extern crate vswhom;
#[cfg(all(target_os = "windows", target_env = "msvc"))]
extern crate winreg;
extern crate rustc_version;
#[cfg(not(target_os = "windows"))]
mod non_windows;
#[cfg(all(target_os = "windows", target_env = "msvc"))]
mod windows_msvc;
#[cfg(all(target_os = "windows", not(target_env = "msvc")))]
mod windows_not_msvc;
#[cfg(not(target_os = "windows"))]
use self::non_windows::*;
#[cfg(all(target_os = "windows", target_env = "msvc"))]
use self::windows_msvc::*;
#[cfg(all(target_os = "windows", not(target_env = "msvc")))]
use self::windows_not_msvc::*;
use std::{env, fs};
use std::fmt::Display;
use toml::Value as TomlValue;
use toml::map::Map as TomlMap;
use std::path::{Path, PathBuf};
/// Compile the Windows resource file and update the cargo search path if building for Windows.
///
/// On non-Windows non-Windows-cross-compile-target this does nothing, on non-MSVC Windows and Windows cross-compile targets,
/// this chains `windres` with `ar`,
/// but on MSVC Windows, this will try its hardest to find `RC.EXE` in Windows Kits and/or SDK directories,
/// falling back to [Jon Blow's VS discovery script](https://pastebin.com/3YvWQa5c),
/// and on Windows 10 `%INCLUDE%` will be updated to help `RC.EXE` find `windows.h` and friends.
///
/// `$OUT_DIR` is added to the include search path.
///
/// Note that this does *nothing* if building with rustc before 1.50.0 and there's a library in the crate,
/// since the resource is linked to the library, if any, instead of the binaries.
///
/// Since rustc 1.50.0, the resource is linked only to the binaries
/// (unless there are none, in which case it's also linked to the library).
///
/// # Examples
///
/// In your build script, assuming the crate's name is "checksums":
///
/// ```rust,no_run
/// extern crate embed_resource;
///
/// fn main() {
/// // Compile and link checksums.rc
/// embed_resource::compile("checksums.rc");
/// }
/// ```
pub fn compile<T: AsRef<Path>>(resource_file: T) {
if let Some((prefix, out_dir, out_file)) = compile_impl(resource_file.as_ref()) {
let hasbins = fs::read_to_string("Cargo.toml")
.unwrap_or_else(|err| {
eprintln!("Couldn't read Cargo.toml: {}; assuming src/main.rs or S_ISDIR(src/bin/)", err);
String::new()
})
.parse::<TomlValue>()
.unwrap_or_else(|err| {
eprintln!("Couldn't parse Cargo.toml: {}; assuming src/main.rs or S_ISDIR(src/bin/)", err);
TomlValue::Table(TomlMap::new())
})
.as_table()
.map(|t| t.contains_key("bin"))
.unwrap_or(false) || (Path::new("src/main.rs").exists() || Path::new("src/bin").is_dir());
eprintln!("Final verdict: crate has binaries: {}", hasbins);
if hasbins && rustc_version::version().expect("couldn't get rustc version") >= rustc_version::Version::new(1, 50, 0) {
println!("cargo:rustc-link-arg-bins={}", out_file);
} else {
// Cargo pre-0.51.0 (rustc pre-1.50.0) compat
// Only links to the calling crate's library
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=dylib={}", prefix);
}
}
}
/// Likewise, but only for select binaries.
///
/// Only available since rustc 1.55.0, does nothing before.
///
/// # Examples
///
/// ```rust,no_run
/// extern crate embed_resource;
///
/// fn main() {
/// embed_resource::compile_for("assets/poke-a-mango.rc", &["poke-a-mango", "poke-a-mango-installer"]);
/// embed_resource::compile_for("assets/uninstaller.rc", &["unins001"]);
/// }
/// ```
pub fn compile_for<T: AsRef<Path>, J: Display, I: IntoIterator<Item = J>>(resource_file: T, for_bins: I) {
if let Some((_, _, out_file)) = compile_impl(resource_file.as_ref()) {
for bin in for_bins {
println!("cargo:rustc-link-arg-bin={}={}", bin, out_file);
}
}
}
fn compile_impl(resource_file: &Path) -> Option<(&str, String, String)> {
let comp = ResourceCompiler::new();
if comp.is_supported() {
let prefix = &resource_file.file_stem().expect("resource_file has no stem").to_str().expect("resource_file's stem not UTF-8");
let out_dir = env::var("OUT_DIR").expect("No OUT_DIR env var");
let out_file = comp.compile_resource(&out_dir, &prefix, resource_file.to_str().expect("resource_file not UTF-8"));
Some((prefix, out_dir, out_file))
} else {
None
}
}
/// Find MSVC build tools other than the compiler and linker
///
/// On Windows + MSVC this can be used try to find tools such as `MIDL.EXE` in Windows Kits and/or SDK directories.
///
/// The compilers and linkers can be better found with the `cc` or `vswhom` crates.
/// This always returns `None` on non-MSVC targets.
///
/// # Examples
///
/// In your build script, find `midl.exe` and use it to compile an IDL file:
///
/// ```rust,no_run
/// # #[cfg(all(target_os = "windows", target_env = "msvc"))]
/// # {
/// extern crate embed_resource;
/// extern crate vswhom;
/// # use std::env;
/// # use std::process::Command;
///
/// let midl = embed_resource::find_windows_sdk_tool("midl.exe").unwrap();
///
/// // midl.exe uses cl.exe as a preprocessor, so it needs to be in PATH
/// let vs_locations = vswhom::VsFindResult::search().unwrap();
/// let output = Command::new(midl)
/// .env("PATH", vs_locations.vs_exe_path.unwrap())
/// .args(&["/out", &env::var("OUT_DIR").unwrap()])
/// .arg("haka.pfx.idl").output().unwrap();
///
/// assert!(output.status.success());
/// # }
/// ```
pub fn find_windows_sdk_tool<T: AsRef<str>>(tool: T) -> Option<PathBuf> {
find_windows_sdk_tool_impl(tool.as_ref())
}
+24
View File
@@ -0,0 +1,24 @@
//! Thin wrapper around `embed_resource::compile()`.
extern crate embed_resource;
use std::env;
fn main() {
#[cfg(target_os = "windows")]
env::set_var("TARGET",
if cfg!(target_arch = "x86_64") {
"x86_64"
} else {
"irrelevant"
});
env::set_var("OUT_DIR", ".");
let resource = env::args().nth(1).expect("Specify the resource file to be compiled as the first argument.");
embed_resource::compile(&resource);
embed_resource::compile_for(&resource, &["embed_resource", "embed_resource-installer"]);
}
+162
View File
@@ -0,0 +1,162 @@
use std::process::{Command, Stdio};
use std::path::{PathBuf, Path};
use std::borrow::Cow;
use std::{env, fs};
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ResourceCompiler {
compiler: Option<Compiler>,
}
impl ResourceCompiler {
pub fn new() -> ResourceCompiler {
ResourceCompiler { compiler: Compiler::probe() }
}
#[inline]
pub fn is_supported(&self) -> bool {
self.compiler.is_some()
}
pub fn compile_resource(&self, out_dir: &str, prefix: &str, resource: &str) -> String {
self.compiler.as_ref().expect("Not supported but we got to compile_resource()?").compile(out_dir, prefix, resource)
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
enum CompilerType {
/// LLVM-RC
///
/// Requires a separate C preprocessor step on the source RC file
LlvmRc,
/// MinGW windres
WindRes,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct Compiler {
tp: CompilerType,
executable: Cow<'static, str>,
}
impl Compiler {
pub fn probe() -> Option<Compiler> {
let target = env::var("TARGET").ok()?;
if let Some(rc) = env::var(&format!("RC_{}", target))
.or_else(|_| env::var(&format!("RC_{}", target.replace('-', "_"))))
.or_else(|_| env::var("RC"))
.ok() {
return Some(guess_compiler_variant(&rc));
}
if target.ends_with("-pc-windows-gnu") {
let executable = format!("{}-w64-mingw32-windres", &target[0..target.find('-').unwrap_or_default()]);
if is_runnable(&executable) {
return Some(Compiler {
tp: CompilerType::WindRes,
executable: executable.into(),
});
}
} else if target.ends_with("-pc-windows-msvc") {
if is_runnable("llvm-rc") {
return Some(Compiler {
tp: CompilerType::LlvmRc,
executable: "llvm-rc".into(),
});
}
}
None
}
pub fn compile(&self, out_dir: &str, prefix: &str, resource: &str) -> String {
match self.tp {
CompilerType::LlvmRc => {
let out_file = format!("{}/{}.lib", out_dir, prefix);
let preprocessed_path = format!("{}/{}-preprocessed.rc", out_dir, prefix);
fs::write(&preprocessed_path,
cc::Build::new()
.define("RC_INVOKED", None)
.flag("-xc")
.file(resource)
.cargo_metadata(false)
.include(out_dir)
.expand())
.unwrap();
try_command(Command::new(&self.executable[..])
.args(&["/fo", &out_file, "--", &preprocessed_path])
.stdin(Stdio::piped())
.current_dir(or_curdir(Path::new(resource).parent().expect("Resource parent nonexistent?"))),
Path::new(&self.executable[..]),
"compile",
&preprocessed_path,
&out_file);
out_file
}
CompilerType::WindRes => {
let out_file = format!("{}/lib{}.a", out_dir, prefix);
try_command(Command::new(&self.executable[..])
.args(&["--input", resource, "--output-format=coff", "--output", &out_file, "--include-dir", out_dir]),
Path::new(&self.executable[..]),
"compile",
resource,
&out_file);
out_file
}
}
}
}
fn try_command(cmd: &mut Command, exec: &Path, action: &str, whom: &str, whre: &str) {
match cmd.status() {
Ok(stat) if stat.success() => {}
Ok(stat) => panic!("{} failed to {} \"{}\" into \"{}\" with {}", exec.display(), action, whom, whre, stat),
Err(e) => panic!("Couldn't execute {} to {} \"{}\" into \"{}\": {}", exec.display(), action, whom, whre, e),
}
}
fn or_curdir(directory: &Path) -> &Path {
if directory == Path::new("") {
Path::new(".")
} else {
directory
}
}
/// -V will print the version in windres.
/// /? will print the help in LLVM-RC and Microsoft RC.EXE.
/// If combined, /? takes precedence over -V.
fn guess_compiler_variant(s: &str) -> Compiler {
match Command::new(s).args(&["-V", "/?"]).output() {
Ok(out) => {
if out.stdout.starts_with(b"GNU windres") {
Compiler {
executable: s.to_string().into(),
tp: CompilerType::WindRes,
}
} else if out.stdout.starts_with(b"OVERVIEW: Resource Converter") {
Compiler {
executable: s.to_string().into(),
tp: CompilerType::LlvmRc,
}
} else {
panic!("Unknown RC compiler variant: {}", s)
}
}
Err(err) => panic!("Couldn't execute {}: {}", s, err),
}
}
fn is_runnable(s: &str) -> bool {
Command::new(s).spawn().map(|mut c| c.kill()).is_ok()
}
pub fn find_windows_sdk_tool_impl(_: &str) -> Option<PathBuf> {
None
}
+192
View File
@@ -0,0 +1,192 @@
use std::sync::atomic::Ordering::SeqCst;
use std::sync::atomic::AtomicBool;
use std::path::{PathBuf, Path};
use std::process::Command;
use vswhom::VsFindResult;
use winreg::enums::*;
use std::{env, fs};
use winreg;
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ResourceCompiler;
impl ResourceCompiler {
#[inline(always)]
pub fn new() -> ResourceCompiler {
ResourceCompiler
}
#[inline(always)]
pub fn is_supported(&self) -> bool {
true
}
pub fn compile_resource(&self, out_dir: &str, prefix: &str, resource: &str) -> String {
let out_file = format!("{}/{}.lib", out_dir, prefix);
// `.res`es are linkable under MSVC as well as normal libraries.
if !Command::new(find_windows_sdk_tool_impl("rc.exe").as_ref().map_or(Path::new("rc.exe"), Path::new))
.args(&["/fo", &out_file, "/I", out_dir, resource])
.status()
.expect("Are you sure you have RC.EXE in your $PATH?")
.success() {
panic!("RC.EXE failed to compile specified resource file");
}
out_file
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
enum Arch {
X86,
X64,
}
pub fn find_windows_sdk_tool_impl(tool: &str) -> Option<PathBuf> {
let arch = if env::var("TARGET").expect("No TARGET env var").starts_with("x86_64") {
Arch::X64
} else {
Arch::X86
};
find_windows_10_kits_tool("KitsRoot10", arch, tool)
.or_else(|| find_windows_kits_tool("KitsRoot10", arch, tool))
.or_else(|| find_windows_kits_tool("KitsRoot81", arch, tool))
.or_else(|| find_windows_kits_tool("KitsRoot", arch, tool))
.or_else(|| find_latest_windows_sdk_tool(arch, tool))
.or_else(|| find_with_vswhom(arch, tool))
}
fn find_with_vswhom(arch: Arch, tool: &str) -> Option<PathBuf> {
let res = VsFindResult::search();
res.as_ref()
.and_then(|res| res.windows_sdk_root.as_ref())
.map(PathBuf::from)
.and_then(|mut root| {
let ver = root.file_name().expect("malformed vswhom-returned SDK root").to_os_string();
root.pop();
root.pop();
root.push("bin");
root.push(ver);
try_bin_dir(root, "x86", "x64", arch)
})
.and_then(|pb| try_tool(pb, tool))
.or_else(move || {
res.and_then(|res| res.windows_sdk_root)
.map(PathBuf::from)
.and_then(|mut root| {
root.pop();
root.pop();
try_bin_dir(root, "bin/x86", "bin/x64", arch)
})
.and_then(|pb| try_tool(pb, tool))
})
}
// Windows 8 - 10
fn find_windows_kits_tool(key: &str, arch: Arch, tool: &str) -> Option<PathBuf> {
winreg::RegKey::predef(HKEY_LOCAL_MACHINE)
.open_subkey_with_flags(r"SOFTWARE\Microsoft\Windows Kits\Installed Roots", KEY_QUERY_VALUE)
.and_then(|reg_key| reg_key.get_value::<String, _>(key))
.ok()
.and_then(|root_dir| try_bin_dir(root_dir, "bin/x86", "bin/x64", arch))
.and_then(|pb| try_tool(pb, tool))
}
// Windows Vista - 7
fn find_latest_windows_sdk_tool(arch: Arch, tool: &str) -> Option<PathBuf> {
winreg::RegKey::predef(HKEY_LOCAL_MACHINE)
.open_subkey_with_flags(r"SOFTWARE\Microsoft\Microsoft SDKs\Windows", KEY_QUERY_VALUE)
.and_then(|reg_key| reg_key.get_value::<String, _>("CurrentInstallFolder"))
.ok()
.and_then(|root_dir| try_bin_dir(root_dir, "Bin", "Bin/x64", arch))
.and_then(|pb| try_tool(pb, tool))
}
// Windows 10 with subdir support
fn find_windows_10_kits_tool(key: &str, arch: Arch, tool: &str) -> Option<PathBuf> {
let kit_root = (winreg::RegKey::predef(HKEY_LOCAL_MACHINE)
.open_subkey_with_flags(r"SOFTWARE\Microsoft\Windows Kits\Installed Roots", KEY_QUERY_VALUE)
.and_then(|reg_key| reg_key.get_value::<String, _>(key))
.ok())?;
include_windows_10_kits(&kit_root);
let root_dir = kit_root + "/bin";
for entry in fs::read_dir(&root_dir).ok()?.filter(|d| d.is_ok()).map(Result::unwrap) {
let fname = entry.file_name().into_string();
let ftype = entry.file_type();
if fname.is_err() || ftype.is_err() || ftype.unwrap().is_file() {
continue;
}
let fname = entry.file_name().into_string().unwrap();
if let Some(rc) = try_bin_dir(root_dir.clone(), &format!("{}/x86", fname), &format!("{}/x64", fname), arch).and_then(|pb| try_tool(pb, tool)) {
return Some(rc);
}
}
None
}
/// Update %INCLUDE% to contain all \Include\<version>\ folders before invoking rc.exe
/// (https://github.com/nabijaczleweli/rust-embed-resource/pull/17),
/// fixing "Unable to find windows.h" errors (https://github.com/nabijaczleweli/rust-embed-resource/issues/11)
fn include_windows_10_kits(kit_root: &str) {
static IS_INCLUDED: AtomicBool = AtomicBool::new(false);
if !IS_INCLUDED.swap(true, SeqCst) {
let mut include = env::var("INCLUDE").unwrap_or_default();
if !include.ends_with(';') {
include.push(';');
}
if let Ok(include_root) = fs::read_dir(kit_root.to_string() + r"\Include\") {
get_dirs(include_root).filter_map(|dir| fs::read_dir(dir.path()).ok()).for_each(|dir| {
get_dirs(dir).for_each(|sub_dir| if let Some(sub_dir) = sub_dir.path().to_str() {
if !include.contains(sub_dir) {
include.push_str(sub_dir);
include.push(';');
}
})
});
}
if let Some(cl) = cc::windows_registry::find_tool(env::var("TARGET").expect("No TARGET env var").as_str(), "cl.exe") {
if let Some((_, ipaths)) = cl.env().iter().find(|(k, _)| k == "INCLUDE") {
include.push_str(ipaths.to_str().expect("%INCLUDE% from cc nonrepresentable"));
include.push(';');
}
}
env::set_var("INCLUDE", include);
}
}
fn get_dirs(read_dir: fs::ReadDir) -> impl Iterator<Item = fs::DirEntry> {
read_dir.filter_map(|dir| dir.ok()).filter(|dir| dir.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
}
fn try_bin_dir<R: Into<PathBuf>>(root_dir: R, x86_bin: &str, x64_bin: &str, arch: Arch) -> Option<PathBuf> {
try_bin_dir_impl(root_dir.into(), x86_bin, x64_bin, arch)
}
fn try_bin_dir_impl(mut root_dir: PathBuf, x86_bin: &str, x64_bin: &str, arch: Arch) -> Option<PathBuf> {
match arch {
Arch::X86 => root_dir.push(x86_bin),
Arch::X64 => root_dir.push(x64_bin),
}
if root_dir.is_dir() {
Some(root_dir)
} else {
None
}
}
fn try_tool(mut pb: PathBuf, tool: &str) -> Option<PathBuf> {
pb.push(tool);
if pb.exists() { Some(pb) } else { None }
}
+53
View File
@@ -0,0 +1,53 @@
use std::process::Command;
use std::path::PathBuf;
use std::borrow::Cow;
use std::ffi::OsStr;
use std::env;
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ResourceCompiler;
impl ResourceCompiler {
#[inline(always)]
pub fn new() -> ResourceCompiler {
ResourceCompiler
}
#[inline(always)]
pub fn is_supported(&self) -> bool {
true
}
pub fn compile_resource(&self, out_dir: &str, prefix: &str, resource: &str) -> String {
let out_file = format!("{}/lib{}.a", out_dir, prefix);
// Under some msys2 environments, $MINGW_CHOST has the correct target for
// GNU windres or llvm-windres (clang32, clang64, or clangarm64)
let target = env::var_os("MINGW_CHOST").map(Cow::Owned).unwrap_or_else(|| {
OsStr::new(if env::var("TARGET").expect("No TARGET env var").starts_with("x86_64") {
"pe-x86-64" // Default for amd64 windres
} else {
"pe-i386" // This is wrong for ARM Windows, but I couldn't find a triple for it (if it exists at all)
})
.into()
});
match Command::new("windres")
.args(&["--input", resource, "--output-format=coff", "--target"])
.arg(target)
.args(&["--output", &out_file, "--include-dir", out_dir])
.status() {
Ok(stat) if stat.success() => {}
Ok(stat) => panic!("windres failed to compile \"{}\" into \"{}\" with {}", resource, out_file, stat),
Err(e) => panic!("Couldn't to execute windres to compile \"{}\" into \"{}\": {}", resource, out_file, e),
}
out_file
}
}
pub fn find_windows_sdk_tool_impl(_: &str) -> Option<PathBuf> {
None
}