File: build.rs

package info (click to toggle)
rust-apr 0.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: makefile: 4
file content (95 lines) | stat: -rw-r--r-- 3,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
extern crate bindgen;

fn create_bindings(
    apr_path: &std::path::Path,
    apu_path: &std::path::Path,
    out_path: &std::path::Path,
    apr_include_paths: &[&std::path::Path],
) {
    // Generate bindings using bindgen
    let mut builder = bindgen::Builder::default();
    // check if the pool-debug feature is present
    if std::env::var("CARGO_FEATURE_POOL_DEBUG").is_ok() {
        builder = builder.clang_arg("-DAPR_POOL_DEBUG");
    }
    let bindings = builder
        .header(apr_path.join("apr.h").to_str().unwrap())
        .header(apr_path.join("apr_allocator.h").to_str().unwrap())
        .header(apr_path.join("apr_general.h").to_str().unwrap())
        .header(apr_path.join("apr_errno.h").to_str().unwrap())
        .header(apr_path.join("apr_pools.h").to_str().unwrap())
        .header(apr_path.join("apr_version.h").to_str().unwrap())
        .header(apr_path.join("apr_tables.h").to_str().unwrap())
        .header(apr_path.join("apr_hash.h").to_str().unwrap())
        .header(apr_path.join("apr_file_info.h").to_str().unwrap())
        .header(apr_path.join("apr_file_io.h").to_str().unwrap())
        .header(apr_path.join("apr_getopt.h").to_str().unwrap())
        .header(apu_path.join("apr_uri.h").to_str().unwrap())
        .header(apr_path.join("apr_time.h").to_str().unwrap())
        .header(apu_path.join("apr_date.h").to_str().unwrap())
        .header(apr_path.join("apr_version.h").to_str().unwrap())
        .header(apu_path.join("apu_version.h").to_str().unwrap())
        .header(apr_path.join("apr_strings.h").to_str().unwrap())
        .header(apr_path.join("apr_thread_proc.h").to_str().unwrap())
        .allowlist_file(".*/apr.h")
        .allowlist_file(".*/apr_general.h")
        .allowlist_file(".*/apr_allocator.h")
        .allowlist_file(".*/apr_version.h")
        .allowlist_file(".*/apr_errno.h")
        .allowlist_file(".*/apr_pools.h")
        .allowlist_file(".*/apr_tables.h")
        .allowlist_file(".*/apr_hash.h")
        .allowlist_file(".*/apr_file_info.h")
        .allowlist_file(".*/apr_file_io.h")
        .allowlist_file(".*/apr_getopt.h")
        .allowlist_file(".*/apr_uri.h")
        .allowlist_file(".*/apr_time.h")
        .allowlist_file(".*/apr_date.h")
        .allowlist_file(".*/apr_strings.h")
        .allowlist_file(".*/apr_version.h")
        .allowlist_file(".*/apu_version.h")
        .allowlist_file(".*/apr_thread_proc.h")
        .clang_args(
            apr_include_paths
                .iter()
                .map(|path| format!("-I{}", path.display())),
        )
        .generate()
        .expect("Failed to generate bindings");

    bindings
        .write_to_file(out_path.join("generated.rs"))
        .expect("Failed to write bindings");
}

fn main() {
    let deps = system_deps::Config::new().probe().unwrap();

    let apr = deps.get_by_name("apr-1").unwrap();

    let apr_util = deps.get_by_name("apr-util-1").unwrap();

    let apr_path = apr
        .include_paths
        .iter()
        .find(|x| x.join("apr.h").exists())
        .expect("Failed to find apr.h");

    let apr_util_path = apr_util
        .include_paths
        .iter()
        .find(|x| x.join("apu.h").exists())
        .expect("Failed to find apu.h");

    let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    create_bindings(
        apr_path.as_path(),
        apr_util_path.as_path(),
        out_path.as_path(),
        apr.include_paths
            .iter()
            .map(|x| x.as_path())
            .collect::<Vec<_>>()
            .as_slice(),
    );
}