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 <messense@icloud.com>
  • Loading branch information
bors[bot] and messense committed Nov 27, 2022
2 parents 4bceaa5 + 1ac2be1 commit 2673339
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 2673339

Please sign in to comment.