forked from scroll-tech/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
67 lines (60 loc) · 1.78 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
use std::{
env,
io::{self, Write},
};
fn main() {
let lib_name = "go-geth-utils";
let out_dir = env::var("OUT_DIR").unwrap();
// Build
let mut build = gobuild::Build::new();
if cfg!(target_os = "macos") {
build.ldflags("-w");
}
let target_files = if cfg!(feature = "scroll") {
vec!["./l2geth/trace.go", "./l2geth/lib.go"]
} else {
vec!["./l1geth/trace.go", "./l1geth/lib.go"]
};
if let Err(e) = build.files(target_files).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.18 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}"));
}
}
// Files the lib depends on that should recompile the lib
let dep_files = if cfg!(feature = "scroll") {
vec![
"./l2geth/trace.go",
"./l2geth/lib.go",
"./l2geth/go.mod",
"./l2geth/go.sum",
]
} else {
vec![
"./l1geth/trace.go",
"./l1geth/lib.go",
"./l1geth/go.mod",
"./l1geth/go.sum",
]
};
for file in dep_files {
println!("cargo:rerun-if-changed={file}");
}
// Link
println!("cargo:rustc-link-search=native={out_dir}");
println!("cargo:rustc-link-lib=static={lib_name}");
}
fn fail(message: String) {
let _ = writeln!(
io::stderr(),
"\n\nError while building geth-utils: {message}\n\n"
);
std::process::exit(1);
}