Skip to content

Commit

Permalink
Fix Bitcoin Core 0.21.2 upgrade
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tcharding committed Nov 30, 2023
1 parent ca4d203 commit 48c70d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
38 changes: 25 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ fn main() {
let is_big_endian = env::var("CARGO_CFG_TARGET_ENDIAN").expect("No endian is set") == "big";
let mut base_config = cc::Build::new();
base_config
.cpp(true)
.include("depend/bitcoin/src")
.include("depend/bitcoin/src/secp256k1/include")
.define("__STDC_FORMAT_MACROS", None);

if target.contains("windows") {
base_config.define("WIN32", "1");
}

let mut secp_config = base_config.clone();
let mut consensus_config = base_config;

// **Secp256k1**
if !cfg!(feature = "external-secp") {
base_config
secp_config
.include("depend/bitcoin/src/secp256k1")
.include("depend/bitcoin/src/secp256k1/src")
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
.define("SECP256K1_BUILD", "1")
// Bitcoin core defines libsecp to *not* use libgmp.
Expand All @@ -38,34 +44,40 @@ fn main() {
.define("USE_SCALAR_INV_BUILTIN", "1")
// Technically libconsensus doesn't require the recovery feautre, but `pubkey.cpp` does.
.define("ENABLE_MODULE_RECOVERY", "1")
.define("ECMULT_WINDOW_SIZE", "15")
.define("ECMULT_GEN_PREC_BITS", "4")
.define("ENABLE_MODULE_SCHNORRSIG", "1")
.define("ENABLE_MODULE_EXTRAKEYS", "1")
// The actual libsecp256k1 C code.
.file("depend/bitcoin/src/secp256k1/src/secp256k1.c");

if is_big_endian {
base_config.define("WORDS_BIGENDIAN", "1");
secp_config.define("WORDS_BIGENDIAN", "1");
}

if use_64bit_compilation {
base_config
secp_config
.define("USE_FIELD_5X52", "1")
.define("USE_SCALAR_4X64", "1")
.define("HAVE___INT128", "1");
} else {
base_config.define("USE_FIELD_10X26", "1").define("USE_SCALAR_8X32", "1");
secp_config.define("USE_FIELD_10X26", "1").define("USE_SCALAR_8X32", "1");
}

secp_config.compile("libsecp256k1.a");
}

let tool = base_config.get_compiler();
let tool = consensus_config.get_compiler();
if tool.is_like_msvc() {
base_config.flag("/std:c++14").flag("/wd4100");
consensus_config.flag("/std:c++17").flag("/wd4100");
} else if tool.is_like_clang() || tool.is_like_gnu() {
base_config.flag("-std=c++11").flag("-Wno-unused-parameter");
consensus_config.flag("-std=c++17").flag("-Wno-unused-parameter");
}

if target.contains("windows") {
base_config.define("WIN32", "1");
}
base_config
consensus_config
.cpp(true)
.include("depend/bitcoin/src")
.include("depend/bitcoin/src/secp256k1/include")
.file("depend/bitcoin/src/util/strencodings.cpp")
.file("depend/bitcoin/src/uint256.cpp")
.file("depend/bitcoin/src/pubkey.cpp")
Expand Down
16 changes: 16 additions & 0 deletions depend/check_uint128_t.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#include <stdint.h>

int main(void) {
__uint128_t var_128;
uint64_t var_64;

/* Try to shut up "unused variable" warnings */
var_64 = 100;
var_128 = 100;
if (var_64 == var_128) {
var_64 = 20;
}
return 0;
}

0 comments on commit 48c70d2

Please sign in to comment.