Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspaces cause incorrect linker args #5928

Closed
konstin opened this issue Aug 22, 2018 · 2 comments
Closed

Workspaces cause incorrect linker args #5928

konstin opened this issue Aug 22, 2018 · 2 comments
Labels
A-features Area: features — conditional compilation

Comments

@konstin
Copy link
Contributor

konstin commented Aug 22, 2018

For crates built upon pyo3, you need different linker args for binaries and libraries. Binaries need to link libpython, while libraries are forbidden by PEP 513 to link libpython. By default pyo3's build script add emits the arguments to link libpython and libraries use a feature called extension-module to deactivate those flags.

When building in a workspace with --all, cargo seems to conflate the linker args, causing linker errors. Pyo3 itself for example has a main crate with tests and an example that is an extension module. cargo test works fine and cd examples/word-count/ && cargo test also works fine, but cargo build --all --tests fails to compile the tests with linker errors missing libpython: Output of cargo build --all --tests -vvv. This seems to mean that cargo uses the linker args of the word count example with the extension module feature for the tests of pyo3 itself instead of using those for the pyo3 crate without the extension module feature.

This bug also occurs in dependent crate, e.g. rust-numpy. Building and testing works fine until you add a workspace with "example/extensions" in it, after which cargo test --all will fail with linker errors.

In summary, cargo seems to use the linker args of one crate in the workspace for all crates instead of using the correct ones for each crate.

Used Versions

  • cargo -V: cargo 1.29.0-nightly (6a7672ef5 2018-08-14)
  • pyo3: 3e7d5280ca18c38b8afc6eb75290b545743253df
  • rust-numpy: 6b6c70cde10a6d620e607fb8e9f1aee48ebbdf40
@alexcrichton
Copy link
Member

This is a conflation of a number of preexisting bugs. They're not super well indexed unfortunately. Cargo unions all features which means with --all it would union all the features requested by anything, and a different bug means that Cargo never compiles multiple versions of a crate with different sets of features meaning that a crate is only compiled once with one set of features.

In that sense it's not compatible with features today in Cargo to have a set of binaries that only work with a feature and a set that only work without, and then build them all at once.

@epage
Copy link
Contributor

epage commented Oct 17, 2023

As this is caused by feature unification, I'm closing this in favor of #4463. If there is a reason for us to keep this specific issue open, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation
Projects
None yet
Development

No branches or pull requests

3 participants