Skip to content

Commit

Permalink
Auto merge of #12949 - cuviper:os-credentials, r=arlosi
Browse files Browse the repository at this point in the history
Filter `cargo-credential-*` dependencies by OS

### What does this PR try to resolve?

The `cargo-credential-*` crates have OS-specific functionality, with `cfg` for an "unsupported" fallback, and these are unconditional dependencies of `cargo`. In distros like Fedora that package dependencies individually, that means these crates still have to be packaged even when they are useless on Linux. (Or else patch them out as a downstream change.) Instead, we can filter those dependencies in `Cargo.toml` and add the fallback at the point of use.

Fixes #12945.

### Additional information

We could further *remove* the `cfg`-unsupported fallbacks from the individual crates, and just have them `#![cfg(..)]` themselves globally. I haven't done that yet, because it would look like a big change for mostly just whitespace removing the nested module. I'm happy to add that if desired though.
  • Loading branch information
bors committed Nov 9, 2023
2 parents 1d89805 + 1ee9632 commit 9b2cad6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ anyhow.workspace = true
base64.workspace = true
bytesize.workspace = true
cargo-credential.workspace = true
cargo-credential-libsecret.workspace = true
cargo-credential-macos-keychain.workspace = true
cargo-credential-wincred.workspace = true
cargo-platform.workspace = true
cargo-util.workspace = true
clap = { workspace = true, features = ["wrap_help"] }
Expand Down Expand Up @@ -189,9 +186,18 @@ unicode-xid.workspace = true
url.workspace = true
walkdir.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
cargo-credential-libsecret.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
cargo-credential-macos-keychain.workspace = true

[target.'cfg(not(windows))'.dependencies]
openssl = { workspace = true, optional = true }

[target.'cfg(windows)'.dependencies]
cargo-credential-wincred.workspace = true

[target.'cfg(windows)'.dependencies.windows-sys]
workspace = true
features = [
Expand Down
6 changes: 6 additions & 0 deletions src/cargo/util/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,15 @@ fn credential_action(
}
"cargo:paseto" => bail!("cargo:paseto requires -Zasymmetric-token"),
"cargo:token-from-stdout" => Box::new(BasicProcessCredential {}),
#[cfg(windows)]
"cargo:wincred" => Box::new(cargo_credential_wincred::WindowsCredential {}),
#[cfg(target_os = "macos")]
"cargo:macos-keychain" => Box::new(cargo_credential_macos_keychain::MacKeychain {}),
#[cfg(target_os = "linux")]
"cargo:libsecret" => Box::new(cargo_credential_libsecret::LibSecretCredential {}),
name if BUILT_IN_PROVIDERS.contains(&name) => {
Box::new(cargo_credential::UnsupportedCredential {})
}
process => Box::new(CredentialProcessCredential::new(process)),
};
config.shell().verbose(|c| {
Expand Down

0 comments on commit 9b2cad6

Please sign in to comment.