Mercurial > crates > nonstick
comparison libpam-sys/libpam-sys-test/build.rs @ 136:efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
This separates the parts of libpam-sys that don't need linking against libpam
from the parts that do need to link against libpam.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 03 Jul 2025 14:28:04 -0400 |
| parents | 6c1e1bdb4164 |
| children | 88627c057709 |
comparison
equal
deleted
inserted
replaced
| 135:b52594841480 | 136:efbc235f01d3 |
|---|---|
| 1 use bindgen::MacroTypeVariation; | 1 use bindgen::MacroTypeVariation; |
| 2 use libpam_sys::pam_impl::PamImpl; | 2 use libpam_sys_helpers::pam_impl::PamImpl; |
| 3 use libpam_sys_helpers::{pam_impl, pam_impl_name}; | |
| 3 use proc_macro2::{Group, Ident, TokenStream, TokenTree}; | 4 use proc_macro2::{Group, Ident, TokenStream, TokenTree}; |
| 4 use quote::{format_ident, ToTokens}; | 5 use quote::{format_ident, ToTokens}; |
| 5 use std::path::Path; | 6 use std::path::Path; |
| 6 use std::process::Command; | 7 use std::process::Command; |
| 7 use std::str::FromStr; | 8 use std::str::FromStr; |
| 9 use syn::{Item, ItemConst}; | 10 use syn::{Item, ItemConst}; |
| 10 | 11 |
| 11 const REDIR_FD: &str = "pam_modutil_redirect_fd"; | 12 const REDIR_FD: &str = "pam_modutil_redirect_fd"; |
| 12 | 13 |
| 13 fn main() { | 14 fn main() { |
| 15 pam_impl::enable_pam_impl_cfg(); | |
| 14 let config = match PamImpl::CURRENT { | 16 let config = match PamImpl::CURRENT { |
| 15 PamImpl::LinuxPam => TestConfig { | 17 PamImpl::LinuxPam => TestConfig { |
| 16 headers: vec![ | 18 headers: vec![ |
| 17 "<security/_pam_types.h>", | 19 "<security/_pam_types.h>", |
| 18 "<security/pam_appl.h>", | 20 "<security/pam_appl.h>", |
| 65 } | 67 } |
| 66 | 68 |
| 67 let generated = builder.generate().unwrap(); | 69 let generated = builder.generate().unwrap(); |
| 68 generated.write_to_file(test_file("bindgen.rs")).unwrap(); | 70 generated.write_to_file(test_file("bindgen.rs")).unwrap(); |
| 69 let file = syn::parse_file(&generated.to_string()).unwrap(); | 71 let file = syn::parse_file(&generated.to_string()).unwrap(); |
| 70 let mut tests = vec![ | 72 let mut tests = vec!["\ |
| 71 "\ | |
| 72 #[allow(dead_code, non_camel_case_types, non_upper_case_globals)] | 73 #[allow(dead_code, non_camel_case_types, non_upper_case_globals)] |
| 73 mod generated { | 74 mod generated { |
| 74 include!(\"bindgen.rs\"); | 75 include!(\"bindgen.rs\"); |
| 75 } | 76 } |
| 76 #[allow(deprecated, overflowing_literals)] | 77 #[allow(deprecated, overflowing_literals)] |
| 77 fn main() { | 78 fn main() { |
| 78 " | 79 " |
| 79 .into(), | 80 .into(), |
| 80 format!( | 81 format!( |
| 81 "assert_eq!(libpam_sys::PamImpl::CURRENT, libpam_sys::PamImpl::{:?});", | 82 "assert_eq!(libpam_sys::pam_impl::PamImpl::CURRENT, libpam_sys::pam_impl::PamImpl::{:?});", |
| 82 PamImpl::CURRENT | 83 PamImpl::CURRENT |
| 83 ), | 84 ), |
| 84 ]; | 85 ]; |
| 85 tests.extend( | 86 tests.extend( |
| 86 file.items | 87 file.items |
| 108 rustfmt(&const_test); | 109 rustfmt(&const_test); |
| 109 } | 110 } |
| 110 | 111 |
| 111 fn generate_ctest(config: &TestConfig) { | 112 fn generate_ctest(config: &TestConfig) { |
| 112 let mut test = ctest::TestGenerator::new(); | 113 let mut test = ctest::TestGenerator::new(); |
| 113 test.cfg("_hack_impl", Some(&format!("{:?}", PamImpl::CURRENT))); | 114 test.cfg("pam_impl", Some(pam_impl_name!())); |
| 114 | 115 |
| 115 for &header in config.headers.iter() { | 116 for &header in config.headers.iter() { |
| 116 if header.starts_with('"') { | 117 if header.starts_with('"') { |
| 117 test.include(env::var("CARGO_MANIFEST_DIR").unwrap()); | 118 test.include(env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 118 } | 119 } |
| 141 // Define away constness because the various PAM implementations | 142 // Define away constness because the various PAM implementations |
| 142 // have different const annotations and this will surely drive you crazy. | 143 // have different const annotations and this will surely drive you crazy. |
| 143 test.define("const", Some("")); | 144 test.define("const", Some("")); |
| 144 | 145 |
| 145 // Also replace all the `const`s with `mut`s in the ffi.rs file. | 146 // Also replace all the `const`s with `mut`s in the ffi.rs file. |
| 146 let file_contents = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/ffi.rs")); | 147 let file_contents = include_str!("../src/lib.rs"); |
| 147 let deconsted_file = test_file("ffi.rs"); | 148 let deconsted_file = test_file("ffi.rs"); |
| 148 remove_consts(file_contents, &deconsted_file); | 149 remove_consts(file_contents, &deconsted_file); |
| 149 | 150 |
| 150 test.generate(&deconsted_file, "ctest.rs"); | 151 test.generate(&deconsted_file, "ctest.rs"); |
| 151 } | 152 } |
