Mercurial > crates > nonstick
changeset 138:999bf07efbcb
Get rid of num_enum dependency in `libpam-sys-helpers`.
Build times now fast!
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 03 Jul 2025 20:55:40 -0400 |
parents | 88627c057709 |
children | 33b9622ed6d2 |
files | Cargo.lock libpam-sys/Cargo.lock libpam-sys/Cargo.toml libpam-sys/libpam-sys-helpers/Cargo.toml libpam-sys/libpam-sys-helpers/src/constants.rs libpam-sys/libpam-sys-test/build.rs libpam-sys/src/lib.rs src/constants.rs |
diffstat | 8 files changed, 20 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.lock Thu Jul 03 17:33:13 2025 -0400 +++ b/Cargo.lock Thu Jul 03 20:55:40 2025 -0400 @@ -72,7 +72,6 @@ dependencies = [ "libc", "libpam-sys-helpers", - "num_enum", ] [[package]] @@ -80,7 +79,6 @@ version = "0.1.0" dependencies = [ "libc", - "num_enum", ] [[package]]
--- a/libpam-sys/Cargo.lock Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/Cargo.lock Thu Jul 03 20:55:40 2025 -0400 @@ -124,12 +124,6 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] name = "garando_errors" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -184,22 +178,6 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] -name = "hashbrown" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" - -[[package]] -name = "indexmap" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] name = "indoc" version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -242,7 +220,6 @@ dependencies = [ "libc", "libpam-sys-helpers", - "num_enum", ] [[package]] @@ -250,7 +227,6 @@ version = "0.1.0" dependencies = [ "libc", - "num_enum", ] [[package]] @@ -306,28 +282,6 @@ ] [[package]] -name = "num_enum" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" -dependencies = [ - "num_enum_derive", - "rustversion", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - -[[package]] name = "prettyplease" version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -338,15 +292,6 @@ ] [[package]] -name = "proc-macro-crate" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" -dependencies = [ - "toml_edit", -] - -[[package]] name = "proc-macro2" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -420,12 +365,6 @@ ] [[package]] -name = "rustversion" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" - -[[package]] name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -517,23 +456,6 @@ ] [[package]] -name = "toml_datetime" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" - -[[package]] -name = "toml_edit" -version = "0.22.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", -] - -[[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -636,12 +558,3 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" - -[[package]] -name = "winnow" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" -dependencies = [ - "memchr", -]
--- a/libpam-sys/Cargo.toml Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/Cargo.toml Thu Jul 03 20:55:40 2025 -0400 @@ -22,9 +22,8 @@ license.workspace = true [dependencies] +libc = "0.2" libpam-sys-helpers = { path = "libpam-sys-helpers" } -libc = "0.2" -num_enum = "0.7.4" [build-dependencies] libc = "0.2"
--- a/libpam-sys/libpam-sys-helpers/Cargo.toml Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/libpam-sys-helpers/Cargo.toml Thu Jul 03 20:55:40 2025 -0400 @@ -10,7 +10,6 @@ [dependencies] libc = "0.2" -num_enum = "0.7" [build-dependencies] libc = "0.2" \ No newline at end of file
--- a/libpam-sys/libpam-sys-helpers/src/constants.rs Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/libpam-sys-helpers/src/constants.rs Thu Jul 03 20:55:40 2025 -0400 @@ -4,8 +4,6 @@ //! `test_constants.rs`. #![allow(non_camel_case_types)] -#![allow(unused_imports)] -use num_enum::{IntoPrimitive, TryFromPrimitive}; /// Macro to make defining a bunch of constants way easier. macro_rules! define { @@ -76,7 +74,6 @@ pub use linux_pam::*; #[cfg(pam_impl = "LinuxPam")] mod linux_pam { - use super::{IntoPrimitive, TryFromPrimitive}; c_enum!( /// An error return code. PAM_OPEN_ERR = 1, @@ -149,7 +146,7 @@ pub const PAM_MODUTIL_NGROUPS: i32 = 64; - #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] + #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(i32)] pub enum pam_modutil_redirect_fd { PAM_MODUTIL_IGNORE_FD, @@ -157,6 +154,22 @@ PAM_MODUTIL_NULL_FD, } + impl From<pam_modutil_redirect_fd> for i32 { + fn from(value: pam_modutil_redirect_fd) -> Self { + value as Self + } + } + + impl TryFrom<i32> for pam_modutil_redirect_fd { + type Error = i32; + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + 0..=2 => Ok(unsafe { *(&value as *const i32).cast() }), + other => Err(other), + } + } + } + pub use pam_modutil_redirect_fd::*; }
--- a/libpam-sys/libpam-sys-test/build.rs Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/libpam-sys-test/build.rs Thu Jul 03 20:55:40 2025 -0400 @@ -95,7 +95,8 @@ .map(|item| { let name = item.ident.to_string(); if let Some(stripped) = name.strip_prefix(&format!("{REDIR_FD}_")) { - format!("assert_eq!(generated::{name} as i32, libpam_sys::{REDIR_FD}::{stripped}.into());") + format!("assert_eq!(generated::{name} as i32, libpam_sys::{REDIR_FD}::{stripped}.into());"); + format!("assert_eq!((generated::{name} as i32).try_into(), Ok(libpam_sys::{REDIR_FD}::{stripped}));") } else { format!("assert_eq!(generated::{name} as i32, libpam_sys::{name});") }
--- a/libpam-sys/src/lib.rs Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/src/lib.rs Thu Jul 03 20:55:40 2025 -0400 @@ -22,7 +22,6 @@ pub use libpam_sys_helpers::constants::*; #[doc(inline)] pub use libpam_sys_helpers::{pam_impl, pam_impl_name}; -use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::ffi::{c_char, c_int, c_uint, c_void}; use std::fmt; use std::marker::{PhantomData, PhantomPinned};
--- a/src/constants.rs Thu Jul 03 17:33:13 2025 -0400 +++ b/src/constants.rs Thu Jul 03 20:55:40 2025 -0400 @@ -1,9 +1,5 @@ //! Constants and enum values from the PAM library. -// We have a lot of dumb casts that we just gotta do because of differences -// between Linux-PAM and OpenPAM header files. -#![allow(clippy::unnecessary_cast)] - use crate::{linklist, man7, manbsd, xsso}; use bitflags::bitflags; use num_enum::{IntoPrimitive, TryFromPrimitive};