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 /openpgp/build.rs | |
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 'openpgp/build.rs')
-rw-r--r-- | openpgp/build.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/openpgp/build.rs b/openpgp/build.rs index 9de8fb76..60f07620 100644 --- a/openpgp/build.rs +++ b/openpgp/build.rs @@ -63,13 +63,20 @@ fn crypto_backends_sanity_check() { } let backends = vec![ - (cfg!(feature = "crypto-nettle"), + (cfg!(all(feature = "crypto-nettle", + not(all(feature = "__implicit-crypto-backend-for-tests", + any(feature = "crypto-openssl", + feature = "crypto-rust"))))), Backend { name: "Nettle", production_ready: true, constant_time: true, }), - (cfg!(feature = "crypto-cng"), + (cfg!(all(feature = "crypto-cng", + not(all(feature = "__implicit-crypto-backend-for-tests", + any(feature = "crypto-nettle", + feature = "crypto-openssl", + feature = "crypto-rust"))))), Backend { name: "Windows CNG", production_ready: true, |