Skip to content

Commit

Permalink
Merge #1279
Browse files Browse the repository at this point in the history
1279: Downgrade cargo_metadata to 0.15.0 r=messense a=messense

See oli-obk/cargo_metadata#212

Co-authored-by: messense <messense@icloud.com>
  • Loading branch information
bors[bot] and messense committed Nov 20, 2022
2 parents 44a1d1b + 646b51f commit 150aa5c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
16 changes: 15 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))?;

Expand Down Expand Up @@ -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()];
}
}
Expand All @@ -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");
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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`")?;
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -227,6 +238,7 @@ impl ProjectResolver {
if !manifest_dir.starts_with(&current_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:
Expand Down Expand Up @@ -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!(
Expand All @@ -274,6 +290,7 @@ impl ProjectResolver {
manifest_path: &Path,
cargo_options: &CargoOptions,
) -> Result<Metadata> {
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)
Expand Down

0 comments on commit 150aa5c

Please sign in to comment.