Debian Codegraph @

build.rs

raw symbols SCIP
1 extern crate bindgen;
2
3 fn create_bindings(
4 apr_path: &std::path::Path,
5 apu_path: &std::path::Path,
6 out_path: &std::path::Path,
7 apr_include_paths: &[&std::path::Path],
8 ) {
9 // Generate bindings using bindgen
10 let mut builder = bindgen::Builder::default().use_core();
11 // check if the pool-debug feature is present
12 if std::env::var("CARGO_FEATURE_POOL_DEBUG").is_ok() {
13 builder = builder.clang_arg("-DAPR_POOL_DEBUG");
14 }
15 let bindings = builder
16 .header(apr_path.join("apr.h").to_str().unwrap())
17 .header(apr_path.join("apr_allocator.h").to_str().unwrap())
18 .header(apr_path.join("apr_general.h").to_str().unwrap())
19 .header(apr_path.join("apr_errno.h").to_str().unwrap())
20 .header(apr_path.join("apr_pools.h").to_str().unwrap())
21 .header(apr_path.join("apr_version.h").to_str().unwrap())
22 .header(apr_path.join("apr_tables.h").to_str().unwrap())
23 .header(apr_path.join("apr_hash.h").to_str().unwrap())
24 .header(apr_path.join("apr_file_info.h").to_str().unwrap())
25 .header(apr_path.join("apr_file_io.h").to_str().unwrap())
26 .header(apr_path.join("apr_getopt.h").to_str().unwrap())
27 .header(apu_path.join("apr_uri.h").to_str().unwrap())
28 .header(apr_path.join("apr_time.h").to_str().unwrap())
29 .header(apu_path.join("apr_date.h").to_str().unwrap())
30 .header(apr_path.join("apr_version.h").to_str().unwrap())
31 .header(apu_path.join("apu_version.h").to_str().unwrap())
32 .header(apr_path.join("apr_strings.h").to_str().unwrap())
33 .header(apr_path.join("apr_thread_proc.h").to_str().unwrap())
34 .header(apr_path.join("apr_thread_mutex.h").to_str().unwrap())
35 .header(apr_path.join("apr_thread_cond.h").to_str().unwrap())
36 .header(apr_path.join("apr_dso.h").to_str().unwrap())
37 .header(apr_path.join("apr_env.h").to_str().unwrap())
38 .header(apr_path.join("apr_network_io.h").to_str().unwrap())
39 .header(apr_path.join("apr_mmap.h").to_str().unwrap())
40 .header(apr_path.join("apr_user.h").to_str().unwrap())
41 .header(apu_path.join("apr_md5.h").to_str().unwrap())
42 .header(apu_path.join("apr_sha1.h").to_str().unwrap())
43 .header(apu_path.join("apr_base64.h").to_str().unwrap())
44 .header(apu_path.join("apr_uuid.h").to_str().unwrap())
45 .header(apu_path.join("apr_strmatch.h").to_str().unwrap())
46 .header(apu_path.join("apr_xlate.h").to_str().unwrap())
47 .header(apu_path.join("apr_xml.h").to_str().unwrap())
48 .header(apu_path.join("apr_crypto.h").to_str().unwrap())
49 .header(apu_path.join("apr_queue.h").to_str().unwrap())
50 .header_contents(
51 "platform_headers.h",
52 if cfg!(windows) {
53 "#include <winsock2.h>\n#include <ws2tcpip.h>"
54 } else {
55 "#include <sys/socket.h>\n#include <sys/types.h>"
56 },
57 )
58 .allowlist_file(".*[/\\\\]apr.h")
59 .allowlist_file(".*[/\\\\]apr_general.h")
60 .allowlist_file(".*[/\\\\]apr_allocator.h")
61 .allowlist_file(".*[/\\\\]apr_version.h")
62 .allowlist_file(".*[/\\\\]apr_errno.h")
63 .allowlist_file(".*[/\\\\]apr_pools.h")
64 .allowlist_file(".*[/\\\\]apr_tables.h")
65 .allowlist_file(".*[/\\\\]apr_hash.h")
66 .allowlist_file(".*[/\\\\]apr_file_info.h")
67 .allowlist_file(".*[/\\\\]apr_file_io.h")
68 .allowlist_file(".*[/\\\\]apr_getopt.h")
69 .allowlist_file(".*[/\\\\]apr_uri.h")
70 .allowlist_file(".*[/\\\\]apr_time.h")
71 .allowlist_file(".*[/\\\\]apr_date.h")
72 .allowlist_file(".*[/\\\\]apr_strings.h")
73 .allowlist_file(".*[/\\\\]apr_version.h")
74 .allowlist_file(".*[/\\\\]apu_version.h")
75 .allowlist_file(".*[/\\\\]apr_thread_proc.h")
76 .allowlist_file(".*[/\\\\]apr_thread_mutex.h")
77 .allowlist_file(".*[/\\\\]apr_thread_cond.h")
78 .allowlist_file(".*[/\\\\]apr_dso.h")
79 .allowlist_file(".*[/\\\\]apr_env.h")
80 .allowlist_file(".*[/\\\\]apr_network_io.h")
81 .allowlist_file(".*[/\\\\]apr_mmap.h")
82 .allowlist_file(".*[/\\\\]apr_user.h")
83 .allowlist_file(".*[/\\\\]apr_md5.h")
84 .allowlist_file(".*[/\\\\]apr_sha1.h")
85 .allowlist_file(".*[/\\\\]apr_base64.h")
86 .allowlist_file(".*[/\\\\]apr_uuid.h")
87 .allowlist_file(".*[/\\\\]apr_strmatch.h")
88 .allowlist_file(".*[/\\\\]apr_xlate.h")
89 .allowlist_file(".*[/\\\\]apr_xml.h")
90 .allowlist_file(".*[/\\\\]apr_crypto.h")
91 .allowlist_file(".*[/\\\\]apr_queue.h")
92 .allowlist_file(".*[/\\\\]apr_portable.h")
93 .allowlist_file(".*[/\\\\]apr_support.h")
94 // Explicitly allowlist fundamental APR types that may be defined via
95 // typedef chains through system headers. On some platforms (e.g. EL9),
96 // bindgen may attribute these to system headers rather than apr.h,
97 // causing them to be filtered out by the allowlist_file rules above.
98 .allowlist_type("apr_int16_t")
99 .allowlist_type("apr_uint16_t")
100 .allowlist_type("apr_int32_t")
101 .allowlist_type("apr_uint32_t")
102 .allowlist_type("apr_int64_t")
103 .allowlist_type("apr_uint64_t")
104 .allowlist_type("apr_size_t")
105 .allowlist_type("apr_ssize_t")
106 .allowlist_type("apr_off_t")
107 .allowlist_type("apr_socklen_t")
108 .allowlist_type("apr_ino_t")
109 .allowlist_type("apr_uintptr_t")
110 .allowlist_type("apr_intptr_t")
111 .clang_args(
112 apr_include_paths
113 .iter()
114 .map(|path| format!("-I{}", path.display())),
115 )
116 .generate()
117 .expect("Failed to generate bindings");
118
119 bindings
120 .write_to_file(out_path.join("bindings.rs"))
121 .expect("Failed to write bindings");
122 }
123
124 fn main() {
125 let deps = system_deps::Config::new().probe().unwrap();
126
127 let apr = deps.get_by_name("apr-1").unwrap();
128
129 let apr_util = deps.get_by_name("apr-util-1").unwrap();
130
131 let apr_path = apr
132 .include_paths
133 .iter()
134 .find(|x| x.join("apr.h").exists())
135 .expect("Failed to find apr.h");
136
137 let apr_util_path = apr_util
138 .include_paths
139 .iter()
140 .find(|x| x.join("apu.h").exists())
141 .expect("Failed to find apu.h");
142
143 let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
144 create_bindings(
145 apr_path.as_path(),
146 apr_util_path.as_path(),
147 out_path.as_path(),
148 apr.include_paths
149 .iter()
150 .map(|x| x.as_path())
151 .collect::<Vec<_>>()
152 .as_slice(),
153 );
154
155 // Check if APU_HAVE_CRYPTO is defined and non-zero in apu.h
156 let apu_h = std::fs::read_to_string(apr_util_path.join("apu.h")).expect("Failed to read apu.h");
157 let has_crypto = apu_h.lines().any(|line| {
158 let trimmed = line.trim();
159 if let Some(rest) = trimmed.strip_prefix("#define") {
160 let rest = rest.trim();
161 if let Some(value) = rest.strip_prefix("APU_HAVE_CRYPTO") {
162 return value.trim() != "0";
163 }
164 }
165 false
166 });
167 if has_crypto {
168 println!("cargo:rustc-cfg=apu_have_crypto");
169 }
170 }