changeset 121:397743cb70e2 default tip

Make libpam-sys-tests work on Illumos!
author Paul Fisher <paul@pfish.zone>
date Mon, 30 Jun 2025 03:43:48 -0400
parents 0f913ec120ac
children
files libpam-sys/libpam-sys-test/Cargo.toml libpam-sys/libpam-sys-test/build.rs
diffstat 2 files changed, 50 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-test/Cargo.toml	Mon Jun 30 01:41:48 2025 -0400
+++ b/libpam-sys/libpam-sys-test/Cargo.toml	Mon Jun 30 03:43:48 2025 -0400
@@ -11,5 +11,6 @@
 [build-dependencies]
 bindgen = "0.72.0"
 libpam-sys-impls = { path = "../libpam-sys-impls" }
+libpam-sys = { path = ".." }
 quote = "1.0.40"
 syn = { version = "2.0.104", default-features = false }
--- a/libpam-sys/libpam-sys-test/build.rs	Mon Jun 30 01:41:48 2025 -0400
+++ b/libpam-sys/libpam-sys-test/build.rs	Mon Jun 30 03:43:48 2025 -0400
@@ -1,56 +1,56 @@
 use bindgen::MacroTypeVariation;
-use libpam_sys_impls::cfg_pam_impl;
+use libpam_sys::PamImpl;
 use quote::{format_ident, ToTokens};
 use std::path::PathBuf;
 use std::{env, fs};
 use syn::{Item, ItemConst, Type, TypePath};
 
 fn main() {
-    generate_const_test();
-}
-
-#[cfg_pam_impl("LinuxPam")]
-fn test_config() -> TestConfig {
-    TestConfig {
-        headers: vec![
-            "security/_pam_types.h".into(),
-            "security/pam_appl.h".into(),
-            "security/pam_ext.h".into(),
-            "security/pam_modules.h".into(),
-        ],
-        ignore_consts: vec![
-            "__LINUX_PAM__".into(),
-            "__LINUX_PAM_MINOR__".into(),
-            "PAM_AUTHTOK_RECOVER_ERR".into(),
-        ],
-    }
+    let config = match PamImpl::CURRENT {
+        PamImpl::LinuxPam => TestConfig {
+            headers: vec![
+                "security/_pam_types.h".into(),
+                "security/pam_appl.h".into(),
+                "security/pam_ext.h".into(),
+                "security/pam_modules.h".into(),
+            ],
+            ignore_consts: vec![
+                "__LINUX_PAM__".into(),
+                "__LINUX_PAM_MINOR__".into(),
+                "PAM_AUTHTOK_RECOVER_ERR".into(),
+            ],
+            ..Default::default()
+        },
+        PamImpl::OpenPam => TestConfig {
+            headers: vec![
+                "security/pam_types.h".into(),
+                "security/openpam.h".into(),
+                "security/pam_appl.h".into(),
+                "security/pam_constants.h".into(),
+            ],
+            ignore_consts: vec![
+                "OPENPAM_VERSION".into(),
+                "OPENPAM_RELEASE".into(),
+                "PAM_SOEXT".into(),
+            ],
+            ..Default::default()
+        },
+        PamImpl::Sun => TestConfig {
+            headers: vec![
+                "security/pam_appl.h".into(),
+                "security/pam_modules.h".into(),
+            ],
+            block_headers: vec!["sys/types.h".into()],
+            ..Default::default()
+        },
+        PamImpl::XSso => Default::default(),
+        other => panic!("Unknown PAM implementation {other:?}"),
+    };
+    generate_const_test(&config);
 }
 
-#[cfg_pam_impl("OpenPam")]
-fn test_config() -> TestConfig {
-    TestConfig {
-        headers: vec![
-            "security/pam_types.h".into(),
-            "security/openpam.h".into(),
-            "security/pam_appl.h".into(),
-            "security/pam_constants.h".into(),
-        ],
-        ignore_consts: vec![
-            "OPENPAM_VERSION".into(),
-            "OPENPAM_RELEASE".into(),
-            "PAM_SOEXT".into(),
-        ],
-    }
-}
-
-#[cfg_pam_impl(not(any("LinuxPam", "OpenPam")))]
-fn test_config() -> TestConfig {
-    panic!("This PAM implementation is not yet tested.")
-}
-
-fn generate_const_test() {
-    let config = test_config();
-    let builder = bindgen::Builder::default()
+fn generate_const_test(config: &TestConfig) {
+    let mut builder = bindgen::Builder::default()
         .header_contents("_.h", &config.header_contents())
         .merge_extern_blocks(true)
         .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
@@ -58,6 +58,9 @@
         .blocklist_function(".*")
         .allowlist_var(".*")
         .default_macro_constant_type(MacroTypeVariation::Signed);
+    for hdr in config.block_headers.iter() {
+        builder = builder.blocklist_file(".*?/".to_owned() + hdr)
+    }
 
     let generated = builder.generate().unwrap().to_string();
     let file = syn::parse_file(&generated).unwrap();
@@ -95,8 +98,10 @@
     .unwrap();
 }
 
+#[derive(Default)]
 struct TestConfig {
     headers: Vec<String>,
+    block_headers: Vec<String>,
     ignore_consts: Vec<String>,
 }