Skip to content

Inconsistent linking against stdlib based on whether a Workspace is used #44862

@illicitonion

Description

@illicitonion

Minimal repro: https://github.com/illicitonion/repro-rustworkspacerpath

I have a dynamic library which I produce. I am trying to split it into a few crates internally, to logically decompose it, and speed up compilation. I would like to end up producing a dylib with no runtime dependencies on the system (as I do when just building one crate).

If I decompose into sub-crates and don't add a [workspace] section to my Cargo.toml, my top-level dylib is produced as I expect. It has no dynamic dependency on libstd listed when I run otool -L on my Mac. However, cargo test --all doesn't pick up the sub-crate tests.

If I add a [workspace] section to my Cargo.toml, cargo test --all picks up the sub-crate tests, but my top-level dylib now has a dynamic dependency on libstd.

As far as I can tell, there doesn't appear to be a way to both have --all work, and not pick up a runtime dependency on a dylib which I'd like to avoid.

Which of the following is the bug, I'm not sure:

  1. cargo test --all doesn't pick up non-workspace sub-crates
  2. cargo build produces different linkage configuration depending on whether you're in a workspace
    but it seems wrong that there's no way to get the best of both behaviours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions