Skip to content

Commit 9b2cad6

Browse files
committed
Auto merge of #12949 - cuviper:os-credentials, r=arlosi
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.
2 parents 1d89805 + 1ee9632 commit 9b2cad6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ anyhow.workspace = true
128128
base64.workspace = true
129129
bytesize.workspace = true
130130
cargo-credential.workspace = true
131-
cargo-credential-libsecret.workspace = true
132-
cargo-credential-macos-keychain.workspace = true
133-
cargo-credential-wincred.workspace = true
134131
cargo-platform.workspace = true
135132
cargo-util.workspace = true
136133
clap = { workspace = true, features = ["wrap_help"] }
@@ -189,9 +186,18 @@ unicode-xid.workspace = true
189186
url.workspace = true
190187
walkdir.workspace = true
191188

189+
[target.'cfg(target_os = "linux")'.dependencies]
190+
cargo-credential-libsecret.workspace = true
191+
192+
[target.'cfg(target_os = "macos")'.dependencies]
193+
cargo-credential-macos-keychain.workspace = true
194+
192195
[target.'cfg(not(windows))'.dependencies]
193196
openssl = { workspace = true, optional = true }
194197

198+
[target.'cfg(windows)'.dependencies]
199+
cargo-credential-wincred.workspace = true
200+
195201
[target.'cfg(windows)'.dependencies.windows-sys]
196202
workspace = true
197203
features = [

src/cargo/util/auth/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,15 @@ fn credential_action(
529529
}
530530
"cargo:paseto" => bail!("cargo:paseto requires -Zasymmetric-token"),
531531
"cargo:token-from-stdout" => Box::new(BasicProcessCredential {}),
532+
#[cfg(windows)]
532533
"cargo:wincred" => Box::new(cargo_credential_wincred::WindowsCredential {}),
534+
#[cfg(target_os = "macos")]
533535
"cargo:macos-keychain" => Box::new(cargo_credential_macos_keychain::MacKeychain {}),
536+
#[cfg(target_os = "linux")]
534537
"cargo:libsecret" => Box::new(cargo_credential_libsecret::LibSecretCredential {}),
538+
name if BUILT_IN_PROVIDERS.contains(&name) => {
539+
Box::new(cargo_credential::UnsupportedCredential {})
540+
}
535541
process => Box::new(CredentialProcessCredential::new(process)),
536542
};
537543
config.shell().verbose(|c| {

0 commit comments

Comments
 (0)