-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
56 lines (43 loc) · 1.01 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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
extern crate cc;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("wasm_instructions.rs");
let mut f = File::create(&dest_path).unwrap();
let c = &mut cc::Build::new();
c.flag("-I.").file("src/wasm_instructions.h");
// Preprocess w/o line numbers
// -EP for Visual C++
// -E -P for gcc
//
// TODO Compiler detection.
//
// Nothing works, so remove line directives ourselves.
for s in String::from_utf8(c.expand()).unwrap().lines() {
let bytes = s.as_bytes();
if bytes.len() > 0 && bytes [0] != b'#' {
f.write(bytes).unwrap();
f.write(b"\n").unwrap();
}
}
cc::Build::new()
.file("src/w3cpp.cpp")
.compile("w3cpp")
}
/*
The .h file looks like this:
#ifdef FOO
FOO(...)
FOO(...)
#else
#undef FOO
#define FOO(...) ...
#include __FILE__
#undef FOO
#define FOO(...) ...
#include __FILE__
#endif
*/