diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-12-15 18:04:52 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-01-05 16:56:05 +0100 |
commit | b7e1b0e5a23923bce97f91fdab16a32d80453876 (patch) | |
tree | 7a7e90769b0a79560c76fcc0a50d5897ba3261c0 /autocrypt | |
parent | f4d4c9804a29d69ad7b88147c07f5d2639fb7d88 (diff) |
Don't select a cryptograhic backend in non-leaf crates.
- This way, only the leaf package has to concern itself with the
selection of a cryptographic backend for Sequoia. Notably, we
don't have to repeat all of sequoia-openpgp's features in all
crates that use sequoia-openpgp.
- Enable the new feature resolver which allows for this method.
- A complication arises because we want to make `cargo test` work by
default for the intermediate crates without developers having to
select a cryptographic backend. To make that work, we implicitly
select a backend in the dev dependencies which are enabled when
compiling the tests. To make it even more convenient, we select
the most convenient backend, which is CNG for Windows and Nettle,
our default, for every other platform.
- Now that we have implicitly selected CNG on Windows for running
the tests, when the user wants to use Nettle on Windows, and does
`cargo test --features sequoia-openpgp/crypto-nettle`, then two
backends are selected: the implicitly selected CNG and the
explicitly selected Nettle. In this case, we detect that an
implicit selection has been made, and ignore the implicitly
selected backend. Now, this has already been compiled by
cargo (remember that we cannot influence the set of dependencies
at the time the build script is run), but we can still ignore the
implicit backend using conditional compilation (i.e. it will not
be included in the resulting binary). The same happens on
non-Windows platforms where Nettle is the implicit default for
tests when the user explicitly requests a different backend. In
both cases, Nettle and CNG are slim wrappers around native
libraries, so the wasted compilation time is low.
Diffstat (limited to 'autocrypt')
-rw-r--r-- | autocrypt/Cargo.toml | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/autocrypt/Cargo.toml b/autocrypt/Cargo.toml index b0e2fc0a..cca5041a 100644 --- a/autocrypt/Cargo.toml +++ b/autocrypt/Cargo.toml @@ -28,10 +28,14 @@ base64 = ">=0.12" [lib] bench = false -[features] -default = ["sequoia-openpgp/default"] -crypto-nettle = ["sequoia-openpgp/crypto-nettle"] -crypto-cng = ["sequoia-openpgp/crypto-cng"] -compression = ["sequoia-openpgp/compression"] -compression-deflate = ["sequoia-openpgp/compression-deflate"] -compression-bzip2 = ["sequoia-openpgp/compression-bzip2"] +# Enables a crypto backend for the tests: +[target.'cfg(not(windows))'.dev-dependencies] +sequoia-openpgp = { path = "../openpgp", version = "1", default-features = false, features = ["crypto-nettle", "__implicit-crypto-backend-for-tests"] } + +# Enables a crypto backend for the tests: +[target.'cfg(windows)'.dev-dependencies] +sequoia-openpgp = { path = "../openpgp", version = "1", default-features = false, features = ["crypto-cng", "__implicit-crypto-backend-for-tests"] } + +# Enables a crypto backend for the docs.rs generation: +[package.metadata.docs.rs] +features = ["sequoia-openpgp/default"] |