Skip to content

Commit

Permalink
Upgrade more deps to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 30, 2024
1 parent 1b41f65 commit b39f8ca
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 232 deletions.
283 changes: 98 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ anyhow = "1.0.80"
base64 = "0.21.0"
glob = "0.3.0"
cargo-config2 = "0.1.24"
cargo_metadata = "0.18.0"
cargo_metadata = "0.19.0"
cargo-options = "0.7.2"
cbindgen = { version = "0.27.0", default-features = false }
flate2 = "1.0.18"
Expand All @@ -57,13 +57,13 @@ tar = "0.4.38"
tempfile = "3.2.0"
toml = "0.8.10"
toml_edit = "0.22.6"
zip = { version = "0.6.1", default-features = false, features = [
zip = { version = "2.0.0", default-features = false, features = [
"bzip2",
"deflate",
"time",
] }
thiserror = "1.0.37"
fs-err = "2.11.0"
thiserror = "2.0.3"
fs-err = "3.0.0"
fat-macho = { version = "0.4.8", default-features = false }
once_cell = "1.7.2"
rustc_version = "0.4.0"
Expand All @@ -75,7 +75,7 @@ python-pkginfo = "0.6.0"
textwrap = "0.16.1"
ignore = "0.4.20"
itertools = "0.12.1"
lddtree = "0.3.4"
lddtree = "0.3.7"
cc = "1.0.88"
dunce = "1.0.2"
normpath = "1.1.1"
Expand All @@ -97,8 +97,8 @@ clap = { version = "4.0.0", features = [
clap_complete_command = { version = "0.6.1", optional = true }

# cross compile
cargo-zigbuild = { version = "0.19.3", default-features = false, optional = true }
cargo-xwin = { version = "0.17", default-features = false, optional = true }
cargo-zigbuild = { version = "0.19.5", default-features = false, optional = true }
cargo-xwin = { version = "0.17.4", default-features = false, optional = true }

# log
tracing = "0.1.36"
Expand All @@ -122,7 +122,11 @@ ureq = { version = "2.9.4", features = [
"socks-proxy",
], default-features = false, optional = true }
native-tls = { version = "0.2.8", optional = true }
rustls = { version = "0.23", optional = true }
rustls = { version = "0.23", default-features = false, features = [
"logging",
"std",
"tls12",
], optional = true }
rustls-pemfile = { version = "2.1.0", optional = true }
keyring = { version = "2.3.2", default-features = false, features = [
"linux-no-secret-service",
Expand All @@ -142,7 +146,7 @@ rstest = "0.22.0"
rustversion = "1.0.9"
time = { version = "0.3.34", features = ["macros"] }
trycmd = "0.15.0"
which = "6.0.0"
which = "7.0.0"

[features]
default = ["full", "rustls"]
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ allow = [
"BSD-3-Clause",
"CC0-1.0",
"Unicode-3.0",
"BSL-1.0",
]
# The confidence threshold for detecting a license from license text.
# The higher the value, the more closely the license text must be to the
Expand Down
59 changes: 55 additions & 4 deletions maturin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,53 @@
}
]
},
"CargoCrateType": {
"description": "Supported cargo crate types",
"oneOf": [
{
"description": "Binary executable target",
"type": "string",
"enum": [
"bin"
]
},
{
"description": "Dynamic system library target",
"type": "string",
"enum": [
"cdylib"
]
},
{
"description": "Dynamic Rust library target",
"type": "string",
"enum": [
"dylib"
]
},
{
"description": "Rust library",
"type": "string",
"enum": [
"lib"
]
},
{
"description": "Rust library for use as an intermediate target",
"type": "string",
"enum": [
"rlib"
]
},
{
"description": "Static library",
"type": "string",
"enum": [
"staticlib"
]
}
]
},
"CargoTarget": {
"description": "Cargo compile target",
"type": "object",
Expand All @@ -239,10 +286,14 @@
],
"properties": {
"kind": {
"description": "Kind of target (\"bin\", \"lib\")",
"type": [
"string",
"null"
"description": "Kind of target (\"bin\", \"cdylib\")",
"anyOf": [
{
"$ref": "#/definitions/CargoCrateType"
},
{
"type": "null"
}
]
},
"name": {
Expand Down
5 changes: 3 additions & 2 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
PythonInterpreter, Target,
};
use anyhow::{anyhow, bail, Context, Result};
use cargo_metadata::CrateType;
use cargo_metadata::Metadata;
use fs_err as fs;
use ignore::overrides::{Override, OverrideBuilder};
Expand Down Expand Up @@ -841,7 +842,7 @@ impl BuildContext {
let artifacts = artifacts.first().context(error_msg)?;

let mut artifact = artifacts
.get("cdylib")
.get(&CrateType::CDyLib)
.cloned()
.ok_or_else(|| anyhow!(error_msg,))?;

Expand Down Expand Up @@ -1089,7 +1090,7 @@ impl BuildContext {
let mut artifact_paths = Vec::with_capacity(artifacts.len());
for artifact in artifacts {
let artifact = artifact
.get("bin")
.get(&CrateType::Bin)
.cloned()
.ok_or_else(|| anyhow!("Cargo didn't build a binary"))?;

Expand Down
27 changes: 17 additions & 10 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::pyproject_toml::ToolMaturin;
use crate::python_interpreter::{InterpreterConfig, InterpreterKind, MINIMUM_PYTHON_MINOR};
use crate::{BuildContext, PythonInterpreter, Target};
use anyhow::{bail, format_err, Context, Result};
use cargo_metadata::{CrateType, TargetKind};
use cargo_metadata::{Metadata, Node};
use cargo_options::heading;
use pep440_rs::VersionSpecifiers;
Expand Down Expand Up @@ -884,7 +885,7 @@ fn filter_cargo_targets(
.all(|f| resolved_features.contains(f))
}
}
_ => target.kind.contains(&"cdylib".to_string()),
_ => target.crate_types.contains(&CrateType::CDyLib),
})
.map(|target| CompileTarget {
target: target.clone(),
Expand All @@ -896,9 +897,9 @@ fn filter_cargo_targets(
// Let's try compile one of the target with `--crate-type cdylib`
let lib_target = root_pkg.targets.iter().find(|target| {
target
.kind
.crate_types
.iter()
.any(|k| LIB_CRATE_TYPES.contains(&k.as_str()))
.any(|crate_type| LIB_CRATE_TYPES.contains(crate_type))
});
if let Some(target) = lib_target {
targets.push(CompileTarget {
Expand All @@ -914,7 +915,7 @@ fn filter_cargo_targets(
config_targets.iter().any(|config_target| {
let name_eq = config_target.name == target.name;
match &config_target.kind {
Some(kind) => name_eq && target.kind.contains(kind),
Some(kind) => name_eq && target.crate_types.contains(&CrateType::from(*kind)),
None => name_eq,
}
})
Expand Down Expand Up @@ -1066,11 +1067,17 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
.iter()
.filter(|target| {
target.kind.iter().any(|kind| {
kind != "example" && kind != "test" && kind != "bench" && kind != "custom-build"
!matches!(
kind,
TargetKind::Bench
| TargetKind::CustomBuild
| TargetKind::Example
| TargetKind::ProcMacro
| TargetKind::Test
)
})
})
.flat_map(|target| target.crate_types.iter())
.map(String::as_str)
.flat_map(|target| target.crate_types.iter().cloned())
.collect();

let bridge = if let Some(bindings) = bridge {
Expand All @@ -1094,7 +1101,7 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
BridgeModel::Bindings(bindings.to_string(), MINIMUM_PYTHON_MINOR)
}
} else if let Some((bindings, minor)) = find_bindings(&deps, &packages) {
if !targets.contains(&"cdylib") && targets.contains(&"bin") {
if !targets.contains(&CrateType::CDyLib) && targets.contains(&CrateType::Bin) {
if bindings == "uniffi" {
// uniffi bindings don't support bin
BridgeModel::Bin(None)
Expand All @@ -1106,9 +1113,9 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
} else {
BridgeModel::Bindings(bindings, minor)
}
} else if targets.contains(&"cdylib") {
} else if targets.contains(&CrateType::CDyLib) {
BridgeModel::Cffi
} else if targets.contains(&"bin") {
} else if targets.contains(&CrateType::Bin) {
BridgeModel::Bin(find_bindings(&deps, &packages))
} else {
bail!("Couldn't detect the binding type; Please specify them with --bindings/-b")
Expand Down
34 changes: 20 additions & 14 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::target::RUST_1_64_0;
use crate::PlatformTag;
use crate::{BuildContext, PythonInterpreter, Target};
use anyhow::{anyhow, bail, Context, Result};
use cargo_metadata::CrateType;
use fat_macho::FatWriter;
use fs_err::{self as fs, File};
use normpath::PathExt;
Expand All @@ -20,7 +21,12 @@ use tracing::{debug, instrument, trace};
const PYO3_ABI3_NO_PYTHON_VERSION: (u64, u64, u64) = (0, 16, 4);

/// crate types excluding `bin`, `cdylib` and `proc-macro`
pub(crate) const LIB_CRATE_TYPES: [&str; 4] = ["lib", "dylib", "rlib", "staticlib"];
pub(crate) const LIB_CRATE_TYPES: [CrateType; 4] = [
CrateType::Lib,
CrateType::DyLib,
CrateType::RLib,
CrateType::StaticLib,
];

/// A cargo target to build
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -48,7 +54,7 @@ pub fn compile(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
targets: &[CompileTarget],
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
) -> Result<Vec<HashMap<CrateType, BuildArtifact>>> {
if context.universal2 {
compile_universal2(context, python_interpreter, targets)
} else {
Expand All @@ -61,7 +67,7 @@ fn compile_universal2(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
targets: &[CompileTarget],
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
) -> Result<Vec<HashMap<CrateType, BuildArtifact>>> {
let mut aarch64_context = context.clone();
aarch64_context.target = Target::from_target_triple(Some("aarch64-apple-darwin".to_string()))?;

Expand All @@ -80,12 +86,12 @@ fn compile_universal2(
.zip(aarch64_artifacts.iter().zip(&x86_64_artifacts))
{
let build_type = if bridge_model.is_bin() {
"bin"
CrateType::Bin
} else {
"cdylib"
CrateType::CDyLib
};
let aarch64_artifact = aarch64_artifact.get(build_type).cloned().ok_or_else(|| {
if build_type == "cdylib" {
let aarch64_artifact = aarch64_artifact.get(&build_type).cloned().ok_or_else(|| {
if build_type == CrateType::CDyLib {
anyhow!(
"Cargo didn't build an aarch64 cdylib. Did you miss crate-type = [\"cdylib\"] \
in the lib section of your Cargo.toml?",
Expand All @@ -94,8 +100,8 @@ fn compile_universal2(
anyhow!("Cargo didn't build an aarch64 bin.")
}
})?;
let x86_64_artifact = x86_64_artifact.get(build_type).cloned().ok_or_else(|| {
if build_type == "cdylib" {
let x86_64_artifact = x86_64_artifact.get(&build_type).cloned().ok_or_else(|| {
if build_type == CrateType::CDyLib {
anyhow!(
"Cargo didn't build a x86_64 cdylib. Did you miss crate-type = [\"cdylib\"] \
in the lib section of your Cargo.toml?",
Expand Down Expand Up @@ -128,7 +134,7 @@ fn compile_universal2(
path: PathBuf::from(output_path),
..x86_64_artifact
};
result.insert(build_type.to_string(), universal_artifact);
result.insert(build_type, universal_artifact);
universal_artifacts.push(result);
}
Ok(universal_artifacts)
Expand All @@ -138,7 +144,7 @@ fn compile_targets(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
targets: &[CompileTarget],
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
) -> Result<Vec<HashMap<CrateType, BuildArtifact>>> {
let mut artifacts = Vec::with_capacity(targets.len());
for target in targets {
let build_command = cargo_build_command(context, python_interpreter, target)?;
Expand All @@ -165,9 +171,9 @@ fn cargo_build_command(
// Add `--crate-type cdylib` if available
if compile_target
.target
.kind
.crate_types
.iter()
.any(|k| LIB_CRATE_TYPES.contains(&k.as_str()))
.any(|crate_type| LIB_CRATE_TYPES.contains(crate_type))
{
// `--crate-type` is stable since Rust 1.64.0
// See https://github.com/rust-lang/cargo/pull/10838
Expand Down Expand Up @@ -461,7 +467,7 @@ fn cargo_build_command(
fn compile_target(
context: &BuildContext,
mut build_command: Command,
) -> Result<HashMap<String, BuildArtifact>> {
) -> Result<HashMap<CrateType, BuildArtifact>> {
debug!("Running {:?}", build_command);

let using_cross = build_command
Expand Down
5 changes: 3 additions & 2 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl ModuleWriter for WheelWriter {
zip::CompressionMethod::Deflated
};

let mut options = zip::write::FileOptions::default()
let mut options = zip::write::SimpleFileOptions::default()
.unix_permissions(permissions)
.compression_method(compression_method);
let mtime = self.mtime().ok();
Expand Down Expand Up @@ -379,7 +379,8 @@ impl WheelWriter {
zip::CompressionMethod::Deflated
};

let mut options = zip::write::FileOptions::default().compression_method(compression_method);
let mut options =
zip::write::SimpleFileOptions::default().compression_method(compression_method);
let mtime = self.mtime().ok();
if let Some(mtime) = mtime {
options = options.last_modified_time(mtime);
Expand Down
Loading

0 comments on commit b39f8ca

Please sign in to comment.