summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2026-04-20 14:08:46 +0200
committerDavid Lönnhager <david.l@mullvad.net>2026-04-20 18:09:22 +0200
commit67d8599b954a51e27593cc141e18642c8cff1deb (patch)
tree5dadcf58247a3a79f31c87cc7fd15225182dc906
parent0018cc234e441e1bbbe42de5dc14d2b409eac49d (diff)
downloadmullvadvpn-67d8599b954a51e27593cc141e18642c8cff1deb.tar.xz
mullvadvpn-67d8599b954a51e27593cc141e18642c8cff1deb.zip
Replace some cfg!() chains with cfg_select!()
-rw-r--r--installer-downloader/src/controller.rs9
-rw-r--r--installer-downloader/src/main.rs9
-rw-r--r--installer-downloader/src/temp.rs11
-rw-r--r--mullvad-daemon/build.rs8
-rw-r--r--mullvad-daemon/src/account_history.rs15
-rw-r--r--mullvad-daemon/src/cleanup.rs58
-rw-r--r--mullvad-update/src/client/api.rs13
-rw-r--r--talpid-platform-metadata/src/arch.rs10
-rw-r--r--talpid-tunnel-config-client/src/lib.rs18
-rw-r--r--wireguard-go-rs/build.rs21
10 files changed, 73 insertions, 99 deletions
diff --git a/installer-downloader/src/controller.rs b/installer-downloader/src/controller.rs
index 77f433cbf9..b96ddbda20 100644
--- a/installer-downloader/src/controller.rs
+++ b/installer-downloader/src/controller.rs
@@ -58,11 +58,10 @@ pub fn initialize_controller<T: AppDelegate + 'static>(delegate: &mut T, environ
let platform = MetaRepositoryPlatform::current().expect("current platform must be supported");
let version_provider = HttpVersionInfoProvider::from(platform);
- #[cfg(target_os = "windows")]
- type CacheDir = mullvad_update::local::AppCacheDir;
-
- #[cfg(target_os = "macos")]
- type CacheDir = mullvad_update::local::NoopAppCacheDir;
+ type CacheDir = cfg_select! {
+ target_os = "windows" => { mullvad_update::local::AppCacheDir }
+ target_os = "macos" => { mullvad_update::local::NoopAppCacheDir }
+ };
AppController::initialize::<_, Downloader<T>, CacheDir, DirProvider>(
delegate,
diff --git a/installer-downloader/src/main.rs b/installer-downloader/src/main.rs
index a88c3c7e7e..7dbeb5301a 100644
--- a/installer-downloader/src/main.rs
+++ b/installer-downloader/src/main.rs
@@ -24,11 +24,10 @@ mod inner {
.expect("failed to create tokio runtime");
let _guard = rt.enter();
- #[cfg(target_os = "windows")]
- super::winapi_impl::main();
-
- #[cfg(target_os = "macos")]
- super::cacao_impl::main();
+ cfg_select! {
+ target_os = "windows" => { super::winapi_impl::main(); }
+ target_os = "macos" => { super::cacao_impl::main(); }
+ }
}
}
diff --git a/installer-downloader/src/temp.rs b/installer-downloader/src/temp.rs
index 4cb3ea8e0b..d6d6a39945 100644
--- a/installer-downloader/src/temp.rs
+++ b/installer-downloader/src/temp.rs
@@ -38,14 +38,9 @@ pub struct TempDirProvider;
impl DirectoryProvider for TempDirProvider {
/// Create a locked-down directory to store downloads in
async fn create_download_dir() -> anyhow::Result<PathBuf> {
- #[cfg(windows)]
- {
- admin_temp_dir().await
- }
-
- #[cfg(target_os = "macos")]
- {
- temp_dir().await
+ cfg_select! {
+ windows => { admin_temp_dir().await }
+ target_os = "macos" => { temp_dir().await }
}
}
}
diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs
index e8723d8fb3..1d8fb3a1dc 100644
--- a/mullvad-daemon/build.rs
+++ b/mullvad-daemon/build.rs
@@ -42,10 +42,10 @@ fn main() {
if matches!(target_os(), Os::Macos) {
// Set the minimum version of macOS on which mullvad-daemon can run.
- if cfg!(target_arch = "x86_64") {
- println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12");
- } else if cfg!(target_arch = "aarch64") {
- println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=11.0");
+ cfg_select! {
+ target_arch = "x86_64" => { println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12"); }
+ target_arch = "aarch64" => { println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=11.0"); }
+ _ => {}
}
}
}
diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs
index 6a6c0e3ddc..4a794d5c91 100644
--- a/mullvad-daemon/src/account_history.rs
+++ b/mullvad-daemon/src/account_history.rs
@@ -39,14 +39,13 @@ impl AccountHistory {
current_number: Option<AccountNumber>,
) -> Result<AccountHistory> {
let mut options = fs::OpenOptions::new();
- #[cfg(unix)]
- {
- options.mode(0o600);
- }
- #[cfg(windows)]
- {
- // a share mode of zero ensures exclusive access to the file to *this* process
- options.share_mode(0);
+ cfg_select! {
+ unix => { options.mode(0o600); }
+ windows => {
+ // a share mode of zero ensures exclusive access to the file to *this* process
+ options.share_mode(0);
+ }
+ _ => {}
}
let path = settings_dir.join(ACCOUNT_HISTORY_FILE);
diff --git a/mullvad-daemon/src/cleanup.rs b/mullvad-daemon/src/cleanup.rs
index 3d9c688f47..efa84eddde 100644
--- a/mullvad-daemon/src/cleanup.rs
+++ b/mullvad-daemon/src/cleanup.rs
@@ -44,38 +44,38 @@ async fn clear_cache_directory() -> Result<(), Error> {
}
async fn clear_directory(path: &Path) -> Result<(), Error> {
- #[cfg(not(target_os = "windows"))]
- {
- fs::remove_dir_all(path)
- .await
- .map_err(|e| Error::RemoveDir(path.display().to_string(), e))?;
- fs::create_dir_all(path)
- .await
- .map_err(|e| Error::CreateDir(path.display().to_string(), e))
- }
- #[cfg(target_os = "windows")]
- {
- let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDir)?;
+ cfg_select! {
+ target_os = "windows" => {
+ let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDir)?;
- let mut result = Ok(());
+ let mut result = Ok(());
- while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntry)? {
- let entry_type = match entry.file_type().await {
- Ok(entry_type) => entry_type,
- Err(error) => {
- result = result.and(Err(Error::FileType(error)));
- continue;
- }
- };
+ while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntry)? {
+ let entry_type = match entry.file_type().await {
+ Ok(entry_type) => entry_type,
+ Err(error) => {
+ result = result.and(Err(Error::FileType(error)));
+ continue;
+ }
+ };
- let removal = if entry_type.is_file() || entry_type.is_symlink() {
- fs::remove_file(entry.path()).await
- } else {
- fs::remove_dir_all(entry.path()).await
- };
- result = result
- .and(removal.map_err(|e| Error::RemoveDir(entry.path().display().to_string(), e)));
+ let removal = if entry_type.is_file() || entry_type.is_symlink() {
+ fs::remove_file(entry.path()).await
+ } else {
+ fs::remove_dir_all(entry.path()).await
+ };
+ result = result
+ .and(removal.map_err(|e| Error::RemoveDir(entry.path().display().to_string(), e)));
+ }
+ result
+ }
+ _ => {
+ fs::remove_dir_all(path)
+ .await
+ .map_err(|e| Error::RemoveDir(path.display().to_string(), e))?;
+ fs::create_dir_all(path)
+ .await
+ .map_err(|e| Error::CreateDir(path.display().to_string(), e))
}
- result
}
}
diff --git a/mullvad-update/src/client/api.rs b/mullvad-update/src/client/api.rs
index 5e384b32ee..74e96d1ee4 100644
--- a/mullvad-update/src/client/api.rs
+++ b/mullvad-update/src/client/api.rs
@@ -27,14 +27,11 @@ pub enum MetaRepositoryPlatform {
impl MetaRepositoryPlatform {
/// Return the current platform
pub fn current() -> Option<Self> {
- if cfg!(target_os = "windows") {
- Some(Self::Windows)
- } else if cfg!(target_os = "linux") {
- Some(Self::Linux)
- } else if cfg!(target_os = "macos") {
- Some(Self::Macos)
- } else {
- None
+ cfg_select! {
+ target_os = "windows" => { Some(Self::Windows) }
+ target_os = "linux" => { Some(Self::Linux) }
+ target_os = "macos" => { Some(Self::Macos) }
+ _ => { None }
}
}
diff --git a/talpid-platform-metadata/src/arch.rs b/talpid-platform-metadata/src/arch.rs
index 74e2856c1d..b045ef930e 100644
--- a/talpid-platform-metadata/src/arch.rs
+++ b/talpid-platform-metadata/src/arch.rs
@@ -49,12 +49,10 @@ pub fn get_native_arch() -> Result<Option<Architecture>, std::io::Error> {
/// Return native architecture.
#[cfg(not(target_os = "windows"))]
pub fn get_native_arch() -> Result<Option<Architecture>, std::io::Error> {
- const TARGET_ARCH: Option<Architecture> = if cfg!(target_arch = "x86_64") {
- Some(Architecture::X86)
- } else if cfg!(target_arch = "aarch64") {
- Some(Architecture::Arm64)
- } else {
- None
+ const TARGET_ARCH: Option<Architecture> = cfg_select! {
+ target_arch = "x86_64" => { Some(Architecture::X86) }
+ target_arch = "aarch64" => { Some(Architecture::Arm64) }
+ _ => { None }
};
Ok(TARGET_ARCH)
}
diff --git a/talpid-tunnel-config-client/src/lib.rs b/talpid-tunnel-config-client/src/lib.rs
index 47753a0f8f..b976853764 100644
--- a/talpid-tunnel-config-client/src/lib.rs
+++ b/talpid-tunnel-config-client/src/lib.rs
@@ -249,18 +249,12 @@ fn parse_daita_response(daita: proto::DaitaResponseV2) -> Result<DaitaSettings,
const fn get_platform() -> proto::DaitaPlatform {
use proto::DaitaPlatform;
- const PLATFORM: DaitaPlatform = if cfg!(target_os = "windows") {
- DaitaPlatform::WindowsWgGo
- } else if cfg!(target_os = "linux") {
- DaitaPlatform::LinuxWgGo
- } else if cfg!(target_os = "macos") {
- DaitaPlatform::MacosWgGo
- } else if cfg!(target_os = "android") {
- DaitaPlatform::AndroidWgGo
- } else if cfg!(target_os = "ios") {
- DaitaPlatform::IosWgGo
- } else {
- panic!("This platform does not support DAITA V2")
+ const PLATFORM: DaitaPlatform = cfg_select! {
+ target_os = "windows" => { DaitaPlatform::WindowsWgGo }
+ target_os = "linux" => { DaitaPlatform::LinuxWgGo }
+ target_os = "macos" => { DaitaPlatform::MacosWgGo }
+ target_os = "android" => { DaitaPlatform::AndroidWgGo }
+ target_os = "ios" => { DaitaPlatform::IosWgGo }
};
PLATFORM
}
diff --git a/wireguard-go-rs/build.rs b/wireguard-go-rs/build.rs
index f2aa096fb9..e0cb00ac56 100644
--- a/wireguard-go-rs/build.rs
+++ b/wireguard-go-rs/build.rs
@@ -44,14 +44,10 @@ enum Arch {
const fn host_os() -> Os {
// this ugliness is a limitation of rust, where we can't directly
// access the target triple of the build script.
- const HOST: Os = if cfg!(target_os = "windows") {
- Os::Windows
- } else if cfg!(target_os = "linux") {
- Os::Linux
- } else if cfg!(target_os = "macos") {
- Os::Macos
- } else {
- panic!("Unsupported host OS")
+ const HOST: Os = cfg_select! {
+ target_os = "windows" => { Os::Windows }
+ target_os = "linux" => { Os::Linux }
+ target_os = "macos" => { Os::Macos }
};
HOST
}
@@ -68,12 +64,9 @@ fn target_os() -> anyhow::Result<Os> {
}
const fn host_arch() -> Arch {
- const ARCH: Arch = if cfg!(target_arch = "x86_64") {
- Arch::Amd64
- } else if cfg!(target_arch = "aarch64") {
- Arch::Arm64
- } else {
- panic!("Unsupported host architecture")
+ const ARCH: Arch = cfg_select! {
+ target_arch = "x86_64" => { Arch::Amd64 }
+ target_arch = "aarch64" => { Arch::Arm64 }
};
ARCH
}