Skip to content

Commit 2b6787c

Browse files
authored
Merge pull request #18 from 999eagle/feature/cross-compilation
Make windres and ar paths configurable
2 parents 0eb3973 + 6d4c335 commit 2b6787c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Diff for: lib.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ pub struct WindowsResource {
9090
manifest: Option<String>,
9191
manifest_file: Option<String>,
9292
output_directory: String,
93+
windres_path: Option<String>,
94+
ar_path: Option<String>,
9395
}
9496

9597
impl WindowsResource {
@@ -185,6 +187,8 @@ impl WindowsResource {
185187
manifest: None,
186188
manifest_file: None,
187189
output_directory: env::var("OUT_DIR").unwrap_or(".".to_string()),
190+
windres_path: None,
191+
ar_path: None,
188192
}
189193
}
190194

@@ -352,6 +356,18 @@ impl WindowsResource {
352356
self
353357
}
354358

359+
/// Set the path to the windres executable.
360+
pub fn set_windres_path(&mut self, path: &str) -> &mut Self {
361+
self.windres_path = Some(path.to_string());
362+
self
363+
}
364+
365+
/// Set the path to the ar executable.
366+
pub fn set_ar_path(&mut self, path: &str) -> &mut Self {
367+
self.ar_path = Some(path.to_string());
368+
self
369+
}
370+
355371
/// Write a resource file with the set values
356372
pub fn write_resource_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
357373
let mut f = try!(fs::File::create(path));
@@ -432,7 +448,8 @@ impl WindowsResource {
432448
fn compile_with_toolkit<'a>(&self, input: &'a str, output_dir: &'a str) -> io::Result<()> {
433449
let output = PathBuf::from(output_dir).join("resource.o");
434450
let input = PathBuf::from(input);
435-
let status = process::Command::new("windres.exe")
451+
let windres_path = self.windres_path.as_ref().map_or("windres.exe", String::as_str);
452+
let status = process::Command::new(windres_path)
436453
.current_dir(&self.toolkit_path)
437454
.arg(format!("-I{}", env::var("CARGO_MANIFEST_DIR").unwrap()))
438455
.arg(format!("{}", input.display()))
@@ -443,7 +460,8 @@ impl WindowsResource {
443460
}
444461

445462
let libname = PathBuf::from(output_dir).join("libresource.a");
446-
let status = process::Command::new("ar.exe")
463+
let ar_path = self.ar_path.as_ref().map_or("ar.exe", String::as_str);
464+
let status = process::Command::new(ar_path)
447465
.current_dir(&self.toolkit_path)
448466
.arg("rsc")
449467
.arg(format!("{}", libname.display()))

0 commit comments

Comments
 (0)