Skip to content

Commit 9127108

Browse files
Merge pull request #154 from brotskydotcom/issue-153
Rework default feature set.
2 parents 1732b79 + 5b9d559 commit 9127108

File tree

5 files changed

+110
-35
lines changed

5 files changed

+110
-35
lines changed

Cargo.toml

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,47 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"]
66
license = "MIT OR Apache-2.0"
77
name = "keyring"
88
repository = "https://github.com/hwchen/keyring-rs.git"
9-
version = "2.1.0"
9+
version = "2.2.0"
1010
edition = "2021"
1111
exclude = [".github/"]
1212
readme = "README.md"
1313

1414
[features]
15-
default = ["linux-secret-service"]
15+
default = ["platform-all"]
16+
platform-all = ["platform-linux", "platform-freebsd", "platform-macos", "platform-ios", "platform-windows"]
17+
platform-linux = ["linux-secret-service", "linux-keyutils"]
18+
platform-freebsd = ["linux-secret-service"]
19+
platform-macos = ["security-framework"]
20+
platform-ios = ["security-framework"]
21+
platform-windows = ["winapi", "byteorder"]
1622
linux-secret-service = ["linux-secret-service-rt-async-io-crypto-rust"]
1723
linux-secret-service-rt-async-io-crypto-rust = ["secret-service/rt-async-io-crypto-rust"]
1824
linux-secret-service-rt-tokio-crypto-rust = ["secret-service/rt-tokio-crypto-rust"]
1925
linux-secret-service-rt-async-io-crypto-openssl = ["secret-service/rt-async-io-crypto-openssl"]
2026
linux-secret-service-rt-tokio-crypto-openssl = ["secret-service/rt-tokio-crypto-openssl"]
2127
linux-no-secret-service = ["linux-default-keyutils"]
22-
linux-default-keyutils = []
28+
linux-default-keyutils = ["linux-keyutils"]
29+
2330

2431
[dependencies]
2532
lazy_static = "1"
2633

2734
[target.'cfg(target_os = "macos")'.dependencies]
28-
security-framework = "2.6"
35+
security-framework = { version = "2.6", optional = true }
2936

3037
[target.'cfg(target_os = "ios")'.dependencies]
31-
security-framework = "2.6"
38+
security-framework = { version = "2.6", optional = true }
3239

3340
[target.'cfg(target_os = "linux")'.dependencies]
3441
secret-service = { version = "3", optional = true }
35-
linux-keyutils = { version = "0.2", features = ["std"] }
42+
linux-keyutils = { version = "0.2", features = ["std"], optional = true }
3643

3744
[target.'cfg(target_os = "freebsd")'.dependencies]
3845
secret-service = { version = "3", optional = true }
3946

4047
[target.'cfg(target_os = "windows")'.dependencies]
41-
byteorder = "1.2"
42-
winapi = { version = "0.3", features = ["wincred", "winerror", "errhandlingapi", "minwindef"] }
48+
byteorder = { version = "1.2", optional = true }
49+
winapi = { version = "0.3", features = ["wincred", "winerror", "errhandlingapi", "minwindef"], optional = true }
4350

4451
[[example]]
4552
name = "iostest"

README.md

+33-3
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,44 @@ for details.
8383

8484
This crate provides secure storage support for
8585
Linux (secret-service and kernel keyutils),
86-
iOS (keychain), macOS (keychain),
87-
and Windows (credential manager).
86+
iOS (keychain), macOS (keychain), and
87+
Windows (credential manager).
8888

8989
It also builds on FreeBSD (secret-service),
9090
and probably works there,
9191
but since neither the maintainers nor GitHub do
9292
building and testing on FreeBSD, we can't be sure.
9393

94-
Please file issues if you have questions or problems.
94+
The default features of this crate are set up
95+
to build all the available platform support.
96+
So, for example, if you build on macOS, then
97+
keychain support is enabled by loading
98+
other underlying crates that the keychain
99+
credential store requires.
100+
101+
On Linux, there are two supported platform
102+
credential stores: the secret-service and
103+
the kernel keyutils, and both are built by default.
104+
If you only want to use one or the other, then
105+
you must turn off default features in your
106+
dependency specification and explicitly
107+
specify the feature for the platform support you
108+
want. For example, you might use
109+
```toml
110+
keyring = { version = "2", default_features = false, features = ["linux-secret-service"] }
111+
```
112+
113+
If you don't build any of the platform support features,
114+
then you will get the `mock` keystore as your default.
115+
116+
PLEASE NOTE: As of version 2.2, turning off the default
117+
feature set will turn off platform support on *all* platforms,
118+
not just on Linux (as was the case before). While this
119+
behavior is a breaking change on Mac, Windows,
120+
and FreeBSD, the behavior on those platforms before was
121+
unintended and undefined (suppressing default features did nothing),
122+
so this is considered a bug fix rather than
123+
a semver-breaking change that requires a major version bump.
95124

96125
## Upgrading from v1
97126

@@ -154,6 +183,7 @@ whether through contributing code, discussion, or bug reports!
154183
- @stankec
155184
- @steveatinfincia
156185
- @Sytten
186+
- @VorpalBlade
157187

158188
If you should be on this list, but don't find yourself,
159189
please contact @brotskydotcom.

