Mercurial > crates > nonstick
comparison build.rs @ 80:5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
- Uses bindgen to generate bindings (only if needed).
- Gets the story together on owned vs. borrowed handles.
- Reduces number of mutable borrows in handle operation
(since `PamHandle` is neither `Send` nor `Sync`,
we never have to worry about thread safety.
- Improves a bunch of macros so we don't have our own
special syntax for docs.
- Implement question indirection for standard XSSO PAM implementations.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Tue, 10 Jun 2025 01:09:30 -0400 |
| parents | |
| children | a8f4718fed5d |
comparison
equal
deleted
inserted
replaced
| 79:2128123b9406 | 80:5aa1a010f1e8 |
|---|---|
| 1 use bindgen::MacroTypeVariation; | |
| 2 use std::env; | |
| 3 use std::path::PathBuf; | |
| 4 | |
| 5 fn main() { | |
| 6 if cfg!(feature = "link") { | |
| 7 println!("cargo::rustc-check-cfg=cfg(pam_impl, values(\"linux-pam\",\"openpam\"))"); | |
| 8 let common_builder = bindgen::Builder::default() | |
| 9 .merge_extern_blocks(true) | |
| 10 .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | |
| 11 .blocklist_type("pam_handle") | |
| 12 .blocklist_type("pam_conv") | |
| 13 .allowlist_var(".*") | |
| 14 .allowlist_function("pam_start") | |
| 15 .allowlist_function("pam_[gs]et_item") | |
| 16 .allowlist_function("pam_get_user") | |
| 17 .allowlist_function("pam_get_authtok") | |
| 18 .allowlist_function("pam_end") | |
| 19 .dynamic_link_require_all(true) | |
| 20 .default_macro_constant_type(MacroTypeVariation::Signed); | |
| 21 | |
| 22 let linux_builder = common_builder.clone().header_contents( | |
| 23 "linux-pam.h", | |
| 24 r#" | |
| 25 #include <security/_pam_types.h> | |
| 26 #include <security/pam_appl.h> | |
| 27 #include <security/pam_ext.h> | |
| 28 #include <security/pam_modules.h> | |
| 29 "#, | |
| 30 ); | |
| 31 let openpam_builder = common_builder.clone().header_contents( | |
| 32 "openpam.h", | |
| 33 r#" | |
| 34 #include <security/openpam.h> | |
| 35 #include <security/pam_appl.h> | |
| 36 #include <security/pam_constants.h> | |
| 37 #include <security/pam_types.h> | |
| 38 "#, | |
| 39 ); | |
| 40 | |
| 41 let (pam_impl, bindings) = { | |
| 42 let bb = linux_builder.generate(); | |
| 43 bb.as_ref().unwrap(); | |
| 44 if let Ok(bindings) = bb { | |
| 45 ("linux-pam", bindings) | |
| 46 } else if let Ok(bindings) = openpam_builder.generate() { | |
| 47 ("openpam", bindings) | |
| 48 } else { | |
| 49 panic!("unrecognized PAM implementation") | |
| 50 } | |
| 51 }; | |
| 52 println!("cargo::rustc-cfg=pam_impl={pam_impl:?}"); | |
| 53 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | |
| 54 bindings | |
| 55 .write_to_file(out_path.join("bindings.rs")) | |
| 56 .unwrap(); | |
| 57 } | |
| 58 } |
