-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
45 lines (31 loc) · 1.26 KB
/
build.rs
File metadata and controls
45 lines (31 loc) · 1.26 KB
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
use std::process::Command;
use std::env;
use std::path::Path;
use std::io::Write;
use std::fs::File;
fn try_gcc(lib: &str, msg: &str) {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("main.c");
let mut f = File::create(&dest_path).unwrap();
f.write_all(b"
int main() {
}
").unwrap();
let s = Command::new("gcc")
.args(&[dest_path.into_os_string().to_str().unwrap(), lib, "-o"])
.arg(&format!("{}/main.o", out_dir))
.status()
.unwrap();
assert!(s.success(), "\n\n".to_string() + msg);
}
fn main() {
try_gcc("-lpcap", "pcap not found. On Ubuntu try 'sudo apt-get install libpcap-dev' before continuing.");
try_gcc("-lcrypto", "crypto not found. On Ubuntu try 'sudo apt-get install libssl-dev' before continuing.");
let out_dir = env::var("OUT_DIR").unwrap();
Command::new("gcc").args(&["icmp/net.c", "-c", "-fPIC", "-o"])
.arg(&format!("{}/net.o", out_dir)).status().unwrap();
Command::new("ar").args(&["crus", "libicmp.a", "net.o"])
.current_dir(&Path::new(&out_dir)).status().unwrap();
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=icmp");
}