-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.rs
30 lines (28 loc) · 1.09 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
// netmap doesn't provide these functions as a library, so we cheat, to save porting them manually
// to Rust. This is a very ugly hack.
extern crate cc;
use std::env;
use std::io::prelude::*;
use std::fs;
use std::path::Path;
fn main() {
if let Some(_) = env::var_os("CARGO_FEATURE_NETMAP_WITH_LIBS") {
let out_dir = env::var("OUT_DIR").unwrap();
let tmp_path = Path::new(&out_dir).join("netmap.c");
let mut tmp = fs::File::create(&tmp_path).unwrap();
tmp.write_all(b"#include <sys/time.h>\n\
#include <errno.h>\n\
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef unsigned char u_char;
#include <net/netmap_user.h>\n").unwrap();
cc::Build::new()
.file(&tmp_path)
.define("NETMAP_WITH_LIBS", None)
.define("static", Some(""))
.define("inline", Some(""))
.include("netmap/sys")
.compile("librust_netmap_user.a");
fs::remove_file(&tmp_path).unwrap();
}
}