fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.21k stars 41 forks source link

Can't install via `cargo install`; Cargo ignores `clap` version #42

Closed pierzchalski closed 2 years ago

pierzchalski commented 2 years ago

This is a weird one. I can clone the project and build it locally just fine, but if I try and install it from crates.io with cargo install rust-script (or from a local checkout with cargo install --path .) I get a bunch of errors like the following:

   ...
   Compiling clap v3.0.0-rc.0
   ...
   Compiling rust-script v0.18.0
error[E0599]: no method named `about` found for struct `Arg` in the current scope
   --> /home/eap/.cargo/registry/src/github.com-1ecc6299db9ec823/rust-script-0.18.0/src/main.rs:109:18
    |
109 |                 .about("Script file or expression to execute.")
    |                  ^^^^^ method not found in `Arg<'_>`

error[E0599]: no method named `about` found for struct `Arg` in the current scope
   --> /home/eap/.cargo/registry/src/github.com-1ecc6299db9ec823/rust-script-0.18.0/src/main.rs:123:18
    |
123 |                 .about("Execute <script> as a literal expression and display the result.")
    |                  ^^^^^ method not found in `Arg<'_>`
    ...

Looks like Cargo.toml specifies clap-3.0.0-beta.5 which indeed has the Arg::about method, but as you can see above cargo install tries to use clap-3.0.0-rc.0 which does not have Arg::about. Why would Cargo be doing this? Is there a workaround?

Charles-Schleich commented 2 years ago

Workaround for now: cargo install rust-script --version "0.7.0"
works as it relies on an older version of clap.

Past that, im not sure why the cargo Sem Version resolver ignores
clap-3.0.0-beta.5 for clap-3.0.0-rc.0

sagiegurari commented 2 years ago

just faced same issue, was hoping for a fix. i wonder, should it depend on non stable version of a crate to begin with?

i think the resolving issue is that in the toml you have:

clap = "3.0.0-beta.5"

which cargo defines by default as ^3.0.0-beta.5 and not =3.0.0-beta.5 so clap-3.0.0-rc.0 is "higher" than clap-3.0.0-beta.5 and still fits the semver. so it takes that. its the correct behavior from cargo point of view but not the one that we should use with unstable release.

fornwall commented 2 years ago

Thanks for reporting! The just released 0.19.0 fixes compatibility with and uses the latest clap release candidate, 3.0.0-rc.7.

Hopefully there will be a final release of clap 3 shortly, so we will avoid these kinds of errors in the future.