Skip to content

Cargo looks for manifest in parent dirs even if one exists, even with --manifest-path #10872

Closed

Description

Problem

I have a project with nested, non-workspace cargo projects. It's a niche but real use case.

I found that if the parent project has a broken manifest, the child project cannot be built, even if its manifest is completely valid. Here's an example project, the child is in testbins/does-build.

does-build • cargo build
error: failed to parse manifest at `/home/jason/Code/test-binary/Cargo.toml`

Caused by:
  can't find `test_it_builds` bin at `src/bin/test_it_builds.rs` or `src/bin/test_it_builds/main.rs`. Please specify bin.path if you want to use a non-default path.

Note that the error is in the parent project. The child project is fine. It's the same if I use --manifest-path ./Cargo.toml.

Steps

  1. Clone linked project.
  2. Change directory to testbins/does-build.
  3. cargo build --manifest-path ./Cargo.toml.

Possible Solution(s)

It all works, and crucially, builds the child project but not the parent, if the parent manifest is fixed.

Notes

Seems related: #7871

The docs say:

Path to the Cargo.toml file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

I would expect that by default it stops when it finds one, but that's not explicitly stated. However, the behaviour with --manifest-path seems very unexpected.

Version

cargo 1.62.0 (a748cf5a3 2022-06-08)`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-documenting-cargo-itselfArea: Cargo's documentationA-workspacesArea: workspaces

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions