Skip to content

Commit

Permalink
Merge pull request #1648 from davidhewitt/fix-cross-compile-config
Browse files Browse the repository at this point in the history
pyo3-build-config: fix cross compilation
  • Loading branch information
davidhewitt committed Jun 26, 2021
2 parents e16bc16 + 5cc1e0f commit b58fe20
Show file tree
Hide file tree
Showing 10 changed files with 346 additions and 107 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,33 @@ jobs:
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }} ${{ matrix.msrv }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false # If one platform fails, allow the rest to keep testing.
fail-fast: false # If one platform fails, allow the rest to keep testing.
matrix:
rust: [stable]
python-version: [3.6, 3.7, 3.8, 3.9, 3.10-dev, pypy-3.6, pypy-3.7]
platform: [
{ os: "macos-latest", python-architecture: "x64", rust-target: "x86_64-apple-darwin" },
{ os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" },
{ os: "windows-latest", python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc" },
{ os: "windows-latest", python-architecture: "x86", rust-target: "i686-pc-windows-msvc" },
]
platform:
[
{
os: "macos-latest",
python-architecture: "x64",
rust-target: "x86_64-apple-darwin",
},
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
},
{
os: "windows-latest",
python-architecture: "x64",
rust-target: "x86_64-pc-windows-msvc",
},
{
os: "windows-latest",
python-architecture: "x86",
rust-target: "i686-pc-windows-msvc",
},
]
exclude:
# There is no 64-bit pypy on windows for pypy-3.6
- python-version: pypy-3.6
Expand All @@ -63,7 +80,12 @@ jobs:
# Test minimal supported Rust version
- rust: 1.41.1
python-version: 3.9
platform: { os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" }
platform:
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
}
msrv: "MSRV"

steps:
Expand Down Expand Up @@ -146,6 +168,9 @@ jobs:
- name: Test proc-macro code
run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml

- name: Test build config
run: cargo test --manifest-path=pyo3-build-config/Cargo.toml

- name: Install python test dependencies
run: python -m pip install -U pip tox

Expand Down Expand Up @@ -193,8 +218,10 @@ jobs:
override: true
profile: minimal
components: llvm-tools-preview
- run: LLVM_PROFILE_FILE="coverage-%p-%m.profraw" cargo test --no-default-features --no-fail-fast
- run: LLVM_PROFILE_FILE="coverage-features-%p-%m.profraw" cargo test --no-default-features --no-fail-fast --features "macros num-bigint num-complex hashbrown serde multiple-pymethods"
- run: cargo test --no-default-features --no-fail-fast
- run: cargo test --no-default-features --no-fail-fast --features "macros num-bigint num-complex hashbrown serde multiple-pymethods"
- run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml
- run: cargo test --manifest-path=pyo3-build-config/Cargo.toml
# can't yet use actions-rs/grcov with source-based coverage: https://github.com/actions-rs/grcov/issues/105
# - uses: actions-rs/grcov@v0.1
# id: coverage
Expand All @@ -210,3 +237,4 @@ jobs:
CARGO_TERM_VERBOSE: true
RUSTFLAGS: "-Zinstrument-coverage"
RUSTDOCFLAGS: "-Zinstrument-coverage"
LLVM_PROFILE_FILE: "coverage-%p-%m.profraw"
7 changes: 6 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,16 @@ fn emit_cargo_configuration(interpreter_config: &InterpreterConfig) -> Result<()
Ok(())
}

/// Generates the interpreter config suitable for the host / target / cross-compilation at hand.
///
/// The result is written to pyo3_build_config::PATH, which downstream scripts can read from
/// (including `pyo3-macros-backend` during macro expansion).
fn configure_pyo3() -> Result<()> {
let interpreter_config = pyo3_build_config::get();
let interpreter_config = pyo3_build_config::make_interpreter_config()?;
ensure_python_version(&interpreter_config)?;
ensure_target_architecture(&interpreter_config)?;
emit_cargo_configuration(&interpreter_config)?;
interpreter_config.to_writer(&mut std::fs::File::create(pyo3_build_config::PATH)?)?;
interpreter_config.emit_pyo3_cfgs();

// Enable use of const generics on Rust 1.51 and greater
Expand Down
1 change: 1 addition & 0 deletions pyo3-build-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "Apache-2.0"
edition = "2018"

[dependencies]
once_cell = "1"

[features]
default = []
Expand Down
10 changes: 1 addition & 9 deletions pyo3-build-config/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#[allow(dead_code)]
#[path = "src/impl_.rs"]
mod impl_;

fn main() {
// Print out error messages using display, to get nicer formatting.
if let Err(e) = impl_::configure() {
eprintln!("error: {}", e);
std::process::exit(1)
}
// Empty build script to force cargo to produce the "OUT_DIR" environment variable.
}

0 comments on commit b58fe20

Please sign in to comment.