-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbuild.rs
More file actions
131 lines (116 loc) · 3.24 KB
/
build.rs
File metadata and controls
131 lines (116 loc) · 3.24 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
extern crate cc;
use std::env;
use std::path::Path;
fn main() {
// rerun if changes to the C code
println!("cargo:rerun-if-changed=depend");
let simplicity_path = Path::new("depend/simplicity");
let mut files = vec![];
// 1. Base files.
files.extend(
[
"frame.c",
"jets.c",
"jets-secp256k1.c",
"rsort.c",
"sha256.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
// 2. Test files.
if cfg!(feature = "test-utils") {
files.extend(
[
"bitstream.c",
"dag.c",
"deserialize.c",
"eval.c",
"type.c",
"typeInference.c",
"ctx8Pruned.c",
"ctx8Unpruned.c",
"hashBlock.c",
"schnorr0.c",
"schnorr6.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
}
// Split into Bitcoin and Elements.
let mut elements_files = files.clone();
let mut bitcoin_files = files;
// 3B. Bitcoin base files.
bitcoin_files.extend(
[
"bitcoin/env.c",
"bitcoin/ops.c",
"bitcoin/bitcoinJets.c",
"bitcoin/txEnv.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
bitcoin_files.push("depend/bitcoin_env.c".into());
// 3E. Elements base files.
elements_files.extend(
[
"elements/env.c",
"elements/ops.c",
"elements/elementsJets.c",
"elements/txEnv.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
elements_files.push("depend/elements_env.c".into());
if cfg!(feature = "test-utils") {
// 4B. Bitcoin base files.
bitcoin_files.extend(
[
"bitcoin/exec.c",
"bitcoin/primitive.c",
// "bitcoin/checkSigHashAllTx1.c", // no sighashall test
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
// 4E. Elements base files.
elements_files.extend(
[
"elements/exec.c",
"elements/primitive.c",
"elements/checkSigHashAllTx1.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
}
// General build
let mut build = cc::Build::new();
build
.std("c11")
.flag_if_supported("-fno-inline-functions")
.opt_level(2)
.file(Path::new("depend/wrapper.c"))
.file(Path::new("depend/jets_wrapper.c"))
.include(simplicity_path.join("include"));
if cfg!(not(fuzzing)) {
build.define("PRODUCTION", None);
}
// Fix missing libc in WASM
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "wasm32" {
build.include("wasm-sysroot");
}
let mut bitcoin_build = build.clone();
let mut elements_build = build;
// Bitcoin build
bitcoin_build
.files(bitcoin_files)
.compile("BitcoinSimplicity");
// Elements build
elements_build
.files(elements_files)
.compile("ElementsSimplicity");
}