File: build.rs

package info (click to toggle)
rust-gstreamer-sys 0.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 536 kB
  • sloc: makefile: 2; ansic: 1
file content (93 lines) | stat: -rw-r--r-- 2,780 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
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1ae7210)
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
// DO NOT EDIT

extern crate pkg_config;

use pkg_config::{Config, Error};
use std::env;
use std::io;
use std::io::prelude::*;
use std::process;

fn main() {
    if let Err(s) = find() {
        let _ = writeln!(io::stderr(), "{}", s);
        process::exit(1);
    }
}

fn find() -> Result<(), Error> {
    let package_name = "gstreamer-1.0";
    let shared_libs = ["gstreamer-1.0"];
    let version = if cfg!(feature = "v1_16") {
        "1.16"
    } else if cfg!(feature = "v1_14") {
        "1.14"
    } else if cfg!(feature = "v1_12") {
        "1.12"
    } else if cfg!(feature = "v1_10") {
        "1.10"
    } else if cfg!(feature = "v1_8") {
        "1.8"
    } else if cfg!(feature = "v1_6") {
        "1.6"
    } else if cfg!(feature = "v1_4") {
        "1.4"
    } else if cfg!(feature = "v1_2_3") {
        "1.2.3"
    } else if cfg!(feature = "v1_2") {
        "1.2"
    } else if cfg!(feature = "v1_0_10") {
        "1.0.10"
    } else {
        "1.0"
    };

    if let Ok(inc_dir) = env::var("GTK_INCLUDE_DIR") {
        println!("cargo:include={}", inc_dir);
    }
    if let Ok(lib_dir) = env::var("GTK_LIB_DIR") {
        for lib_ in shared_libs.iter() {
            println!("cargo:rustc-link-lib=dylib={}", lib_);
        }
        println!("cargo:rustc-link-search=native={}", lib_dir);
        return Ok(());
    }

    let target = env::var("TARGET").expect("TARGET environment variable doesn't exist");
    let hardcode_shared_libs = target.contains("windows");

    let mut config = Config::new();
    config.atleast_version(version);
    config.print_system_libs(false);
    if hardcode_shared_libs {
        config.cargo_metadata(false);
    }
    match config.probe(package_name) {
        Ok(library) => {
            if let Ok(paths) = std::env::join_paths(library.include_paths) {
                println!("cargo:include={}", paths.to_string_lossy());
            }
            if hardcode_shared_libs {
                for lib_ in shared_libs.iter() {
                    println!("cargo:rustc-link-lib=dylib={}", lib_);
                }
                for path in library.link_paths.iter() {
                    println!(
                        "cargo:rustc-link-search=native={}",
                        path.to_str().expect("library path doesn't exist")
                    );
                }
            }
            Ok(())
        }
        Err(Error::EnvNoPkgConfig(_)) | Err(Error::Command { .. }) => {
            for lib_ in shared_libs.iter() {
                println!("cargo:rustc-link-lib=dylib={}", lib_);
            }
            Ok(())
        }
        Err(err) => Err(err),
    }
}