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
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::{
env,
path::PathBuf,
};
fn main() {
// Run cmake to build nng
let dst = Config::new("nng")
.generator("Ninja")
.define("CMAKE_BUILD_TYPE", "Release")
.define("NNG_TESTS", "OFF")
.define("NNG_TOOLS", "OFF")
.build();
// Check output of `cargo build --verbose`, should see something like:
// -L native=/path/runng/target/debug/build/runng-sys-abc1234/out
// That contains output from cmake
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
// Tell rustc to use nng static library
println!("cargo:rustc-link-lib=static=nng");
// https://rust-lang-nursery.github.io/rust-bindgen
// https://docs.rs/bindgen
let bindings = bindgen::Builder::default()
.header("wrapper.h")
// This is needed if use `#include <nng.h>` instead of `#include "path/nng.h"`
//.clang_arg("-Inng/src/")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings");
}