Mercurial > crates > nonstick
comparison libpam-sys/src/lib.rs @ 134:6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Instead of having to do a bunch of custom parsing and other logic
that tools often choke on, this change introduces an easy way
to depend upon custom #[cfg]s provided by the libpam-sys crate.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 03 Jul 2025 11:03:36 -0400 |
| parents | c77846f3a979 |
| children |
comparison
equal
deleted
inserted
replaced
| 133:32b2a545ca3e | 134:6c1e1bdb4164 |
|---|---|
| 1 #![doc = include_str!("../README.md")] | 1 #![doc = include_str!("../README.md")] |
| 2 //! | 2 //! |
| 3 //! ## PAM implementation | 3 //! ## PAM implementation |
| 4 //! | 4 //! |
| 5 #![doc = concat!("This documentation was built for the **", __pam_impl_name__!(), "** implementation.")] | 5 #![doc = concat!("This documentation was built for the **", env!("LIBPAMSYS_IMPL"), "** implementation.")] |
| 6 | |
| 7 use libpam_sys_impls::{__pam_impl_enum__, __pam_impl_name__}; | |
| 8 | |
| 9 /// A `cfg`-like attribute macro for code specific to one PAM implementation. | |
| 10 /// | |
| 11 /// Different versions of PAM export different functions and have some | |
| 12 /// meaningful internal implementation differences, like the way `pam_conv` | |
| 13 /// is handled (see [the Linux-PAM man page for details][man7]). | |
| 14 /// | |
| 15 /// This macro will let you figure out which PAM you're compiling | |
| 16 /// (and eventually running) against so you can make those critical changes. | |
| 17 /// | |
| 18 /// The implementation names are the same as those in the [`PamImpl`] enum. | |
| 19 /// | |
| 20 /// ``` | |
| 21 /// use libpam_sys::cfg_pam_impl; | |
| 22 /// | |
| 23 /// #[cfg_pam_impl("Sun")] | |
| 24 /// fn do_something() { /* Illumos/Solaris-only code */ } | |
| 25 /// | |
| 26 /// #[cfg_pam_impl(not("Sun"))] | |
| 27 /// fn do_something() { /* non-Illumos code */ } | |
| 28 /// | |
| 29 /// #[cfg_pam_impl(any("LinuxPam", "XSso"))] | |
| 30 /// fn do_something_else() { /* Linux-PAM or X/SSO-spec PAM */ } | |
| 31 /// | |
| 32 /// #[cfg_pam_impl(not(any("Sun", "OpenPam")))] | |
| 33 /// fn do_a_third_thing() { /* Neither Sun nor OpenPAM */ } | |
| 34 /// | |
| 35 /// #[cfg_pam_impl(any())] | |
| 36 /// fn this_will_never_build() { /* why would you do this? */ } | |
| 37 /// | |
| 38 /// #[cfg_pam_impl(not(any()))] | |
| 39 /// fn this_will_always_build() { /* I, sure, whatever, you do you. */ } | |
| 40 /// ``` | |
| 41 /// | |
| 42 /// [man7]: https://man7.org/linux/man-pages/man3/pam_conv.3.html | |
| 43 #[doc(inline)] | |
| 44 pub use libpam_sys_impls::cfg_pam_impl; | |
| 45 | 6 |
| 46 mod constants; | 7 mod constants; |
| 47 mod ffi; | 8 mod ffi; |
| 48 pub mod helpers; | 9 pub mod helpers; |
| 10 pub mod pam_impl; | |
| 49 | 11 |
| 50 #[doc(inline)] | 12 #[doc(inline)] |
| 51 pub use crate::{constants::*, ffi::*}; | 13 pub use crate::{constants::*, ffi::*, pam_impl::*}; |
| 52 | |
| 53 // Looking for the actual code defining this enum? | |
| 54 // It's in the build.rs file for libpam_sys_impls. | |
| 55 __pam_impl_enum__!(#[non_exhaustive]); |
