forked from instructure/jsoncdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
50 lines (42 loc) · 1.42 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
extern crate cc;
use std::process::Command;
#[derive(Default)]
struct PGConfig {
includedir: String,
includedir_server: String,
libdir: String,
}
fn pg_config() -> PGConfig {
let output = Command::new("pg_config").output().unwrap_or_else(|e| {
panic!("Failed to execute process: {}", e)
});
/* Sample result:
...
INCLUDEDIR = /usr/local/Cellar/postgresql/9.4.5/include
PKGINCLUDEDIR = /usr/local/Cellar/postgresql/9.4.5/include
INCLUDEDIR-SERVER = /usr/local/Cellar/postgresql/9.4.5/include/server
LIBDIR = /usr/local/Cellar/postgresql/9.4.5/lib
...
*/
let mut config = PGConfig { ..Default::default() };
let text = String::from_utf8(output.stdout).expect("Expected UTF-8 from call to `pg_config`.");
for words in text.lines().map(|line| line.split_whitespace()) {
let vec: Vec<&str> = words.collect();
match vec[0] {
"INCLUDEDIR" => config.includedir = vec[2].into(),
"INCLUDEDIR-SERVER" => config.includedir_server = vec[2].into(),
"LIBDIR" => config.libdir = vec[2].into(),
_ => {}
}
}
config
}
fn main() {
let config = pg_config();
cc::Build::new()
.file("src/magic.c")
.include(config.includedir)
.include(config.includedir_server)
.compile("libmagic.a");
// The GCC module emits `rustc-link-lib=static=magic` for us.
}