nabijaczleweli / cargo-update

A cargo subcommand for checking and applying updates to installed executables
MIT License
1.25k stars 41 forks source link

Configuration: support setting environment variables for specific crates #244

Closed alpha-tango-kilo closed 1 year ago

alpha-tango-kilo commented 1 year ago

I would like to be able to set an environment variable for the underlying cargo install call that happens when updating a specific crate

Use case: when updating sccache on Windows, you can't have sccache running, because you can't replace the running executable with the new one. Thus, one of the easiest ways to work around this is to set RUSTC_WRAPPER to be blank to stop the compilation from using (and therefore running) sccache, allowing the update to complete successfully

Is this a reasonable feature idea, and would you be open potentially to a PR for this functionality? (No idea when I may get time to do this, but it seems like it should be pretty doable)

Alternatively one could instead hard-code this edge case for just this one crate on just Windows, if that would be preferred over adding a new feature

nabijaczleweli commented 1 year ago

I'm worried "environment: [string | null]" will inevitably become "parse environment substitutions as well", which would be really annoying. But lets just say it won't, and we're in business tbh.

nabijaczleweli commented 1 year ago

Can you try the current master branch (at least 42ca2652019c6ea2f86508e36a81c137ab5edfd1)? That has --{,clear-,inherit-}environment with the expected semantics:

$ cargo-install-update-config install-update-config -e a=b -E c treesize
Toolchain              nightly
Respect binaries       false
Target version         ^0.4
Default features       true
Environment variables  a=b
                       c   cleared

$ cargo-install-update-config install-update-config --inherit-environment c treesize
Toolchain              nightly
Respect binaries       false
Target version         ^0.4
Default features       true
Environment variables  a=b
alpha-tango-kilo commented 1 year ago

Works perfectly, thanks so much! The only thing I'd suggest is maybe some shorter aliases, e.g. --{,clear-,inherit-}env, but regradless the current implementation serves my purpose flawlessly 😄

nabijaczleweli commented 1 year ago

There's -e and -E for set/clear, inherit is effectively a partial -r so it can stay long and there's no obvious short letter. It's already annoying that it's --...-environment instead of --...-environment-variable but that'd be insane imo

Released in v13.2.0