Debian Codegraph @

build.rs

raw symbols SCIP
1 extern crate bindgenrust-analyzer cargo leptonica-sys 0.4.9 bindgen/;
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#;
5 #[cfg(windows)]
6 use vcpkg;
7
8 // const MINIMUM_LEPT_VERSION: &str = "1.80.0";
9
10 #[cfg(windows)]
11 fn find_leptonica_system_lib() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
12 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rerun-if-env-changed=LEPTONICA_INCLUDE_PATH");
13 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rerun-if-env-changed=LEPTONICA_LINK_PATHS");
14 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rerun-if-env-changed=LEPTONICA_LINK_LIBS");
15
16 let vcpkg = || {
17 let lib = vcpkg::Config::new().find_package("leptonica").unwrap();
18
19 let include = lib
20 .include_paths
21 .iter()
22 .map(|x| x.to_string_lossy())
23 .collect::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>();
24 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(includerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include!)
25 };
26
27 let include_path = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("LEPTONICA_INCLUDE_PATH").ok();
28 let link_paths = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("LEPTONICA_LINK_PATHS").ok();
29 let link_paths = link_paths.as_deref().map(|x| x.split(','));
30 let link_libs = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("LEPTONICA_LINK_LIBS").ok();
31 let link_libs = link_libs.as_deref().map(|x| x.split(','));
32 if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(include_path), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(link_paths), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(link_libs)) =
33 (include_path, link_paths, link_libs)
34 {
35 for link_path in link_paths {
36 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-search={}", link_path)
37 }
38
39 for link_lib in link_libs {
40 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-lib={}", link_lib)
41 }
42
43 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(include_path)
44 } else {
45 vcpkg()
46 }
47 }
48
49 // we sometimes need additional search paths, which we get using pkg-config
50 // we can use leptonica installed anywhere on Linux.
51 // if you change install path(--prefix) to `configure` script.
52 // set `export PKG_CONFIG_PATH=/path-to-lib/pkgconfig` before.
53 #[cfg(any(target_os = "macos", target_os = "linux", target_os = "freebsd"))]
54 fn find_leptonica_system_librust-analyzer cargo leptonica-sys 0.4.9 find_leptonica_system_lib().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
55 let pk = pkg_configrust-analyzer cargo pkg-config 0.3.34 crate/::Configrust-analyzer cargo pkg-config 0.3.34 Config#::newrust-analyzer cargo pkg-config 0.3.34 impl#[Config]new().().proberust-analyzer cargo pkg-config 0.3.34 impl#[Config]probe().("lept").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
56 // Tell cargo to tell rustc to link the system proj shared library.
57 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-search=native={:?}", pk.link_pathsrust-analyzer cargo pkg-config 0.3.34 Library#link_paths.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
58 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-lib={}", pk.libsrust-analyzer cargo pkg-config 0.3.34 Library#libs.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
59
60 let mut include_path = pk.include_pathsrust-analyzer cargo pkg-config 0.3.34 Library#include_paths.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().();
61 if include_path.ends_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]ends_with().("leptonica") {
62 include_path.poprust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]pop().();
63 }
64 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(include_path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
65 }
66
67 #[cfg(all(
68 not(windows),
69 not(target_os = "macos"),
70 not(target_os = "linux"),
71 not(target_os = "freebsd")
72 ))]
73 fn find_leptonica_system_lib() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
74 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("cargo:rustc-link-lib=lept");
75 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
76 }
77
78 fn mainrust-analyzer cargo leptonica-sys 0.4.9 main().() {
79 let clang_extra_include = find_leptonica_system_librust-analyzer cargo leptonica-sys 0.4.9 find_leptonica_system_lib().();
80
81 let mut bindings = bindgenrust-analyzer cargo bindgen 0.72.1 crate/::Builderrust-analyzer cargo bindgen 0.72.1 Builder#::defaultrust-analyzer cargo bindgen 0.72.1 impl#[Builder][Default]default().().headerrust-analyzer cargo bindgen 0.72.1 options/impl#[Builder]header().("wrapper.h");
82
83 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(include_path) = clang_extra_include {
84 bindings = bindings.clang_argrust-analyzer cargo bindgen 0.72.1 options/impl#[Builder]clang_arg().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-I{}", include_path));
85 }
86
87 bindings = bindings.blocklist_typerust-analyzer cargo bindgen 0.72.1 options/impl#[Builder]blocklist_type().("max_align_t");
88
89 let bindings = bindings
90 .parse_callbacksrust-analyzer cargo bindgen 0.72.1 options/impl#[Builder]parse_callbacks().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(bindgenrust-analyzer cargo bindgen 0.72.1 crate/::CargoCallbacksrust-analyzer cargo bindgen 0.72.1 CargoCallbacks.))
91 .generaterust-analyzer cargo bindgen 0.72.1 impl#[Builder]generate().()
92 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Unable to generate bindings");
93
94 let out_path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<String>`]from().(envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("OUT_DIR").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
95 bindings
96 .write_to_filerust-analyzer cargo bindgen 0.72.1 impl#[Bindings]write_to_file().(out_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("bindings.rs"))
97 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Couldn't write bindings!");
98 }