Skip to content
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

script_runner_args not passed to @rust script_runner #1025

Closed
wmmc88 opened this issue Jan 18, 2024 · 6 comments
Closed

script_runner_args not passed to @rust script_runner #1025

wmmc88 opened this issue Jan 18, 2024 · 6 comments
Assignees

Comments

@wmmc88
Copy link
Contributor

wmmc88 commented Jan 18, 2024

Describe The Bug

My rust-script has a path dependency on a crate in my workspace:

script = '''
//! ```cargo
//! [dependencies]
//! my-crate = { path = "./path/to/crate", version = "0.1.10" }
//! ```

my_crate::module::foo();
'''

This does not work because the relative path will be wrong once cargo-make copies the contents of the script block into a file (which is currently under OUT_DIR/_cargo_make_temp/persisted_scripts, but I've noticed this path change before (I think after #968 was fixed). To fix this issue, I would like to use script_runner_args to pass --base-path to rust-script:

script_runner = "@rust"
script_runner_args = ["--base-path", "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}"]
script_extension = ".rs"
script = '''
//! ```cargo
//! [dependencies]
//! my-crate = { path = "./path/to/crate", version = "0.1.10" }
//! ```

my_crate::module::foo();
'''

But based off the output, it looks like the script_runner_args arent being passed to rust-script:

[cargo-make] INFO - Execute Command: "rust-script" "D:\\my-crate\\target\\_cargo_make_temp\\persisted_scripts\\AA10AF6651A422818CFC651DA0CFDDD5C3F750C9A05390A49C7C9888EE08050D.rs"

Sidenote: I'd rather if I could just use //! my-crate = { path = "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}", version = "0.1.10" }, but it looks like that expansion is not done for script blocks when script_runner is @rust.

@sagiegurari
Copy link
Owner

i've changed rust runner over the years when some stopped working... the latest (from 3 years back or so) is rust script - https://rust-script.org which seems it doesn't support getting cli args and passing them to the rust process.
at least not documented as i can see.

a workaround would be to use env vars i guess....

@wmmc88
Copy link
Contributor Author

wmmc88 commented Jan 19, 2024

rust-script actually does support passing args to the rust process, but that's not the issue I'm reporting here. I am interested in passing args to the script runner (i.e. passing args to rust-script)

I want to use script_runner_args to pass args to the rustscript invocation. In the above example, I want cargo-make's invocation of rustscript to be:
rust-script.exe --base-path path/to/initial/makefile/directory D:\\my-crate\\target\\_cargo_make_temp\\persisted_scripts\\AA10AF6651A422818CFC651DA0CFDDD5C3F750C9A05390A49C7C9888EE08050D.rs

I'm not quite sure how I could use env vars to solve the problem here. The path = "./path/to/crate" portion that I'd like to substitute CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY into is part of a comment that is processed by rust-script before actually running the script. So it wouldn't be able to use things like std::env::var in rust. If something like //! my-crate = { path = "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}", version = "0.1.10" } were to work, I think cargo make would have to preprocess the script block and do the substitutions before passing the script to rust-script.

@sagiegurari
Copy link
Owner

ah ok got it. I'll check

@sagiegurari
Copy link
Owner

@wmmc88 just pushed a fix for that. would love your feedback that it solves your issue.
don't forget to install from the github branch 0.37.8

@wmmc88
Copy link
Contributor Author

wmmc88 commented Jan 22, 2024

@sagiegurari confirmed its working!

@sagiegurari
Copy link
Owner

released new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants