From 4d701c5dce771c567c28b6ac625492b825a6bf10 Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 20 Nov 2022 11:21:47 +0800 Subject: [PATCH 1/3] Downgrade `cargo_metadata` to 0.15.0 --- Cargo.lock | 5 ++--- Cargo.toml | 4 +++- Changelog.md | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d04006b98..3512630d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -365,16 +365,15 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.15.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406c859255d568f4f742b3146d51851f3bfd49f734a2c289d9107c4395ee0062" +checksum = "3abb7553d5b9b8421c6de7cb02606ff15e0c6eea7d8eadd75ef013fd636bec36" dependencies = [ "camino", "cargo-platform", "semver", "serde", "serde_json", - "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 57a002607..854f884f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,9 @@ name = "maturin" anyhow = "1.0.63" base64 = "0.13.0" glob = "0.3.0" -cargo_metadata = "0.15.0" +# cargo_metadata 0.15.1 breaks `maturin build` on Rust 1.48.0 +# see https://github.com/oli-obk/cargo_metadata/issues/212 +cargo_metadata = "=0.15.0" cargo-options = "0.5.2" cargo-zigbuild = "0.14.1" cargo-xwin = { version = "0.12.2", default-features = false } diff --git a/Changelog.md b/Changelog.md index b42d26b8b..90dc353b1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* Downgrade `cargo_metadata` to 0.15.0 to fix `maturin build` on old Rust versions like 1.48.0 in [#1279](https://github.com/PyO3/maturin/pull/1279) + ## [0.14.0] - 2022-11-19 * **Breaking Change**: Remove support for specifying python package metadata in `Cargo.toml` in [#1200](https://github.com/PyO3/maturin/pull/1200). From f85eb5c9600307bc6c20a0640ad793ec7665a5bc Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 20 Nov 2022 11:22:32 +0800 Subject: [PATCH 2/3] Add more tracing logs to `src/compile.rs` --- src/compile.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/compile.rs b/src/compile.rs index 32ce5eb77..241e9a6dc 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -10,6 +10,7 @@ use std::io::{BufReader, Read}; use std::path::{Path, PathBuf}; use std::process::Stdio; use std::str; +use tracing::debug; /// The first version of pyo3 that supports building Windows abi3 wheel /// without `PYO3_NO_PYTHON` environment variable @@ -77,6 +78,8 @@ fn compile_universal2( } else { "cdylib" }; + debug!("Building an universal2 {}", build_type); + let mut aarch64_context = context.clone(); aarch64_context.target = Target::from_target_triple(Some("aarch64-apple-darwin".to_string()))?; @@ -189,6 +192,7 @@ fn compile_target( // `--crate-type` is stable since Rust 1.64.0 // See https://github.com/rust-lang/cargo/pull/10838 if target.rustc_version.semver >= RUST_1_64_0 { + debug!("Setting crate_type to cdylib for Rust >= 1.64.0"); cargo_rustc.crate_type = vec!["cdylib".to_string()]; } } @@ -209,6 +213,7 @@ fn compile_target( // We must only do this for libraries as it breaks binaries // For some reason this value is ignored when passed as rustc argument if context.target.is_musl_target() { + debug!("Setting `-C target-features=-crt-static` for musl dylib"); rust_flags .get_or_insert_with(Default::default) .push(" -C target-feature=-crt-static"); @@ -239,6 +244,7 @@ fn compile_target( "-C".to_string(), macos_dylib_install_name, ]; + debug!("Setting additional linker args for macOS: {:?}", mac_args); cargo_rustc.args.extend(mac_args); } } else if target.is_emscripten() { @@ -265,6 +271,10 @@ fn compile_target( emscripten_args.push("-C".to_string()); emscripten_args.push("link-arg=-sWASM_BIGINT".to_string()); } + debug!( + "Setting additional linker args for Emscripten: {:?}", + emscripten_args + ); cargo_rustc.args.extend(emscripten_args); } @@ -400,6 +410,8 @@ fn compile_target( build_command.env("MACOSX_DEPLOYMENT_TARGET", format!("{}.{}", major, minor)); } + debug!("Running {:?}", build_command); + let mut cargo_build = build_command .spawn() .context("Failed to run `cargo rustc`")?; @@ -412,7 +424,9 @@ fn compile_target( .take() .expect("Cargo build should have a stdout"); for message in cargo_metadata::Message::parse_stream(BufReader::new(stream)) { - match message.context("Failed to parse message coming from cargo")? { + let message = message.context("Failed to parse cargo metadata message")?; + debug!("cargo message: {:?}", message); + match message { cargo_metadata::Message::CompilerArtifact(artifact) => { let package_in_metadata = context .cargo_metadata From 646b51fcd8568ac74a9074064cfa063ea84a9d7b Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 20 Nov 2022 14:10:04 +0800 Subject: [PATCH 3/3] Add tracing logs to `src/project_layout.rs` --- src/project_layout.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/project_layout.rs b/src/project_layout.rs index 50f52d851..3c8f6e309 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -7,6 +7,7 @@ use normpath::PathExt as _; use std::env; use std::io; use std::path::{Path, PathBuf}; +use tracing::debug; const PYPROJECT_TOML: &str = "pyproject.toml"; @@ -193,6 +194,10 @@ impl ProjectResolver { // use command line argument if specified if let Some(path) = cargo_manifest_path { let path = path.normalize()?.into_path_buf(); + debug!( + "Using cargo manifest path from command line argument: {:?}", + path + ); let workspace_root = Self::resolve_cargo_metadata(&path, cargo_options)?.workspace_root; let workspace_parent = workspace_root.parent().unwrap_or(&workspace_root); for parent in path.ancestors().skip(1) { @@ -202,10 +207,12 @@ impl ProjectResolver { } let pyproject_file = parent.join(PYPROJECT_TOML); if pyproject_file.is_file() { + debug!("Found pyproject.toml at {:?}", pyproject_file); return Ok((path, pyproject_file)); } } let pyproject_file = path.parent().unwrap().join(PYPROJECT_TOML); + debug!("Trying pyproject.toml at {:?}", pyproject_file); return Ok((path, pyproject_file)); } // check `manifest-path` option in pyproject.toml @@ -215,6 +222,10 @@ impl ProjectResolver { .into_path_buf(); let pyproject_file = current_dir.join(PYPROJECT_TOML); if pyproject_file.is_file() { + debug!( + "Found pyproject.toml in working directory at {:?}", + pyproject_file + ); let pyproject = PyProjectToml::new(&pyproject_file).context("pyproject.toml is invalid")?; if let Some(path) = pyproject.manifest_path() { @@ -227,6 +238,7 @@ impl ProjectResolver { if !manifest_dir.starts_with(¤t_dir) { bail!("Cargo.toml can not be placed outside of the directory containing pyproject.toml"); } + debug!("Using cargo manifest path from pyproject.toml {:?}", path); return Ok((path.normalize()?.into_path_buf(), pyproject_file)); } else { // Detect src layout: @@ -260,6 +272,10 @@ impl ProjectResolver { // check Cargo.toml in current directory let path = current_dir.join("Cargo.toml"); if path.exists() { + debug!( + "Using cargo manifest path from working directory: {:?}", + path + ); Ok((path, current_dir.join(PYPROJECT_TOML))) } else { Err(format_err!( @@ -274,6 +290,7 @@ impl ProjectResolver { manifest_path: &Path, cargo_options: &CargoOptions, ) -> Result { + debug!("Resolving cargo metadata from {:?}", manifest_path); let cargo_metadata_extra_args = extract_cargo_metadata_args(cargo_options)?; let result = MetadataCommand::new() .manifest_path(manifest_path)