-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there an scriptable way to get the final binary which cargo run uses? #7895
Comments
Usage example for "easier approach": https://github.com/zserik/crulz-rs/blob/827b7b76a58c381d500da079330f0707957c892b/run_examples.sh |
Alternatively, you can run #3670 tracks some ideas for future enhancements. |
Ok. Is this ( |
@ehuss Thanks. |
for future reference, working version using |
The previous link gives us the output ("target") directory. If you know the binary name, you can manually append it to that path like it is done there. if not, you can get the binary name from combined: TARGET_DIR="$(cargo metadata --format-version 1 --no-deps | jq -r '.target_directory')"
BIN_NAME="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[].targets[] | select( .kind | map(. == "bin") | any ) | .name')"
BINARY_PATH="$TARGET_DIR/release/$BIN_NAME" |
For anyone else that finds this on google, here's a script that directly uses the output from #!/bin/sh
json=$(cargo build --message-format=json-render-diagnostics "$@") && \
printf "%s" "$json" | jq -js '[.[] | select(.reason == "compiler-artifact") | select(.executable != null)] | last | .executable' Additional arguments for |
I want to run the program built by
cargo build [--release]
in a loop, but I haven't found a way to get the path the produced binary "programmatically" (e.g. automatable).I have multiple developing machines with differing
target-dir
's, thus, on some machines, the target dir would be./target/
, but on others it would be/mnt/path/to/target.x64/
or something like that, which makes the easier approach (just usingtarget/release/$binname
) unusable. Runningcargo run [--release]
in a loop is currently not a good solution because each call introduces an overhead and additional output which is (at least) annoying.cargo run
from trying torebuild
the program every time + suppress theFinished
message?The text was updated successfully, but these errors were encountered: