-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
45 lines (39 loc) · 1.32 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
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
Command::new("cp")
.arg("-r")
.arg("lib")
.arg(out_dir.clone())
.status()
.expect("copy liburing to out_dir");
Command::new("make")
.arg("liburing.a")
.current_dir(format!("{}/lib/src", out_dir.clone()))
.env("CFLAGS", "-fPIC")
.status()
.expect("failed to build liburing.a");
// Tell cargo to tell rustc to link the system liburing
// shared library.
println!("cargo:rustc-link-lib=static=uring");
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rustc-link-search=native={}/lib/src", out_dir.clone());
// Generate bindings
let bindings = bindgen::Builder::default()
.whitelist_function("__io_uring.*")
.whitelist_function("io_uring.*")
.whitelist_var("IORING.*")
.whitelist_var("IOSQE.*")
.whitelist_type("io_uring.*")
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(out_dir);
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}