Skip to content

Commit

Permalink
Add cargo options to maturin develop command
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 18, 2022
1 parent a9edc7b commit 7d5d65d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 57 deletions.
10 changes: 2 additions & 8 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use tempfile::TempDir;
#[allow(clippy::too_many_arguments)]
pub fn develop(
bindings: Option<String>,
manifest_file: &Path,
cargo_extra_args: Vec<String>,
rustc_extra_args: Vec<String>,
cargo_options: CargoOptions,
venv_dir: &Path,
release: bool,
strip: bool,
Expand All @@ -37,11 +35,7 @@ pub fn develop(
skip_auditwheel: false,
zig: false,
universal2: false,
cargo: CargoOptions {
target: None,
manifest_path: Some(manifest_file.to_path_buf()),
..Default::default()
},
cargo: cargo_options,
};

let build_context = build_options.into_build_context(release, strip, true)?;
Expand Down
41 changes: 9 additions & 32 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use std::path::PathBuf;
use std::str::FromStr;

#[derive(Debug, Parser)]
#[clap(name = env!("CARGO_PKG_NAME"), version)]
#[clap(
version,
name = env!("CARGO_PKG_NAME"),
global_setting(clap::AppSettings::DeriveDisplayOrder)
)]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::large_enum_variant))]
/// Build and publish crates with pyo3, rust-cpython and cffi bindings as well
/// as rust binaries as python packages
Expand Down Expand Up @@ -71,30 +75,12 @@ enum Opt {
/// Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin
#[clap(short = 'b', long = "bindings", alias = "binding-crate")]
bindings: Option<String>,
#[clap(
short = 'm',
long = "manifest-path",
parse(from_os_str),
default_value = "Cargo.toml"
)]
/// The path to the Cargo.toml
manifest_path: PathBuf,
/// Pass --release to cargo
#[clap(short = 'r', long)]
release: bool,
/// Strip the library for minimum file size
#[clap(long)]
strip: bool,
/// Extra arguments that will be passed to cargo as `cargo rustc [...] [arg1] [arg2] --`
///
/// Use as `--cargo-extra-args="--my-arg"`
#[clap(long = "cargo-extra-args")]
cargo_extra_args: Vec<String>,
/// Extra arguments that will be passed to rustc as `cargo rustc [...] -- [arg1] [arg2]`
///
/// Use as `--rustc-extra-args="--my-arg"`
#[clap(long = "rustc-extra-args")]
rustc_extra_args: Vec<String>,
/// Install extra requires aka. optional dependencies
///
/// Use as `--extras=extra1,extra2`
Expand All @@ -106,6 +92,8 @@ enum Opt {
multiple_occurrences = false
)]
extras: Vec<String>,
#[clap(flatten)]
cargo_options: CargoOptions,
},
/// Build only a source distribution (sdist) without compiling.
///
Expand Down Expand Up @@ -383,12 +371,10 @@ fn run() -> Result<()> {
}
Opt::Develop {
bindings,
manifest_path,
cargo_extra_args,
rustc_extra_args,
release,
strip,
extras,
cargo_options,
} => {
let venv_dir = match (env::var_os("VIRTUAL_ENV"), env::var_os("CONDA_PREFIX")) {
(Some(dir), None) => PathBuf::from(dir),
Expand All @@ -406,16 +392,7 @@ fn run() -> Result<()> {
}
};

develop(
bindings,
&manifest_path,
cargo_extra_args,
rustc_extra_args,
&venv_dir,
release,
strip,
extras,
)?;
develop(bindings, cargo_options, &venv_dir, release, strip, extras)?;
}
Opt::SDist { manifest_path, out } => {
let build_options = BuildOptions {
Expand Down
20 changes: 11 additions & 9 deletions tests/common/develop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::{check_installed, create_virtualenv, maybe_mock_cargo};
use anyhow::Result;
use maturin::develop;
use std::path::Path;
use maturin::{develop, CargoOptions};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;

Expand Down Expand Up @@ -34,13 +34,15 @@ pub fn test_develop(
let manifest_file = package.as_ref().join("Cargo.toml");
develop(
bindings,
&manifest_file,
vec![
"--quiet".to_string(),
"--target-dir".to_string(),
format!("test-crates/targets/{}", unique_name),
],
vec![],
CargoOptions {
manifest_path: Some(manifest_file),
quiet: true,
target_dir: Some(PathBuf::from(format!(
"test-crates/targets/{}",
unique_name
))),
..Default::default()
},
&venv_dir,
false,
cfg!(feature = "faster-tests"),
Expand Down
18 changes: 10 additions & 8 deletions tests/common/other.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::{Context, Result};
use clap::Parser;
use flate2::read::GzDecoder;
use maturin::BuildOptions;
use maturin::{BuildOptions, CargoOptions};
use std::collections::HashSet;
use std::iter::FromIterator;
use std::path::Path;
use std::path::{Path, PathBuf};
use tar::Archive;

/// Tries to compile a sample crate (pyo3-pure) for musl,
Expand Down Expand Up @@ -116,13 +116,15 @@ pub fn test_source_distribution(
let sdist_directory = Path::new("test-crates").join("wheels").join(unique_name);

let build_options = BuildOptions {
manifest_path: Some(manifest_path),
out: Some(sdist_directory),
cargo_extra_args: vec![
"--quiet".to_string(),
"--target-dir".to_string(),
"test-crates/targets/test_workspace_cargo_lock".to_string(),
],
cargo: CargoOptions {
manifest_path: Some(manifest_path),
quiet: true,
target_dir: Some(PathBuf::from(
"test-crates/targets/test_workspace_cargo_lock",
)),
..Default::default()
},
..Default::default()
};

Expand Down

0 comments on commit 7d5d65d

Please sign in to comment.