From 7518a9fe78c6ef560e815973a0199b0ca5345980 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Fri, 3 Jul 2026 12:06:41 +0000 Subject: [PATCH] use cfg_select instead of cfg_if --- Cargo.toml | 5 +-- src/os/unix/consts.rs | 80 +++++++++++++++++++++++++------------------ src/os/unix/mod.rs | 12 +++---- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5592ecc9..fb52fa1c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.mkd" description = "Bindings around the platform's dynamic library loading primitives with greatly improved memory safety." keywords = ["dlopen", "load", "shared", "dylib"] categories = ["api-bindings"] -rust-version = "1.88.0" +rust-version = "1.95" edition = "2021" autotests = false include = ["Cargo.toml", "LICENSE", "README.mkd", "src/**/*.rs", "tests/**/*.rs", "tests/ordinals.def"] @@ -28,9 +28,6 @@ version = "0.2" version = "0.61" features = ["Win32_Foundation"] -[target.'cfg(unix)'.dependencies.cfg-if] -version = "1" - [dev-dependencies] libc = "0.2" static_assertions = "1.1" diff --git a/src/os/unix/consts.rs b/src/os/unix/consts.rs index 46fd1a1c2..697142f78 100644 --- a/src/os/unix/consts.rs +++ b/src/os/unix/consts.rs @@ -54,14 +54,15 @@ mod posix { #[cfg(any(not(libloading_docs), unix))] mod posix { - use cfg_if::cfg_if; use super::c_int; - cfg_if! { - if #[cfg(target_os = "haiku")] { + cfg_select! { + target_os = "haiku" => { pub(super) const RTLD_LAZY: c_int = 0; - } else if #[cfg(target_os = "aix")] { + } + target_os = "aix" => { pub(super) const RTLD_LAZY: c_int = 4; - } else if #[cfg(any( + } + any( target_os = "linux", target_os = "android", target_os = "emscripten", @@ -88,19 +89,21 @@ mod posix { target_os = "nto", target_os = "hurd", target_os = "cygwin", - ))] { + ) => { pub(super) const RTLD_LAZY: c_int = 1; - } else { + } + _ => { compile_error!( "Target has no known `RTLD_LAZY` value. Please submit an issue or PR adding it." ); } } - cfg_if! { - if #[cfg(target_os = "haiku")] { + cfg_select! { + target_os = "haiku" => { pub(super) const RTLD_NOW: c_int = 1; - } else if #[cfg(any( + } + any( target_os = "linux", all(target_os = "android", target_pointer_width = "64"), target_os = "emscripten", @@ -128,41 +131,47 @@ mod posix { target_os = "nto", target_os = "hurd", target_os = "cygwin", - ))] { + ) => { pub(super) const RTLD_NOW: c_int = 2; - } else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] { + } + all(target_os = "android",target_pointer_width = "32") => { pub(super) const RTLD_NOW: c_int = 0; - } else { + } + _ => { compile_error!( "Target has no known `RTLD_NOW` value. Please submit an issue or PR adding it." ); } } - cfg_if! { - if #[cfg(any( + cfg_select! { + any( target_os = "haiku", all(target_os = "android",target_pointer_width = "32"), - ))] { + ) => { pub(super) const RTLD_GLOBAL: c_int = 2; - } else if #[cfg(target_os = "aix")] { + } + target_os = "aix" => { pub(super) const RTLD_GLOBAL: c_int = 0x10000; - } else if #[cfg(any( + } + any( target_env = "uclibc", all(target_os = "linux", target_arch = "mips"), all(target_os = "linux", target_arch = "mips64"), target_os = "cygwin", - ))] { + ) => { pub(super) const RTLD_GLOBAL: c_int = 4; - } else if #[cfg(any( + } + any( target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "watchos", - ))] { + ) => { pub(super) const RTLD_GLOBAL: c_int = 8; - } else if #[cfg(any( + } + any( target_os = "linux", all(target_os = "android", target_pointer_width = "64"), target_os = "emscripten", @@ -181,32 +190,36 @@ mod posix { target_os = "redox", target_os = "nto", target_os = "hurd", - ))] { + ) => { pub(super) const RTLD_GLOBAL: c_int = 0x100; - } else { + } + _ => { compile_error!( "Target has no known `RTLD_GLOBAL` value. Please submit an issue or PR adding it." ); } } - cfg_if! { - if #[cfg(any( + cfg_select! { + any( target_os = "netbsd", target_os = "nto", - ))] { + ) => { pub(super) const RTLD_LOCAL: c_int = 0x200; - } else if #[cfg(target_os = "aix")] { + } + target_os = "aix" => { pub(super) const RTLD_LOCAL: c_int = 0x80000; - } else if #[cfg(any( + } + any( target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "watchos", - ))] { + ) => { pub(super) const RTLD_LOCAL: c_int = 4; - } else if #[cfg(any( + } + any( target_os = "linux", target_os = "android", target_os = "emscripten", @@ -227,9 +240,10 @@ mod posix { target_os = "redox", target_os = "hurd", target_os = "cygwin", - ))] { + ) => { pub(super) const RTLD_LOCAL: c_int = 0; - } else { + } + _ => { compile_error!( "Target has no known `RTLD_LOCAL` value. Please submit an issue or PR adding it." ); diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index d727c622f..08f15e22b 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -272,12 +272,9 @@ impl Library { /// consider using the [`Library::get_singlethreaded`] call. #[inline(always)] pub unsafe fn get(&self, symbol: impl AsSymbolName) -> Result, crate::Error> { - #[cfg_attr(libloading_docs, allow(unused_extern_crates))] - #[cfg(libloading_docs)] - extern crate cfg_if; - cfg_if::cfg_if! { + cfg_select! { // These targets are known to have MT-safe `dlerror`. - if #[cfg(any( + any( target_os = "linux", target_os = "android", target_os = "openbsd", @@ -288,9 +285,10 @@ impl Library { target_os = "redox", target_os = "fuchsia", target_os = "cygwin", - ))] { + ) => { self.get_singlethreaded(symbol) - } else { + } + _ => { self.get_impl(symbol, || Err(crate::Error::DlSymUnknown)) } }