-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
38 lines (33 loc) · 992 Bytes
/
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
extern crate xdrgen;
use std::process::Command;
use std::fs::OpenOptions;
use std::env;
use std::path::PathBuf;
use std::io::Write;
fn compile(source: &str) {
// compiling remote_protocol.x is a bit more involved
// first process it with cpp to eval defines
let cpp = Command::new("/usr/bin/cpp")
// constants from libvirt-host.h
.arg("-include")
.arg("libvirt-defs.h")
.arg(source)
.output().unwrap();
// then write output to temporarily file
let out_dir = env::var("OUT_DIR").unwrap();
let mut path = PathBuf::from(out_dir);
path.push(source);
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&path).unwrap();
file.write_all(&cpp.stdout).unwrap();
// finally run xdrgen
let path_str = format!("{}", path.display());
xdrgen::compile(path_str).unwrap();
}
fn main() {
compile("virnetprotocol.x");
compile("remote_protocol.x");
}