Skip to content

Commit 913ce3e

Browse files
daxpeddaoli-obk
authored andcommitted
Fix cross-compilation
1 parent b874810 commit 913ce3e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313

14+
* Passing `--target` to build command when cross-compiling.
15+
1416
### Changed
1517

1618
### Removed

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ impl Config {
258258
Ok(())
259259
}
260260

261+
/// Check whether the host is the specified string
262+
pub fn host_matches(&self, target: &str) -> bool {
263+
self.host.as_ref().expect("host should have been filled in") == target
264+
}
265+
261266
pub(crate) fn has_asm_support(&self) -> bool {
262267
static ASM_SUPPORTED_ARCHS: &[&str] = &[
263268
"x86", "x86_64", "arm", "aarch64", "riscv32",

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,15 @@ fn build_command(
520520
cmd.arg("--edition").arg(&*edition);
521521
}
522522

523+
if let Some(target) = &config.target {
524+
// Adding a `--target` arg to calls to Cargo will cause target folders
525+
// to create a target-specific sub-folder. We can avoid that by just
526+
// not passing a `--target` arg if its the same as the host.
527+
if !config.host_matches(target) {
528+
cmd.arg("--target").arg(target);
529+
}
530+
}
531+
523532
// False positive in miri, our `map` uses a ref pattern to get the references to the tuple fields instead
524533
// of a reference to a tuple
525534
#[allow(clippy::map_identity)]
@@ -1281,7 +1290,7 @@ fn test_condition(condition: &Condition, config: &Config) -> bool {
12811290
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
12821291
Condition::Target(t) => target.contains(t),
12831292
Condition::Host(t) => config.host.as_ref().unwrap().contains(t),
1284-
Condition::OnHost => target == config.host.as_ref().unwrap(),
1293+
Condition::OnHost => config.host_matches(target),
12851294
}
12861295
}
12871296

0 commit comments

Comments
 (0)