Mercurial > crates > nonstick
annotate build.rs @ 88:c9fc7e6257d3 default tip
This is a v0.0.7 if I ever saw one.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 10 Jun 2025 05:36:58 -0400 |
parents | a638a45e5f1f |
children |
rev | line source |
---|---|
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
1 use bindgen::MacroTypeVariation; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
2 use std::env; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
3 use std::path::PathBuf; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
4 |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
5 fn main() { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
6 if cfg!(feature = "link") { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
7 println!("cargo::rustc-check-cfg=cfg(pam_impl, values(\"linux-pam\",\"openpam\"))"); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
8 let common_builder = bindgen::Builder::default() |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
9 .merge_extern_blocks(true) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
10 .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
11 .blocklist_type("pam_handle") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
12 .blocklist_type("pam_conv") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
13 .allowlist_var(".*") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
14 .allowlist_function("pam_start") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
15 .allowlist_function("pam_[gs]et_item") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
16 .allowlist_function("pam_get_user") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
17 .allowlist_function("pam_get_authtok") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
18 .allowlist_function("pam_end") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
19 .dynamic_link_require_all(true) |
84
a638a45e5f1f
do some real irritating i32/u32 juggling to make bindgen happy
Paul Fisher <paul@pfish.zone>
parents:
83
diff
changeset
|
20 .default_macro_constant_type(MacroTypeVariation::Unsigned); |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
21 |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
22 let linux_builder = common_builder |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
23 .clone() |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
24 // This function is not available in OpenPAM. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
25 // We don't use it, but we include it so that if the user |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
26 // tries to run this against the wrong PAM library, it fails. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
27 .allowlist_function("pam_start_confdir") |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
28 .header_contents( |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
29 "linux-pam.h", |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
30 r#" |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
31 #include <security/_pam_types.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
32 #include <security/pam_appl.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
33 #include <security/pam_ext.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
34 #include <security/pam_modules.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
35 "#, |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
36 ); |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
37 let openpam_builder = common_builder |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
38 .clone() |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
39 // This function is not available in Linux-PAM. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
40 // We don't use it, but we include it so that if the user |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
41 // tries to run this against the wrong PAM library, it fails. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
42 .allowlist_function("pam_setenv") |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
43 .header_contents( |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
44 "openpam.h", |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
45 r#" |
83
9fc778c03bff
Reorder pam_types to work on BSD.
Paul Fisher <paul@pfish.zone>
parents:
82
diff
changeset
|
46 #include <security/pam_types.h> |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
47 #include <security/openpam.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
48 #include <security/pam_appl.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
49 #include <security/pam_constants.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
50 "#, |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
51 ); |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
52 |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
53 let (pam_impl, bindings) = { |
82
73c3f8e3b49d
Don't immediately fail when running build.rs.
Paul Fisher <paul@pfish.zone>
parents:
81
diff
changeset
|
54 if let Ok(bindings) = linux_builder.generate() { |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
55 ("linux-pam", bindings) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
56 } else if let Ok(bindings) = openpam_builder.generate() { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
57 ("openpam", bindings) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
58 } else { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
59 panic!("unrecognized PAM implementation") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
60 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
61 }; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
62 println!("cargo::rustc-cfg=pam_impl={pam_impl:?}"); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
63 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
64 bindings |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
65 .write_to_file(out_path.join("bindings.rs")) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
66 .unwrap(); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
67 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
68 } |