Cargo run to use binary from dependency

Hi all,
I have a question that struggles me for at least a day. I want to use third party binary in my Rust project called patched version of spin project as both as binary artifact and library:
So far, I managed to build the binary as follows:

Cargo.toml

spin-cli = { git = "https://github.com/yordanmadzhunkov/spin", tag="v2.4.2", lib = true, artifact = "bin"}

this produces an executable called target/debug/deps/artifact/spin-cli-c8eeda24a0cce06b/bin/spin-c8eeda24a0cce06b

which is awesome, but I want to be able to invoke it from my scripts like following:

cargo run spin -- args

Unfortunetly I am not able to find a way to get the path to to it automatically. I want to be able to always refer to the latest build of this executable. Can you give me any pointers or suggestions.
Also, I tried the following approach as described in the cargo documentation with any success. CARGO_BIN_FILE_SPIN_CLI is not set as enviroument variable by cargo as the docs claim it should be
https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies

artifact-dependencies: Environment variables

After building an artifact dependency, Cargo provides the following environment variables that you can use to access the artifact:

    CARGO_<ARTIFACT-TYPE>_DIR_<DEP> — This is the directory containing all the artifacts from the dependency.

    <ARTIFACT-TYPE> is the artifact specified for the dependency (uppercased as in CDYLIB, STATICLIB, or BIN) and <DEP> is the name of the dependency. As with other Cargo environment variables, dependency names are converted to uppercase, with dashes replaced by underscores.

Thank you in advance!

PS. If this is not the proper place for such question, please redirect me.

Cargo should provide the environment variable not to your shell, but to your own binaries when you invoke them with cargo run build them. Would it be a nuisance for you to create a spin binary yourself that is just a small wrapper invoking the underlying spin artefact? I think that'd be the simplest way to get cargo run spin -- args to work.


Edit: environment variables for binary artefact deps defined in the [dependencies] section of your manifest are provided at compile time, not at run time (you can access them with the env! macro). From the RFC:

For dependencies, these variables are supplied during the compilation of the crate, and can be accessed using env!.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.