Skip to content

Commit

Permalink
Merge pull request #972 from messense/cargo-options
Browse files Browse the repository at this point in the history
Expose commonly used Cargo CLI options in `maturin build` command
  • Loading branch information
messense authored Jun 19, 2022
2 parents 7108fdd + b37760e commit efb6102
Show file tree
Hide file tree
Showing 17 changed files with 489 additions and 359 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ jobs:
- name: Build wheel (with sdist)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
cargo run -- build --release -b bin --sdist -o dist --target ${{ matrix.target }} --cargo-extra-args="--features password-storage" --compatibility manylinux2010 musllinux_1_1
cargo run -- build --release -b bin --sdist -o dist --target ${{ matrix.target }} --features password-storage --compatibility manylinux2010 musllinux_1_1
# ring doesn't support aarch64 windows yet
- name: Build wheel (windows aarch64)
if: matrix.target == 'aarch64-pc-windows-msvc'
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --cargo-extra-args="--no-default-features" --cargo-extra-args="--features log,upload,human-panic"
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --no-default-features --features log,upload,human-panic

- name: Build wheel (without sdist)
if: ${{ matrix.target != 'x86_64-unknown-linux-musl' && matrix.target != 'aarch64-pc-windows-msvc' }}
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --cargo-extra-args="--features password-storage"
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --features password-storage

- name: Build wheel (macOS universal2)
if: matrix.target == 'x86_64-apple-darwin'
Expand All @@ -106,7 +106,7 @@ jobs:
# set SDKROOT for C dependencies like ring and bzip2
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
rustup target add aarch64-apple-darwin
cargo run -- build --release -b bin -o dist --universal2 --cargo-extra-args="--features password-storage"
cargo run -- build --release -b bin -o dist --universal2 --features password-storage
- name: Archive binary (windows)
if: matrix.os == 'windows-latest'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ jobs:
shell: bash
run: |
set -ex
cargo run -- build -i pypy3 -m test-crates/pyo3-pure/Cargo.toml --cargo-extra-args="-vv"
cargo run -- build -i pypy3 -m test-crates/pyo3-pure/Cargo.toml -vv
pypy3 -m pip install --force-reinstall --no-index --find-links test-crates/pyo3-pure/target/wheels pyo3-pure
pypy3 -m pip install pytest
pypy3 -m pytest test-crates/pyo3-pure/test_pyo3_pure.py
cargo run -- pep517 build-wheel -i pypy3 -m test-crates/pyo3-pure/Cargo.toml --cargo-extra-args="-vv"
cargo run -- pep517 build-wheel -i pypy3 -m test-crates/pyo3-pure/Cargo.toml -vv
- uses: actions/setup-python@v4
with:
python-version: "3.10.0"
Expand Down
37 changes: 19 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ base64 = "0.13.0"
bytesize = "1.0.1"
glob = "0.3.0"
cargo_metadata = "0.14.0"
cargo-zigbuild = "0.9.0"
cargo-xwin = { version = "0.8.6", default-features = false }
cargo-options = "0.2.0"
cargo-zigbuild = "0.10.1"
cargo-xwin = { version = "0.9.1", default-features = false }
cbindgen = { version = "0.24.2", default-features = false }
flate2 = "1.0.18"
goblin = "0.5.1"
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* **Breaking Change**: Drop support for python 3.6, which is end of life in [#945](https://github.com/PyO3/maturin/pull/945)
* **Breaking Change**: Don't build source distribution by default in `maturin build` command in [#955](https://github.com/PyO3/maturin/pull/955), `--no-sdist` option is replaced by `--sdist`
* **Breaking Change**: maturin no longer search for python interpreters by default and only build for current interpreter in `PATH` in [#964](https://github.com/PyO3/maturin/pull/964)
* **Breaking Change**: Removed `--cargo-extra-args` and `--rustc-extra-args` options in [#972](https://github.com/PyO3/maturin/pull/972). You can now pass all common `cargo build` arguments directly to `maturin build`
* Add support for building with multiple binary targets in [#948](https://github.com/PyO3/maturin/pull/948)
* Add a `--target` option to `maturin list-python` command in [#957](https://github.com/PyO3/maturin/pull/957)
* Add support for using bundled python sysconfigs for PyPy when abi3 feature is enabled in [#958](https://github.com/PyO3/maturin/pull/958)
* Add support for cross compiling PyPy wheels when abi3 feature is enabled in [#963](https://github.com/PyO3/maturin/pull/963)
* Add `--find-interpreter` option to `build` and `publish` commands to search for python interpreters in [#964](https://github.com/PyO3/maturin/pull/964)
* Infer target triple from `ARCHFLAGS` for macOS to be compatible with `cibuildwheel` in [#967](https://github.com/PyO3/maturin/pull/967)
* Expose commonly used Cargo CLI options in `maturin build` command in [#972](https://github.com/PyO3/maturin/pull/972)

## [0.12.20] - 2022-06-15

Expand Down
14 changes: 5 additions & 9 deletions src/build_context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::auditwheel::{get_policy_and_libs, patchelf, relpath};
use crate::auditwheel::{PlatformTag, Policy};
use crate::build_options::CargoOptions;
use crate::compile::warn_missing_py_init;
use crate::module_writer::{
add_data, write_bin, write_bindings_module, write_cffi_module, write_python_part, WheelWriter,
Expand Down Expand Up @@ -182,7 +183,7 @@ pub struct BuildContext {
/// The directory to store the built wheels in. Defaults to a new "wheels"
/// directory in the project's target directory
pub out: PathBuf,
/// Pass --release to cargo
/// Build artifacts in release mode, with optimizations
pub release: bool,
/// Strip the library for minimum file size
pub strip: bool,
Expand All @@ -192,10 +193,6 @@ pub struct BuildContext {
pub zig: bool,
/// Whether to use the the manylinux/musllinux or use the native linux tag (off)
pub platform_tag: Vec<PlatformTag>,
/// Extra arguments that will be passed to cargo as `cargo rustc [...] [arg1] [arg2] --`
pub cargo_extra_args: Vec<String>,
/// Extra arguments that will be passed to rustc as `cargo rustc [...] -- [arg1] [arg2]`
pub rustc_extra_args: Vec<String>,
/// The available python interpreter
pub interpreter: Vec<PythonInterpreter>,
/// Cargo.toml as resolved by [cargo_metadata]
Expand All @@ -204,6 +201,8 @@ pub struct BuildContext {
pub universal2: bool,
/// Build editable wheels
pub editable: bool,
/// Cargo build options
pub cargo_options: CargoOptions,
}

/// The wheel file location and its Python version tag (e.g. `py3`).
Expand Down Expand Up @@ -260,10 +259,7 @@ impl BuildContext {
fs::create_dir_all(&self.out)
.context("Failed to create the target directory for the source distribution")?;

let include_cargo_lock = self
.cargo_extra_args
.iter()
.any(|arg| arg == "--locked" || arg == "--frozen");
let include_cargo_lock = self.cargo_options.locked || self.cargo_options.frozen;
match PyProjectToml::new(self.manifest_path.parent().unwrap()) {
Ok(pyproject) => {
let sdist_path = source_distribution(
Expand Down
Loading

0 comments on commit efb6102

Please sign in to comment.