Skip to content

Commit

Permalink
Merge #1301
Browse files Browse the repository at this point in the history
1301: Fix wrong platform tag when building in i386 docker container r=messense a=messense

Fixes the i386 issue reported in #1289 (comment).

We can not trust the return value of `uname -m` in Docker container.

Co-authored-by: messense <[email protected]>
  • Loading branch information
bors[bot] and messense authored Nov 27, 2022
2 parents 4bceaa5 + 4c6a3f0 commit c5eb723
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Bump MSRV to 1.62.0 in [#1297](https://github.com/PyO3/maturin/pull/1297)
* Fix build error when required features of bin target isn't enabled in [#1299](https://github.com/PyO3/maturin/pull/1299)
* Fix wrong platform tag when building in i386 docker container in [#1301](https://github.com/PyO3/maturin/pull/1301)

## [0.14.2] - 2022-11-24

Expand Down
32 changes: 25 additions & 7 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::str;
use target_lexicon::{Architecture, Environment, Triple};
use tracing::error;

pub(crate) const RUST_1_64_0: semver::Version = semver::Version::new(1, 64, 0);

Expand Down Expand Up @@ -297,13 +298,7 @@ impl Target {
}
// Linux
(Os::Linux, _) => {
let arch = if self.cross_compiling {
self.arch.to_string()
} else {
PlatformInfo::new()
.map(|info| info.machine().into_owned())
.unwrap_or_else(|_| self.arch.to_string())
};
let arch = self.get_platform_arch()?;
let mut platform_tags = platform_tags.to_vec();
platform_tags.sort();
let mut tags = vec![];
Expand Down Expand Up @@ -366,6 +361,29 @@ impl Target {
Ok(tag)
}

fn get_platform_arch(&self) -> Result<String> {
if self.cross_compiling {
return Ok(self.arch.to_string());
}
let machine = PlatformInfo::new().map(|info| info.machine().into_owned());
let arch = match machine {
Ok(machine) => {
if machine == "x86_64" && self.arch != Arch::X86_64 {
// When running in Docker sometimes uname returns x86_64 but the container is actually x86,
// In this case we trust the architecture of rustc target
self.arch.to_string()
} else {
machine
}
}
Err(err) => {
error!("Failed to get machine architecture: {}", err);
self.arch.to_string()
}
};
Ok(arch)
}

fn get_platform_release(&self) -> Result<String> {
let os = self.os.to_string();
let os_version = env::var(format!("MATURIN_{}_VERSION", os.to_ascii_uppercase()));
Expand Down

0 comments on commit c5eb723

Please sign in to comment.