Mercurial > crates > nonstick
annotate 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 |
rev | line source |
---|---|
190
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
1 use std::{env, fs}; |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
2 |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
3 fn main() { |
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
4 println!("cargo:rustc-link-lib=pam"); |
176
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
5 libpam_sys_impls::enable_pam_impl_cfg(); |
190
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
6 |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
7 let pam_impl = libpam_sys_impls::build_target_impl(); |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
8 let impl_str = pam_impl.map(|i| format!("{i:?}")).unwrap_or("[undefined]".into()); |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
9 println!("cargo:rustc-env=LIBPAMSYS_IMPL={impl_str}"); |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
10 let output = match pam_impl { |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
11 None => "".into(), |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
12 Some(pam_impl) => { |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
13 format!("\ |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
14 /// The implementation of PAM this library was built against. |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
15 pub const CURRENT: PamImpl = PamImpl::{pam_impl:?}; |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
16 /// The name of the PAM implementation this library was built |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
17 /// against, as a string. |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
18 #[macro_export] |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
19 macro_rules! pam_impl_name {{ () => {{ \"{pam_impl:?}\" }} }} |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
20 pub(crate) use pam_impl_name; |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
21 ") |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
22 } |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
23 }; |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
24 let outfile = format!("{out}/pam_impl_consts.rs", out = env::var("OUT_DIR").expect("missing OUT_DIR env var")); |
995aca290452
Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents:
176
diff
changeset
|
25 fs::write(outfile, output).expect("couldn't write output file"); |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
26 } |