build-xplat-binaries.sh

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/bin/bash
2+
echo Rustup and Cargo updates...
23
rustup update
34
cargo update
4-
cargo clippy --target x86_64-unknown-linux-musl
5-
cargo clippy --target x86_64-pc-windows-gnu
5+
echo Clippy no default features...
6+
cargo clippy --no-default-features --target aarch64-unknown-linux-musl
7+
cargo clippy --no-default-features --target aarch64-pc-windows-msvc
8+
cargo clippy --no-default-features --target aarch64-apple-darwin
9+
cargo clippy --no-default-features --target aarch64-apple-ios
10+
echo Clippy default features...
11+
cargo clippy --target aarch64-unknown-linux-musl
12+
cargo clippy --target aarch64-pc-windows-msvc
613
cargo clippy --target aarch64-apple-darwin
714
cargo clippy --target aarch64-apple-ios
8-
cargo build --target x86_64-unknown-linux-musl
9-
cargo build --target x86_64-pc-windows-gnu
15+
echo Compile no default features...
16+
cargo build --no-default-features --target aarch64-unknown-linux-musl
17+
cargo build --no-default-features --target aarch64-pc-windows-msvc
18+
cargo build --no-default-features --target aarch64-apple-darwin
19+
cargo build --no-default-features --target aarch64-apple-ios
20+
echo Compile default features...
21+
cargo build --target aarch64-unknown-linux-musl
22+
cargo build --target aarch64-pc-windows-msvc
1023
cargo build --target aarch64-apple-darwin
1124
cargo build --target aarch64-apple-ios

build-xplat-docs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
cargo doc --no-deps --target x86_64-unknown-linux-musl $OPEN_DOCS
3-
cargo doc --no-deps --target x86_64-pc-windows-gnu $OPEN_DOCS
2+
cargo doc --no-deps --target aarch64-unknown-linux-musl $OPEN_DOCS
3+
cargo doc --no-deps --target aarch64-pc-windows-msvc $OPEN_DOCS
44
cargo doc --no-deps --target aarch64-apple-darwin $OPEN_DOCS
55
cargo doc --no-deps --target aarch64-apple-ios $OPEN_DOCS

src/lib.rs

+43-18
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,64 @@ pub use credential::{Credential, CredentialBuilder};
110110
pub use error::{Error, Result};
111111

112112
// Included keystore implementations and default choice thereof.
113-
// It would be really nice if we could conditionalize multiple declarations,
114-
// but we can't so we have to repeat the conditional on each one.
115113

116-
#[cfg(target_os = "linux")]
114+
pub mod mock;
115+
116+
#[cfg(all(target_os = "linux", feature = "linux-keyutils"))]
117117
pub mod keyutils;
118-
#[cfg(all(target_os = "linux", not(feature = "linux-no-secret-service")))]
118+
#[cfg(all(
119+
target_os = "linux",
120+
feature = "secret-service",
121+
not(feature = "linux-no-secret-service")
122+
))]
119123
pub mod secret_service;
120-
#[cfg(all(target_os = "linux", not(feature = "linux-default-keyutils")))]
124+
#[cfg(all(
125+
target_os = "linux",
126+
feature = "secret-service",
127+
not(feature = "linux-default-keyutils")
128+
))]
121129
use crate::secret_service as default;
122-
#[cfg(all(target_os = "linux", feature = "linux-default-keyutils"))]
130+
#[cfg(all(
131+
target_os = "linux",
132+
feature = "linux-keyutils",
133+
any(feature = "linux-default-keyutils", not(feature = "secret-service"))
134+
))]
123135
use keyutils as default;
136+
#[cfg(all(
137+
target_os = "linux",
138+
not(feature = "secret-service"),
139+
not(feature = "linux-keyutils")
140+
))]
141+
use mock as default;
124142

125-
#[cfg(target_os = "freebsd")]
143+
#[cfg(all(target_os = "freebsd", feature = "secret-service"))]
126144
pub mod secret_service;
127-
#[cfg(target_os = "freebsd")]
145+
#[cfg(all(target_os = "freebsd", feature = "secret-service"))]
128146
use crate::secret_service as default;
147+
#[cfg(all(target_os = "freebsd", not(feature = "secret-service")))]
148+
use mock as default;
129149

130-
#[cfg(target_os = "windows")]
131-
pub mod windows;
132-
#[cfg(target_os = "windows")]
133-
use windows as default;
134-
135-
#[cfg(target_os = "macos")]
150+
#[cfg(all(target_os = "macos", feature = "platform-macos"))]
136151
pub mod macos;
137-
#[cfg(target_os = "macos")]
152+
#[cfg(all(target_os = "macos", feature = "platform-macos"))]
138153
use macos as default;
154+
#[cfg(all(target_os = "macos", not(feature = "platform-macos")))]
155+
use mock as default;
139156

140-
#[cfg(target_os = "ios")]
157+
#[cfg(all(target_os = "windows", feature = "platform-windows"))]
158+
pub mod windows;
159+
#[cfg(all(target_os = "windows", not(feature = "platform-windows")))]
160+
use mock as default;
161+
#[cfg(all(target_os = "windows", feature = "platform-windows"))]
162+
use windows as default;
163+
164+
#[cfg(all(target_os = "ios", feature = "platform-ios"))]
141165
pub mod ios;
142-
#[cfg(target_os = "ios")]
166+
#[cfg(all(target_os = "ios", feature = "platform-ios"))]
143167
use ios as default;
168+
#[cfg(all(target_os = "ios", not(feature = "platform-ios")))]
169+
use mock as default;
144170

145-
pub mod mock;
146171
#[cfg(not(any(
147172
target_os = "linux",
148173
target_os = "freebsd",

0 commit comments

Comments
 (0)