forked from parallaxsecond/rust-tss-esapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
61 lines (56 loc) · 2.53 KB
/
build.rs
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
// Copyright 2019 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use std::env;
use std::path::PathBuf;
// Minimum version of the TSS 2.0 libraries that this crate can use.
const MINIMUM_VERSION: &str = "2.3.3";
fn main() {
if cfg!(not(feature = "docs")) {
let tss2_esys = pkg_config::Config::new()
.atleast_version(MINIMUM_VERSION)
.probe("tss2-esys")
.expect("Error with pkg-config finding tss2-esys.");
let tss2_tctildr = pkg_config::Config::new()
.atleast_version(MINIMUM_VERSION)
.probe("tss2-tctildr")
.expect("Error with pkg-config finding tss2-tctildr.");
let tss2_mu = pkg_config::Config::new()
.atleast_version(MINIMUM_VERSION)
.probe("tss2-mu")
.expect("Error with pkg-config finding tss2-mu.");
// These three pkg-config files should contain only one include/lib path.
let tss2_esys_include_path = tss2_esys.include_paths[0]
.clone()
.into_os_string()
.into_string()
.expect("Error converting OsString to String.");
let tss2_tctildr_include_path = tss2_tctildr.include_paths[0]
.clone()
.into_os_string()
.into_string()
.expect("Error converting OsString to String.");
let tss2_mu_include_path = tss2_mu.include_paths[0]
.clone()
.into_os_string()
.into_string()
.expect("Error converting OsString to String.");
let bindings = bindgen::Builder::default()
.clang_arg(format!("-I{}/tss2/", tss2_esys_include_path))
.clang_arg(format!("-I{}/tss2/", tss2_tctildr_include_path))
.clang_arg(format!("-I{}/tss2/", tss2_mu_include_path))
.rustfmt_bindings(true)
.header(format!("{}/tss2/tss2_esys.h", tss2_esys_include_path))
.header(format!("{}/tss2/tss2_tctildr.h", tss2_tctildr_include_path))
.header(format!("{}/tss2/tss2_mu.h", tss2_mu_include_path))
.generate_comments(false)
.derive_default(true)
.generate()
.expect("Unable to generate bindings to TSS2 ESYS APIs.");
let out_path = PathBuf::from(
env::var("OUT_DIR").expect("Error while getting the OUT_DIR environment variable."),
);
bindings
.write_to_file(out_path.join("tss2_esys_bindings.rs"))
.unwrap_or_else(|_| panic!("Couldn't write bindings to {:?}!", out_path));
}
}