-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
83 lines (73 loc) · 2.91 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
use std::{env, process::Command};
fn build_secp256k1() {
let target = env::var("TARGET").expect("TARGET was not set");
let mut builder = cc::Build::new();
builder
.opt_level(1)
.flag_if_supported("-Wno-unused-function")
.define("ENABLE_MODULE_EXTRAKEYS", "1")
.define("ENABLE_MODULE_RECOVERY", "1")
.define("ENABLE_MODULE_SCHNORRSIG", "1")
.include("depends/bitcoin/src/secp256k1/include")
.include("depends/bitcoin/src/secp256k1/src")
.file("depends/bitcoin/src/secp256k1/src/precomputed_ecmult.c")
.file("depends/bitcoin/src/secp256k1/src/secp256k1.c");
if target.contains("windows") {
builder.define("WIN32", "1");
}
builder.compile("libsecp256k1.a")
}
// Run `autogen.sh` and `configure` scripts for Bitcoin
fn configure_bitcoin() {
// Set the Bitcoin source directory
static SOURCE_DIR: &str = "depends/bitcoin";
let out_dir = env::var("OUT_DIR").unwrap();
// Run the configure script to generate config headers
let status = Command::new("sh")
.arg("-c")
.arg(format!(
"cd {SOURCE_DIR} && ./autogen.sh && ./configure --with-secp256k1={out_dir}"
))
.status()
.expect("failed to configure Bitcoin Core");
if !status.success() {
panic!("Bitcoin Core configuration failed");
}
}
fn main() {
build_secp256k1();
configure_bitcoin();
let out_dir = env::var("OUT_DIR").unwrap();
let target = env::var("TARGET").expect("TARGET was not set");
let mut builder = cc::Build::new();
builder
.cpp(true)
.flag("-std=c++20")
.opt_level(1)
.flag("-Wno-unused-parameter")
.include(&out_dir)
.include("depends/bitcoin/src")
.include("depends/bitcoin/src/secp256k1/include")
.file("depends/bitcoin/src/crypto/ripemd160.cpp")
.file("depends/bitcoin/src/crypto/sha1.cpp")
.file("depends/bitcoin/src/crypto/sha256.cpp")
.file("depends/bitcoin/src/hash.cpp")
.file("depends/bitcoin/src/pubkey.cpp")
.file("depends/bitcoin/src/primitives/transaction.cpp")
.file("depends/bitcoin/src/script/interpreter.cpp")
.file("depends/bitcoin/src/script/script.cpp")
.file("depends/bitcoin/src/script/script_error.cpp")
.file("depends/bitcoin/src/support/cleanse.cpp")
.file("depends/bitcoin/src/uint256.cpp")
.file("depends/bitcoin/src/util/strencodings.cpp")
.file("stubs/bitcoin-script.cpp");
if target.contains("windows") {
builder.define("WIN32", "1");
}
builder.compile("bitcoin-script.a");
println!("cargo:include=depends/bitcoin/src");
println!("cargo:rerun-if-changed=stubs/bitcoin-script.cpp");
println!("cargo:rustc-link-lib=static=secp256k1");
println!("cargo:rustc-link-search=native=depends/bitcoin/src/.libs");
println!("cargo:rustc-link-search=native={}", out_dir);
}