# HG changeset patch # User Paul Fisher # Date 1752437211 14400 # Node ID e9354e655f38183ae1cb920b46cee90a0b1a02b4 # Parent 09dff285ff5e83c1196b27d23f1ac1942e8043ce Improve PAM detection docs. diff -r 09dff285ff5e -r e9354e655f38 libpam-sys/README.md --- a/libpam-sys/README.md Sun Jul 13 15:38:00 2025 -0400 +++ b/libpam-sys/README.md Sun Jul 13 16:06:51 2025 -0400 @@ -16,6 +16,33 @@ Normally, this crate exports all functionality available in the selected PAM library. `XSso` exports only the subset of the [X/SSO specification][xsso] supported by both OpenPAM and Sun PAM. +### Changing behavior based on PAM implementation + +Downstream crates can detect the current PAM implementation using custom `#[cfg]`s: + +```rust +// Your package's build.rs: +use libpam_sys::pam_impl; + +fn main() { + pam_impl::enable_pam_impl_cfg(); + + // the rest of your build script... +} +``` + +This will enable the use of `#[cfg]`s that look like this: + +```rust +#[cfg(pam_impl = "Sun")] +fn some_func() { /* Sun-specific implementation */ } + +#[cfg(any(pam_impl = "LinuxPam", pam_impl = "OpenPam"))] +fn some_func() { /* Linux-PAM / OpenPAM implementation */ } +``` + +Further documentation on this is available in `libpam-sys-consts`. + ## Testing Tests are mostly run through `libpam-sys-test`, which lives in the crate's workspace in its repository (along with [nonstick]). diff -r 09dff285ff5e -r e9354e655f38 libpam-sys/libpam-sys-consts/README.md --- a/libpam-sys/libpam-sys-consts/README.md Sun Jul 13 15:38:00 2025 -0400 +++ b/libpam-sys/libpam-sys-consts/README.md Sun Jul 13 16:06:51 2025 -0400 @@ -24,7 +24,7 @@ ```rust // build.rs -use libpam_sys_helpers::pam_impl; +use libpam_sys_consts::pam_impl; fn main() { pam_impl::enable_pam_impl_cfg(); diff -r 09dff285ff5e -r e9354e655f38 libpam-sys/libpam-sys-consts/src/lib.rs --- a/libpam-sys/libpam-sys-consts/src/lib.rs Sun Jul 13 15:38:00 2025 -0400 +++ b/libpam-sys/libpam-sys-consts/src/lib.rs Sun Jul 13 16:06:51 2025 -0400 @@ -15,6 +15,18 @@ /// Use [`enable_pam_impl_cfg`] in your `build.rs` to generate custom `#[cfg]`s /// for conditional compilation based on PAM implementation. /// +/// ``` +/// // Your package's build.rs: +/// +/// use libpam_sys_consts::pam_impl; +/// // also available at libpam_sys::pam_impl +/// +/// fn main() { +/// pam_impl::enable_pam_impl_cfg(); +/// // whatever else you do in your build script. +/// } +/// ``` +/// /// This will set the current `pam_impl` as well as registering all known /// PAM implementations with `rustc-check-cfg` to get cfg-checking. ///