Mercurial > crates > nonstick
comparison libpam-sys/build.rs @ 190:995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
The previous structure of libpam-sys-impls meant that things got
confusing (including for me) between what constants were build-time
and what constants were run-time. This broke cross-compilation.
This simplifies the way that works so that `libpam-sys-impls` has
*no* build script itself and is intended mostly as a library to be
included in other libraries' build scripts (while also exporting
the PamImpl enum).
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 02 Aug 2025 18:47:46 -0400 |
parents | 0730f5f2ee2a |
children | e915c54097d6 |
comparison
equal
deleted
inserted
replaced
189:b2456d274576 | 190:995aca290452 |
---|---|
1 use std::{env, fs}; | |
2 | |
1 fn main() { | 3 fn main() { |
2 println!("cargo:rustc-link-lib=pam"); | 4 println!("cargo:rustc-link-lib=pam"); |
3 libpam_sys_impls::enable_pam_impl_cfg(); | 5 libpam_sys_impls::enable_pam_impl_cfg(); |
6 | |
7 let pam_impl = libpam_sys_impls::build_target_impl(); | |
8 let impl_str = pam_impl.map(|i| format!("{i:?}")).unwrap_or("[undefined]".into()); | |
9 println!("cargo:rustc-env=LIBPAMSYS_IMPL={impl_str}"); | |
10 let output = match pam_impl { | |
11 None => "".into(), | |
12 Some(pam_impl) => { | |
13 format!("\ | |
14 /// The implementation of PAM this library was built against. | |
15 pub const CURRENT: PamImpl = PamImpl::{pam_impl:?}; | |
16 /// The name of the PAM implementation this library was built | |
17 /// against, as a string. | |
18 #[macro_export] | |
19 macro_rules! pam_impl_name {{ () => {{ \"{pam_impl:?}\" }} }} | |
20 pub(crate) use pam_impl_name; | |
21 ") | |
22 } | |
23 }; | |
24 let outfile = format!("{out}/pam_impl_consts.rs", out = env::var("OUT_DIR").expect("missing OUT_DIR env var")); | |
25 fs::write(outfile, output).expect("couldn't write output file"); | |
4 } | 26 } |