Cargo "could not find `Cargo.toml`" in CI
Cargo walks up from the current directory looking for a Cargo.toml and found none. The job is running somewhere other than your crate root - usually a wrong working directory or an unexpected checkout layout.
What this error means
cargo fails instantly with could not find Cargo.toml in <dir> or any parent directory. The build never starts because Cargo has no manifest to work from. Common when the crate lives in a subdirectory of the repo.
error: could not find `Cargo.toml` in `/home/runner/work/app/app` or any parent directoryCommon causes
Wrong working directory in CI
The crate lives in a subfolder (e.g. backend/ or crates/api/), but the cargo step runs from the repo root where there is no Cargo.toml.
Checkout layout differs from local
A monorepo or a path the action checked out nests the crate differently than your machine, so the cwd Cargo inherits has no manifest above it.
How to fix it
Run cargo from the crate directory
Set the working directory or pass --manifest-path so Cargo points at the right Cargo.toml.
- run: cargo build --locked
working-directory: backend
# or, without changing cwd:
- run: cargo build --manifest-path backend/Cargo.toml --lockedConfirm where the manifest actually is
- Add a debug step:
ls -laandfind . -name Cargo.toml -maxdepth 3. - Set
working-directory(or--manifest-path) to that location. - For workspaces, run from the workspace root that holds the virtual manifest.
How to prevent it
- Pin
working-directoryfor cargo steps when the crate isn’t at the repo root. - Use
--manifest-pathin shared scripts so they work regardless of cwd. - Keep the CI checkout layout consistent with the local repo structure.