Skip to content

Commit

Permalink
Explicitly set windres target, fixing i686 builds from amd64
Browse files Browse the repository at this point in the history
Closes #34
  • Loading branch information
nabijaczleweli committed Apr 22, 2021
1 parent c0855cc commit 7d2c551
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/windows_not_msvc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::process::Command;
use std::path::PathBuf;
use std::env;


#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand All @@ -19,7 +20,15 @@ impl ResourceCompiler {

pub fn compile_resource(&self, out_dir: &str, prefix: &str, resource: &str) {
let out_file = format!("{}/lib{}.a", out_dir, prefix);
match Command::new("windres").args(&["--input", resource, "--output-format=coff", "--output", &out_file, "--include-dir", out_dir]).status() {
let target = 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)
};

match Command::new("windres")
.args(&["--input", resource, "--output-format=coff", "--target", target, "--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),
Expand Down

0 comments on commit 7d2c551

Please sign in to comment.