forked from scroll-tech/zktrie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
52 lines (47 loc) · 1.49 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
use std::env;
use std::io::{self, Write};
use std::path::Path;
fn main() {
if cfg!(feature = "rs_zktrie") {
return;
}
let lib_name = "zktrie";
let src_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let src_dir = Path::new(src_dir.as_str());
//#[cfg(not(target_os = "windows"))]
//let build_mode = gobuild::BuildMode::CArchive;
//#[cfg(target_os = "windows")]
let build_mode = gobuild::BuildMode::CShared;
let mut build = gobuild::Build::new();
if cfg!(target_os = "macos") {
build.ldflags("-w");
}
build.buildmode(build_mode);
// Build
if let Err(e) = build.try_compile(lib_name) {
// The error type is private so have to check the error string
if format!("{e}").starts_with("Failed to find tool.") {
fail(
" Failed to find Go. Please install Go 1.16 or later \
following the instructions at https://golang.org/doc/install.
On linux it is also likely available as a package."
.to_string(),
);
} else {
fail(format!("{e}"));
}
}
// file updating
let srcs = ["types", "trie", "lib.go", "c.go"];
for src in srcs {
let p = src_dir.join(src);
println!("cargo:rerun-if-changed={}", p.as_path().display());
}
}
fn fail(message: String) {
let _ = writeln!(
io::stderr(),
"\n\nError while building zktrie: {message}\n\n",
);
std::process::exit(1);
}