From 84e52cd234e0ae161e4c862bb6ee627729fa513c Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 23 Sep 2022 10:50:20 +0800 Subject: [PATCH] Add support for Cargo workspace inheritance https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace --- test-crates/workspace-inheritance/Cargo.lock | 254 ++++++++++++++++++ test-crates/workspace-inheritance/Cargo.toml | 8 + .../generic_lib/Cargo.toml | 8 + .../generic_lib/src/lib.rs | 3 + .../workspace-inheritance/python/Cargo.toml | 12 + .../python/pyproject.toml | 3 + .../workspace-inheritance/python/src/lib.rs | 14 + tests/run.rs | 16 ++ 8 files changed, 318 insertions(+) create mode 100644 test-crates/workspace-inheritance/Cargo.lock create mode 100644 test-crates/workspace-inheritance/Cargo.toml create mode 100644 test-crates/workspace-inheritance/generic_lib/Cargo.toml create mode 100644 test-crates/workspace-inheritance/generic_lib/src/lib.rs create mode 100644 test-crates/workspace-inheritance/python/Cargo.toml create mode 100644 test-crates/workspace-inheritance/python/pyproject.toml create mode 100644 test-crates/workspace-inheritance/python/src/lib.rs diff --git a/test-crates/workspace-inheritance/Cargo.lock b/test-crates/workspace-inheritance/Cargo.lock new file mode 100644 index 000000000..5e02a5b8b --- /dev/null +++ b/test-crates/workspace-inheritance/Cargo.lock @@ -0,0 +1,254 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "generic_lib" +version = "0.1.0" + +[[package]] +name = "indoc" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e" + +[[package]] +name = "libc" +version = "0.2.125" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" + +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + +[[package]] +name = "parking_lot" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "proc-macro2" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "pyo3" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" +dependencies = [ + "cfg-if", + "indoc", + "libc", + "parking_lot", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b65b546c35d8a3b1b2f0ddbac7c6a569d759f357f2b9df884f5d6b719152c8" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c275a07127c1aca33031a563e384ffdd485aee34ef131116fcd58e3430d1742b" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284fc4485bfbcc9850a6d661d627783f18d19c2ab55880b021671c4ba83e90f7" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53bda0f58f73f5c5429693c96ed57f7abdb38fdfc28ae06da4101a257adb7faf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "syn" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "target-lexicon" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1" + +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + +[[package]] +name = "unindent" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "workspace_with_path_dep" +version = "0.1.0" +dependencies = [ + "generic_lib", + "pyo3", +] diff --git a/test-crates/workspace-inheritance/Cargo.toml b/test-crates/workspace-inheritance/Cargo.toml new file mode 100644 index 000000000..60652ae97 --- /dev/null +++ b/test-crates/workspace-inheritance/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +members = [ + "generic_lib", + "python" +] + +[workspace.dependencies] +generic_lib = { path = "generic_lib" } diff --git a/test-crates/workspace-inheritance/generic_lib/Cargo.toml b/test-crates/workspace-inheritance/generic_lib/Cargo.toml new file mode 100644 index 000000000..c3bb1ca14 --- /dev/null +++ b/test-crates/workspace-inheritance/generic_lib/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "generic_lib" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/test-crates/workspace-inheritance/generic_lib/src/lib.rs b/test-crates/workspace-inheritance/generic_lib/src/lib.rs new file mode 100644 index 000000000..9673d1684 --- /dev/null +++ b/test-crates/workspace-inheritance/generic_lib/src/lib.rs @@ -0,0 +1,3 @@ +pub fn foo() -> &'static str { + "foo" +} diff --git a/test-crates/workspace-inheritance/python/Cargo.toml b/test-crates/workspace-inheritance/python/Cargo.toml new file mode 100644 index 000000000..05a4e42fc --- /dev/null +++ b/test-crates/workspace-inheritance/python/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "workspace_with_path_dep" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "0.16.5", features = ["extension-module"] } +generic_lib.workspace = true diff --git a/test-crates/workspace-inheritance/python/pyproject.toml b/test-crates/workspace-inheritance/python/pyproject.toml new file mode 100644 index 000000000..5d44682cd --- /dev/null +++ b/test-crates/workspace-inheritance/python/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["maturin>=0.13,<0.14"] +build-backend = "maturin" diff --git a/test-crates/workspace-inheritance/python/src/lib.rs b/test-crates/workspace-inheritance/python/src/lib.rs new file mode 100644 index 000000000..3210813e0 --- /dev/null +++ b/test-crates/workspace-inheritance/python/src/lib.rs @@ -0,0 +1,14 @@ +use pyo3::prelude::*; + +/// Formats the sum of two numbers as string. +#[pyfunction] +fn sum_as_string(a: usize, b: usize) -> PyResult { + Ok((a + b).to_string()) +} + +/// A Python module implemented in Rust. +#[pymodule] +fn workspace_with_path_dep(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; + Ok(()) +} diff --git a/tests/run.rs b/tests/run.rs index 221267448..47f865893 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -293,6 +293,22 @@ fn workspace_with_path_dep_sdist() { )) } +#[test] +fn workspace_inheritance_sdist() { + handle_result(other::test_source_distribution( + "test-crates/workspace-inheritance/python", + vec![ + "workspace-inheritance-0.1.0/local_dependencies/generic_lib/Cargo.toml", + "workspace-inheritance-0.1.0/local_dependencies/generic_lib/src/lib.rs", + "workspace-inheritance-0.1.0/Cargo.toml", + "workspace-inheritance-0.1.0/pyproject.toml", + "workspace-inheritance-0.1.0/src/lib.rs", + "workspace-inheritance-0.1.0/PKG-INFO", + ], + "workspace_inheritance_sdist", + )) +} + #[test] fn abi3_python_interpreter_args() { handle_result(other::abi3_python_interpreter_args());