Skip to content

Commit 12d7ec3

Browse files
committed
Fix Bitcoin Core 0.21.2 upgrade
Fix the build after vendoring new version of Core. Includes changes to the build script by Jake and update to the C++ toolchain suggested by Richard. Co-developed-by: Jake Rawsthorne <jake@jakerawsthorne.co.uk> Co-developed-by: Richard Ulrich <richard.ulrich@seba.swiss>
1 parent a4f30ef commit 12d7ec3

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

build.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@ fn main() {
2121
let is_big_endian = env::var("CARGO_CFG_TARGET_ENDIAN").expect("No endian is set") == "big";
2222
let mut base_config = cc::Build::new();
2323
base_config
24-
.cpp(true)
25-
.include("depend/bitcoin/src")
2624
.include("depend/bitcoin/src/secp256k1/include")
2725
.define("__STDC_FORMAT_MACROS", None)
2826
.flag_if_supported("-Wno-implicit-fallthrough");
2927

28+
if target.contains("windows") {
29+
base_config.define("WIN32", "1");
30+
}
31+
32+
let mut secp_config = base_config.clone();
33+
let mut consensus_config = base_config;
34+
3035
// **Secp256k1**
3136
if !cfg!(feature = "external-secp") {
32-
base_config
37+
secp_config
3338
.include("depend/bitcoin/src/secp256k1")
39+
.include("depend/bitcoin/src/secp256k1/src")
3440
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
3541
.define("SECP256K1_BUILD", "1")
3642
// Bitcoin core defines libsecp to *not* use libgmp.
@@ -39,34 +45,40 @@ fn main() {
3945
.define("USE_SCALAR_INV_BUILTIN", "1")
4046
// Technically libconsensus doesn't require the recovery feautre, but `pubkey.cpp` does.
4147
.define("ENABLE_MODULE_RECOVERY", "1")
48+
.define("ECMULT_WINDOW_SIZE", "15")
49+
.define("ECMULT_GEN_PREC_BITS", "4")
50+
.define("ENABLE_MODULE_SCHNORRSIG", "1")
51+
.define("ENABLE_MODULE_EXTRAKEYS", "1")
4252
// The actual libsecp256k1 C code.
4353
.file("depend/bitcoin/src/secp256k1/src/secp256k1.c");
4454

4555
if is_big_endian {
46-
base_config.define("WORDS_BIGENDIAN", "1");
56+
secp_config.define("WORDS_BIGENDIAN", "1");
4757
}
4858

4959
if use_64bit_compilation {
50-
base_config
60+
secp_config
5161
.define("USE_FIELD_5X52", "1")
5262
.define("USE_SCALAR_4X64", "1")
5363
.define("HAVE___INT128", "1");
5464
} else {
55-
base_config.define("USE_FIELD_10X26", "1").define("USE_SCALAR_8X32", "1");
65+
secp_config.define("USE_FIELD_10X26", "1").define("USE_SCALAR_8X32", "1");
5666
}
67+
68+
secp_config.compile("libsecp256k1.a");
5769
}
5870

59-
let tool = base_config.get_compiler();
71+
let tool = consensus_config.get_compiler();
6072
if tool.is_like_msvc() {
61-
base_config.flag("/std:c++14").flag("/wd4100");
73+
consensus_config.flag("/std:c++17").flag("/wd4100");
6274
} else if tool.is_like_clang() || tool.is_like_gnu() {
63-
base_config.flag("-std=c++11").flag("-Wno-unused-parameter");
75+
consensus_config.flag("-std=c++17").flag("-Wno-unused-parameter");
6476
}
6577

66-
if target.contains("windows") {
67-
base_config.define("WIN32", "1");
68-
}
69-
base_config
78+
consensus_config
79+
.cpp(true)
80+
.include("depend/bitcoin/src")
81+
.include("depend/bitcoin/src/secp256k1/include")
7082
.file("depend/bitcoin/src/util/strencodings.cpp")
7183
.file("depend/bitcoin/src/uint256.cpp")
7284
.file("depend/bitcoin/src/pubkey.cpp")

depend/check_uint128_t.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#include <stdint.h>
3+
4+
int main(void) {
5+
__uint128_t var_128;
6+
uint64_t var_64;
7+
8+
/* Try to shut up "unused variable" warnings */
9+
var_64 = 100;
10+
var_128 = 100;
11+
if (var_64 == var_128) {
12+
var_64 = 20;
13+
}
14+
return 0;
15+
}
16+

0 commit comments

Comments
 (0)