From 2ea23ceb416d2a6c84a752d5a36afaf754b7c644 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sat, 28 Aug 2021 05:38:42 +0200 Subject: Switch TLS conditional compilation to feature --- src/args.rs | 14 ++------------ src/config.rs | 35 +++++------------------------------ src/main.rs | 14 ++------------ 3 files changed, 9 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index b6bb092..cea5658 100644 --- a/src/args.rs +++ b/src/args.rs @@ -135,22 +135,12 @@ pub struct CliArgs { pub print_completions: Option, /// TLS certificate to use - #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - ))] + #[cfg(feature = "tls")] #[structopt(long = "tls-cert", requires = "tls-key")] pub tls_cert: Option, /// TLS private key to use - #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - ))] + #[cfg(feature = "tls")] #[structopt(long = "tls-key", requires = "tls-cert")] pub tls_key: Option, } diff --git a/src/config.rs b/src/config.rs index 66cd81a..e2b4c3a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,12 +8,7 @@ use std::{ use anyhow::{anyhow, Context, Result}; use http::HeaderMap; -#[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" -))] +#[cfg(feature = "tls")] use rustls::internal::pemfile::{certs, pkcs8_private_keys}; use crate::{args::CliArgs, auth::RequiredAuth}; @@ -102,20 +97,10 @@ pub struct MiniserveConfig { pub hide_version_footer: bool, /// If set, use provided rustls config for TLS - #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - ))] + #[cfg(feature = "tls")] pub tls_rustls_config: Option, - #[cfg(not(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - )))] + #[cfg(not(feature = "tls"))] pub tls_rustls_config: Option<()>, } @@ -152,12 +137,7 @@ impl MiniserveConfig { _ => args.port, }; - #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - ))] + #[cfg(feature = "tls")] let tls_rustls_server_config = if let (Some(tls_cert), Some(tls_key)) = (args.tls_cert, args.tls_key) { @@ -178,12 +158,7 @@ impl MiniserveConfig { None }; - #[cfg(not(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - )))] + #[cfg(not(feature = "tls"))] let tls_rustls_server_config = None; Ok(MiniserveConfig { diff --git a/src/main.rs b/src/main.rs index 9b3d732..c60e153 100644 --- a/src/main.rs +++ b/src/main.rs @@ -227,12 +227,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { .default_service(web::get().to(error_404)) }); - #[cfg(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - ))] + #[cfg(feature = "tls")] let srv = if let Some(tls_config) = miniserve_config.tls_rustls_config { srv.bind_rustls(socket_addresses.as_slice(), tls_config) .map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))? @@ -245,12 +240,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { .run() }; - #[cfg(not(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm" - )))] + #[cfg(not(feature = "tls"))] let srv = srv .bind(socket_addresses.as_slice()) .map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))? -- cgit v1.2.3