diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b6265fc3e..471a2c9a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -278,11 +278,16 @@ jobs: name: Test Alpine Linux if: github.event_name != 'pull_request' runs-on: ubuntu-latest + strategy: + matrix: + container: + - amd64/alpine:latest + - i386/alpine:latest env: RUST_BACKTRACE: '1' CARGO_INCREMENTAL: '0' CARGO_TERM_COLOR: always - container: alpine:latest + container: ${{ matrix.container }} steps: - uses: actions/checkout@v3 - name: Install build requirements diff --git a/Changelog.md b/Changelog.md index 126ab1244..fd3d70290 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/target.rs b/src/target.rs index 2930dc5ec..dc8e0ce3f 100644 --- a/src/target.rs +++ b/src/target.rs @@ -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); @@ -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![]; @@ -366,6 +361,29 @@ impl Target { Ok(tag) } + fn get_platform_arch(&self) -> Result { + 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 { let os = self.os.to_string(); let os_version = env::var(format!("MATURIN_{}_VERSION", os.to_ascii_uppercase()));