Closed mkmik closed 1 year ago
@mkmik Makes sense to do something here!
What do you think about adding something like the below option:
-b, --base-path [<base-path>]
Base path for resolving dependencies
This could be used as in:
demo:
#!/usr/bin/env rust-script --base-path {{justfile_directory()}}
/// ```cargo
/// [dependencies]
/// demo = { path = "./demo" }
/// ```
use demo::add;
println!("{}", add(1, 2));
yes that sounds reasonable!
@mkmik Great! This option (-b, --base-path
) is now available in the just released 0.30.0 version - does it work for you?
wow that was fast.
it does work!
$ cat justfile
demo:
#!/usr/bin/env rust-script --base-path {{justfile_directory()}}
//! ```cargo
//! [dependencies]
//! dummy = { path = "./dummy" }
//! ```
fn main() {
dummy::run();
}
$ cat ../../dummy/src/lib.rs
pub fn run() {
println!("it works");
}
$ just demo
it works
BTW, for posterity, this works too:
demo:
#!/usr/bin/env rust-script --base-path {{justfile_directory()}}
// cargo-deps: dummy = { path = "./dummy" }
fn main() {
dummy::run();
}
and this too:
demo:
#!/usr/bin/env rust-script --base-path {{justfile_directory()}} -d dummy={path="./dummy"}
fn main() {
dummy::run();
}
I have a script that works with rust-script:
It depends on a local crate in the same directory where the script file lives.
I'd like to run it via a runner like
just
. However when run from the runner, the script location is not in the same directory where the the runner recipe lives and thus the dependencies relative paths no longer work.The runner runs the script with $PWD set to the place I expect it to be, but rust-script (correctly) uses the location of the rust script to find deps.
Is there a trick I can use in order to fool rust-script about its location (fiddling with argv[0] ?) Or could we add a flag to tell rust-script to use $PWD as base dir for resolving dependencies?