-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
104 lines (90 loc) · 2.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use glob::glob;
use std::env;
use std::{path::PathBuf, process::Command};
/// Get the path to the repo root (uses git to find the repo root)
fn get_repo_root() -> PathBuf {
let repo_root = Command::new("git")
.arg("rev-parse")
.arg("--show-toplevel")
.output()
.unwrap()
.stdout;
let repo_root = String::from_utf8(repo_root).unwrap();
let repo_root = repo_root.trim();
let repo_root = PathBuf::from(repo_root);
repo_root
}
/// Get the path to WASI-SDK root (uses git to find the repo root)
fn get_wasi_sdk_root() -> PathBuf {
let repo_root = get_repo_root();
repo_root.join("deps/wasi-sdk")
}
/// Get the path to the WASI-SDK cc binary
fn get_wasi_cc() -> PathBuf {
get_wasi_sdk_root().join("bin/clang")
}
/// Get the path to the WASI-SDK ar binary
fn get_wasi_ar() -> PathBuf {
get_wasi_sdk_root().join("bin/llvm-ar")
}
fn main() {
println!("cargo:rerun-if-changed=src/lfs");
println!("cargo:rerun-if-changed=src/lfs-sys");
println!("cargo:rerun-if-changed=src/lfs-rambd");
let files = glob("*.o").unwrap().chain(glob("*.a").unwrap());
files.for_each(|f| {
let f = f.unwrap();
Command::new("rm").arg("-f").arg(f).output().unwrap();
});
let clang_ar = get_wasi_ar();
let clang_cc = get_wasi_cc();
let out = Command::new(clang_cc)
.arg("-std=c11")
.arg("-Wall")
.arg("-Wextra")
.arg("-Werror")
.arg("-Wpedantic")
.arg("-O3")
.arg("-static")
.arg("-fPIC")
.arg("-DLFS_NO_DEBUG")
.arg("-DLFS_NO_WARN")
.arg("-DLFS_NO_ERROR")
.arg("-DLFS_NO_ASSERT")
.arg("-DLFS_THREADSAFE")
.arg("-mmutable-globals")
.arg("-matomics")
.arg("-mbulk-memory")
.arg("-c")
.arg("-Isrc/lfs")
.arg("-Isrc/lfs-sys")
.arg("-Isrc/lfs-rambd")
.arg("src/lfs/lfs.c")
.arg("src/lfs/lfs_util.c")
.arg("src/lfs-sys/lfs_sys.c")
.arg("src/lfs-rambd/lfs_rambd.c")
.output()
.unwrap();
if !out.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&out.stdout));
println!("stderr: {}", String::from_utf8_lossy(&out.stderr));
panic!("failed to compile lfs");
}
let out = Command::new(clang_ar)
.arg("-r")
.arg("liblfs.a")
.arg("lfs.o")
.arg("lfs_sys.o")
.arg("lfs_util.o")
.arg("lfs_rambd.o")
.output()
.unwrap();
if !out.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&out.stdout));
println!("stderr: {}", String::from_utf8_lossy(&out.stderr));
panic!("failed to compile lfs");
}
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-search=native={}", dir);
println!("cargo:rustc-link-lib=lfs");
}