By default, cargo will build the crate at the current directory when invoked; if the current directory holds a workspace, cargo will then build all crates within that workspace.
Sometimes it can be useful to only build a subset of a given workspace (e.g. only specific binaries are needed, or some crates cannot be built for certain platforms, etc.), and cargo can be instructed to do so.
Notably, it is possible to set:
cargoExtraArgs = "-p foo -p bar";to only build the
barcrates only, but nothing else in the workspace
cargoExtraArgs = "--bin baz";to only build the
bazbinary (from whatever crate defines it)
cargoExtraArgs = "--workspace --exclude qux";to build the entire cargo workspace except for the
pname = "NAME_OF_THE_EXECUTABLE"; when building a single
executable from the workspace. Having the name of the package match the
executable name will allow the result to easily run via
nix run without