diff --git a/credential/cargo-credential-libsecret/README.md b/credential/cargo-credential-libsecret/README.md index a6af3b7575a..c781fe7cec7 100644 --- a/credential/cargo-credential-libsecret/README.md +++ b/credential/cargo-credential-libsecret/README.md @@ -5,6 +5,10 @@ See the [credential-provider] documentation for how to use this. This credential provider is built-in to cargo as `cargo:libsecret`. +It is available on Unix-like platforms such as Linux and the BSDs. +Apple and mobile platforms either use their OS-specific keyring, +or libsecret doesn't exist there. + > This crate is maintained by the Cargo team, primarily for use by Cargo > and not intended for external use (except as a transitive dependency). This > crate may make major changes to its APIs or be deprecated without warning. diff --git a/credential/cargo-credential-libsecret/src/lib.rs b/credential/cargo-credential-libsecret/src/lib.rs index 431cd987ff8..66e25773e82 100644 --- a/credential/cargo-credential-libsecret/src/lib.rs +++ b/credential/cargo-credential-libsecret/src/lib.rs @@ -2,7 +2,17 @@ //! > and not intended for external use (except as a transitive dependency). This //! > crate may make major changes to its APIs or be deprecated without warning. -#[cfg(target_os = "linux")] +#[cfg(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "android" + )) +))] mod linux { //! Implementation of the libsecret credential helper. @@ -259,7 +269,27 @@ mod linux { } } -#[cfg(not(target_os = "linux"))] +#[cfg(not(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "android" + )) +)))] pub use cargo_credential::UnsupportedCredential as LibSecretCredential; -#[cfg(target_os = "linux")] +#[cfg(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "android" + )) +))] pub use linux::LibSecretCredential; diff --git a/doc/book/src/reference/registry-authentication.md b/doc/book/src/reference/registry-authentication.md index 6a6c5ce2892..1f95f6c5161 100644 --- a/doc/book/src/reference/registry-authentication.md +++ b/doc/book/src/reference/registry-authentication.md @@ -55,6 +55,11 @@ The Keychain Access app can be used to view stored tokens. ### `cargo:libsecret` Uses [libsecret](https://wiki.gnome.org/Projects/Libsecret) to store tokens. +It is available on Unix-like platforms such as Linux and the BSDs. +Apple and mobile platforms either use their OS-specific keyring, +or libsecret doesn't exist there. The `libsecret` library is loaded at +runtime, so it only needs to be installed when this provider is used. + Any password manager with libsecret support can be used to view stored tokens. The following are a few examples (non-exhaustive): diff --git a/src/util/auth/mod.rs b/src/util/auth/mod.rs index 4824a08c4c2..171fc8917c1 100644 --- a/src/util/auth/mod.rs +++ b/src/util/auth/mod.rs @@ -480,7 +480,17 @@ static BUILT_IN_PROVIDERS: &[&'static str] = &[ /// Retrieves a cached instance of `LibSecretCredential`. /// Must be cached to avoid repeated load/unload cycles, which are not supported by `glib`. -#[cfg(target_os = "linux")] +#[cfg(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "android" + )) +))] fn get_credential_libsecret() -> CargoResult<&'static cargo_credential_libsecret::LibSecretCredential> { static CARGO_CREDENTIAL_LIBSECRET: std::sync::OnceLock< @@ -535,7 +545,17 @@ fn credential_action( "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")] + #[cfg(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + target_os = "android" + )) + ))] "cargo:libsecret" => Box::new(get_credential_libsecret()?), name if BUILT_IN_PROVIDERS.contains(&name) => { Box::new(cargo_credential::UnsupportedCredential {})