CARGO-LOCATE-PROJECT(1)

📦
version 1.99.1 · 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0

💖 CARGO-LOCATE-PROJECT 💖

okay bestie, welcome to the General Commands Manual glow-up of cargo-locate-project — the lil command that just tells you where your Cargo.toml is hiding. that's it. that's the whole job. and honestly? iconic. 👑


✨ NAME ✨

cargo-locate-project — print a JSON representation of a Cargo.toml file's location 🗺️💅


🎀 SYNOPSIS 🎀

cargo locate-project [options]

🦋 DESCRIPTION 🦋

so like. this command prints a JSON object to stdout with the full path to the manifest. and how does it find the manifest? it searches upward for a file named Cargo.toml, starting from the current working directory. it's giving detective energy fr fr 🔍✨

and here's the plot twist: if your project happens to be part of a workspace</>, the manifest of the project gets output — not the workspace root. so you get the member, not the mom. 👩👧

but wait, you can override that with the --workspace flag. and how does it find the root workspace? by traversing further upward, or by using the field package.workspace after locating the manifest of a workspace member. no cap, that's the whole mechanism. 🧚


💅 OPTIONS 💅

  • --workspace — locate the Cargo.toml at the root of the workspace, as opposed to the current workspace member. switching from "me" to "the whole fam". 👑

🌸 Display Options 🌸

  • --message-format fmt — the representation in which to print the project location. valid values are:
    • json (default): a JSON object with the path under the key "root". 🍓
    • plain: just the path. no frills, no decorations, just the raw path bestie. ✨
  • -v, --verbose — use verbose output. and you can specify it twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. may also be specified with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. 📢
  • -q, --quiet — do not print cargo log messages. may also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. shhhh 🤫
  • --color when — control when colored output is used. valid values:
    • auto (default): automatically detect if color support is available on the terminal. 🔮
    • always: always display colors. rainbow mode activated 🌈
    • never: never display colors. monochrome era 🖤

may also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.


🧸 Manifest Options 🧸

  • --manifest-path path — path to the Cargo.toml file. by default, Cargo searches for the Cargo.toml file in the current directory or any parent directory. basically: "here's exactly where to look, don't go snooping". 🕵️‍♀️

💜 Common Options 💜

  • +toolchain — if Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). see the rustup documentation <https://rust-lang.github.io/rustup/overrides.html> for more information about how toolchain overrides work. 👑
  • --config KEY=VALUE or PATH — overrides a Cargo configuration value. the argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times</>. see the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for more information. 🎀
  • -C PATH — changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering .cargo/config.toml, for example. this option must appear before the command name, for example cargo -C path/to/my-project build.
🚨 okay this one matters: this option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and requires the -Z unstable-options flag to enable (see #10098 <https://github.com/rust-lang/cargo/issues/10098>). so no, it will not just work on stable, bestie. it's giving exclusive. 💀
  • -h, --help — prints help information. the classic. the goat. 🫶
  • -Z flag — unstable (nightly-only) flags to Cargo. run cargo -Z help for details. ⭐

🌈 ENVIRONMENT 🌈

see the reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> for details on environment variables that Cargo reads. 🌱


⭐ EXIT STATUS ⭐

  1. 0: Cargo succeeded. slay! 🎉
  2. 101: Cargo failed to complete. 😭

🔥 EXAMPLES 🔥

  1. display the path to the manifest based on the current directory:
cargo locate-project

👑 SEE ALSO 👑

cargo(1), cargo-metadata(1)


and that's the whole page bestie, you ate it up 💖 this was the CARGO-LOCATE-PROJECT(1) page from the General Commands Manual, so go forth and locate those projects. periodt. 🦋✨🎀

📦 where this page comes from