Skip to content

Commit 94f4cb2

Browse files
authored
Add support for cross-compiled binaries (#25)
1 parent 81eafe6 commit 94f4cb2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct Args {
1919
pub forwarded_args: Vec<OsString>,
2020
/// "debug", "release" etc.
2121
pub profile: String,
22+
/// The target architecture. None for native builds.
23+
pub arch: Option<String>,
2224
/// The absolute path to the Cargo.toml file. Currently the --manifest-path option is not implemented.
2325
pub manifest_path: PathBuf,
2426
}
@@ -60,6 +62,10 @@ impl ArgsOrHelp {
6062
String::from("debug")
6163
};
6264

65+
let arch = args
66+
.opt_value_from_str("--target")?
67+
.or_else(|| std::env::var("CARGO_BUILD_TARGET").ok());
68+
6369
let build_base = args
6470
.opt_value_from_str("--target-dir")?
6571
.unwrap_or_else(|| "target".into());
@@ -78,6 +84,7 @@ impl ArgsOrHelp {
7884
build_base,
7985
forwarded_args,
8086
profile,
87+
arch,
8188
manifest_path,
8289
};
8390

@@ -222,9 +229,15 @@ pub fn install_binaries(
222229
build_base: impl AsRef<Path>,
223230
package_name: &str,
224231
profile: &str,
232+
arch: Option<&str>,
225233
binaries: &[Product],
226234
) -> Result<()> {
227-
let src_dir = build_base.as_ref().join(profile);
235+
let src_dir = if let Some(arch) = arch {
236+
build_base.as_ref().join(arch).join(profile)
237+
} else {
238+
build_base.as_ref().join(profile)
239+
};
240+
228241
let dest_dir = install_base.as_ref().join("lib").join(package_name);
229242
if dest_dir.is_dir() {
230243
std::fs::remove_dir_all(&dest_dir)?;

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ fn fallible_main() -> Result<bool> {
7878
&args.build_base,
7979
package_name,
8080
&args.profile,
81+
args.arch.as_deref(),
8182
// Unwrap is safe since complete_from_path() has been called
8283
&manifest.bin,
8384
)?;

0 commit comments

Comments
 (0)