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

Maybe should replace the cargo-script with rust-script #516

Closed
umaYnit opened this issue Feb 21, 2021 · 14 comments
Closed

Maybe should replace the cargo-script with rust-script #516

umaYnit opened this issue Feb 21, 2021 · 14 comments
Assignees
Milestone

Comments

@umaYnit
Copy link

umaYnit commented Feb 21, 2021

I tried to use cargo-script to write a build script, and My project was cross-compiled, so I tried to set a separate environment variable for cargo-script, but it still didn’t work. My script like this.

[tasks.hello]
env = { "CARGO_BUILD_TARGET" = "x86_64-pc-windows-msvc", "CARGO_MAKE_RUST_SCRIPT_PROVIDER" = "cargo-script" }
script_runner = "@rust"
script = '''
fn main() {
    println!("hello world!!");
}
'''

I checked the project and found this description:

Note: cargo-script does not work when Cargo is instructed to use a target architecture different to the default host architecture.

And the issue pointed out that the project is not very actived, rust-script is a maintained fork of cargo-script.
DanielKeep/cargo-script#71

@sagiegurari
Copy link
Owner

ya, i know of that. i also enable cargo play as an alternative.
if we are to replace to the fork, need to make sure its backwards compatible.
if it is, I'll do it, or a PR :)

@umaYnit
Copy link
Author

umaYnit commented Feb 22, 2021

I tried it, and there is basically no problem.
But because it supports "no main" mode, the judgment is simple now, so there may be problem if write like the following:

[tasks.hello]
script_runner = "@rust"
script = '''
     fn main() {
        println!("hello world!!");
    }
'''

@umaYnit
Copy link
Author

umaYnit commented Feb 22, 2021

And it not a cargo subcommand

@sagiegurari
Copy link
Owner

if its not a cargo subcommand it can still be used easily but will require a bit more code changes.

@sagiegurari
Copy link
Owner

rust-script is now supported. its not the default runner (just to make sure i do'nt break other projects for now)
so to enable it you need to add in the env:

[env]
CARGO_MAKE_RUST_SCRIPT_PROVIDER = "rust-script"

its currently in the 0.32.13 dev branch.

@sagiegurari
Copy link
Owner

@umaYnit once you verify this one is good for you, i'll publish a new cargo-make version with all the fixes i pushed based on your feedback
thanks a lot by the way!!! your feedback really helped me find some critical bugs.

@sagiegurari
Copy link
Owner

@umaYnit seems cargo-script is really broken so will make rust-script default after all

@sagiegurari
Copy link
Owner

@umaYnit since cargo-script was so broken lately, i decided to also release a new cargo make version already.
feel free to check it out and reopen/open issues. your feedback and PRs were great!

@umaYnit
Copy link
Author

umaYnit commented Mar 8, 2021

Execute compilation for the current project in rust-script, and the compiled product will be generated in the cache directory of rust-script, not the current project dir. test case:

[config]
skip_core_tasks = true

[tasks.build]
# env = { "CARGO_MAKE_RUST_SCRIPT_PROVIDER" = "cargo-script" }
script_runner = "@rust"
script = '''
fn main() {
    if !std::process::Command::new("cargo")
        .args(&["make", "_build"])
        .spawn()
        .unwrap()
        .wait()
        .unwrap()
        .success() { panic!() }
    println!("success");
}
'''

[tasks._build]
command = "cargo"
args = ["build", "--release"]

@sagiegurari
Copy link
Owner

is that an issue?

@sagiegurari
Copy link
Owner

i think cargo script did the same

@umaYnit
Copy link
Author

umaYnit commented Mar 8, 2021

cargo script not, will generated in project dir.

@sagiegurari
Copy link
Owner

strange. i always deleted some binary dir that cargo script created in the .cargo folder if i'm not wrong.
anyway, if this is configurable, i can pass it as part of the cli args.

@umaYnit
Copy link
Author

umaYnit commented Mar 9, 2021

I don’t see the relevant parameters in rust-script, maybe I should open an issue in rust-script.

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