A cargo subcommand to fetch the
$OUT_DIR variable from build scripts.
This can be seen as an extension to
cargo metadata, except it requires that
cargo check succeeds.
cargo check succeeds, then this command succeeds too (and give the same output).
Due to recent changes in
cargo check, this will not invalidate cached outputs, so the build scripts wont be re-run unless they need to :)
It is effectively a workaround to rust-lang/cargo#7546
$ cargo out
Assuming your current crate is named
current-crate, this wil output something like:
Alternatively, to omit the name you can use
--no-names. This is useful in shell scripts as
$(cargo out --no-names)
This command works with any crate name (as long as it has a
$ cargo out syn indexmap
syn /Users/techcable/git/current-crate/target/debug/build/syn-2bbc24a01fc81726/out indexmap /Users/techcable/git/current-crate/target/debug/build/indexmap-376e9f234cf30ee8/out
These are output in the order specified on the command line, seperated by newlines.
If the package doesn't have an out dir, the output will be "" exactly and the exit code will be
You might want to consider json output as well.
$ cargo out --json --all
If packages don't have an $OUT_DIR (because they don't have a build script), then the value for the specified key will be null.
This can be used along with jq for easy processing in scripts :)
If multiple packages have the same name, then version will be added. More precicely, the json keys will be the minimal
cargo pkgid needed to disambiguate them. This is actually somewhat difficult to do :)
How it works
cargo check --message-format=json and extracts only the nessicarry information.
Do to recent compiler changes, this will always output the proper
$OUT_DIR variables for all packages that have one.
However recent changes to
cargo check have made this possible. It sill :)