From 14079bff8c783cb6c47b564c44241058664cef38 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Tue, 7 Sep 2021 20:43:07 +0200 Subject: [PATCH] Give a compiletime error when using an incorrect combination of TLS features (#666) --- .github/workflows/test.yml | 2 ++ Cargo.toml | 2 +- src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3596aea..29e2d99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,8 @@ on: - master env: + RUSTFLAGS: "--cfg lettre_ignore_tls_mismatch" + RUSTDOCFLAGS: "--cfg lettre_ignore_tls_mismatch" RUST_BACKTRACE: full jobs: diff --git a/Cargo.toml b/Cargo.toml index dc2e6ea..e75a6b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ tokio1-rustls-tls = ["tokio1", "rustls-tls", "tokio1_rustls"] [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs", "--cfg", "lettre_ignore_tls_mismatch"] [[example]] name = "basic_html" diff --git a/src/lib.rs b/src/lib.rs index 179bb6e..cbaf6bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,6 +110,56 @@ )] #![cfg_attr(docsrs, feature(doc_cfg))] +#[cfg(not(lettre_ignore_tls_mismatch))] +mod compiletime_checks { + #[cfg(all( + feature = "tokio1", + feature = "native-tls", + not(feature = "tokio1-native-tls") + ))] + compile_error!("Lettre is being built with the `tokio1` and the `native-tls` features, but the `tokio1-native-tls` feature hasn't been turned on. +If you'd like to use rustls make sure that the `native-tls` hasn't been enabled by mistake (you may need to import lettre without default features) +If you're building a library which depends on lettre import it without default features and enable just the features you need."); + + #[cfg(all( + feature = "tokio1", + feature = "rustls-tls", + not(feature = "tokio1-rustls-tls") + ))] + compile_error!("Lettre is being built with the `tokio1` and the `rustls-tls` features, but the `tokio1-rustls-tls` feature hasn't been turned on. +If you'd like to use native-tls make sure that the `rustls-tls` hasn't been enabled by mistake. +If you're building a library which depends on lettre import it without default features and enable just the features you need."); + + /* + #[cfg(all( + feature = "async-std1", + feature = "native-tls", + not(feature = "async-std1-native-tls") + ))] + compile_error!("Lettre is being built with the `async-std1` and the `native-tls` features, but the `async-std1-native-tls` feature hasn't been turned on. + If you'd like to use rustls make sure that the `native-tls` hasn't been enabled by mistake (you may need to import lettre without default features) + If you're building a library which depends on lettre import it without default features and enable just the features you need."); + */ + #[cfg(all( + feature = "async-std1", + feature = "native-tls", + not(feature = "async-std1-native-tls") + ))] + compile_error!("Lettre is being built with the `async-std1` and the `native-tls` features, but the async-std integration doesn't support native-tls yet. +If you'd like to work on the issue please take a look at https://github.com/lettre/lettre/issues/576. +If you'd like to use rustls make sure that the `native-tls` hasn't been enabled by mistake (you may need to import lettre without default features) +If you're building a library which depends on lettre import lettre without default features and enable just the features you need."); + + #[cfg(all( + feature = "async-std1", + feature = "rustls-tls", + not(feature = "async-std1-rustls-tls") + ))] + compile_error!("Lettre is being built with the `async-std1` and the `rustls-tls` features, but the `async-std1-rustls-tls` feature hasn't been turned on. +If you'd like to use native-tls make sure that the `rustls-tls` hasn't been enabled by mistake (you may need to import lettre without default features) +If you're building a library which depends on lettre import it without default features and enable just the features you need."); +} + pub mod address; pub mod error; #[cfg(any(feature = "tokio1", feature = "async-std1"))]