Skip to content

Commit

Permalink
Move secp256k1 build into a separate function
Browse files Browse the repository at this point in the history
This just moves the code that configures the build for `secp256k1p`, but
the plan is to have this function perform an independent build.
  • Loading branch information
jvff committed Jul 14, 2021
1 parent 7a72f7e commit 56f5555
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,7 @@ fn main() -> Result<()> {

// **Secp256k1**
if !cfg!(feature = "external-secp") {
base_config
.include("depend/zcash/src/secp256k1")
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
.flag_if_supported("-Wno-missing-field-initializers")
.define("SECP256K1_BUILD", "1")
// zcash core defines libsecp to *not* use libgmp.
.define("USE_NUM_NONE", "1")
.define("USE_FIELD_INV_BUILTIN", "1")
.define("USE_SCALAR_INV_BUILTIN", "1")
.define("ECMULT_WINDOW_SIZE", "15")
.define("ECMULT_GEN_PREC_BITS", "4")
// Use the endomorphism optimization now that the patents have expired.
.define("USE_ENDOMORPHISM", "1")
// Technically libconsensus doesn't require the recovery feature, but `pubkey.cpp` does.
.define("ENABLE_MODULE_RECOVERY", "1")
// The actual libsecp256k1 C code.
.file("depend/zcash/src/secp256k1/src/secp256k1.c");

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

if is_64bit_compilation() {
base_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");
}
build_secp256k1(&mut base_config);
}

if target.contains("windows") {
Expand All @@ -124,6 +93,42 @@ fn main() -> Result<()> {
Ok(())
}

/// Build the `secp256k1` library.
fn build_secp256k1(build: &mut cc::Build) {
build
.include("depend/zcash/src/secp256k1")
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
.flag_if_supported("-Wno-missing-field-initializers")
.define("SECP256K1_BUILD", "1")
// zcash core defines libsecp to *not* use libgmp.
.define("USE_NUM_NONE", "1")
.define("USE_FIELD_INV_BUILTIN", "1")
.define("USE_SCALAR_INV_BUILTIN", "1")
.define("ECMULT_WINDOW_SIZE", "15")
.define("ECMULT_GEN_PREC_BITS", "4")
// Use the endomorphism optimization now that the patents have expired.
.define("USE_ENDOMORPHISM", "1")
// Technically libconsensus doesn't require the recovery feature, but `pubkey.cpp` does.
.define("ENABLE_MODULE_RECOVERY", "1")
// The actual libsecp256k1 C code.
.file("depend/zcash/src/secp256k1/src/secp256k1.c");

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

if is_64bit_compilation() {
build
.define("USE_FIELD_5X52", "1")
.define("USE_SCALAR_4X64", "1")
.define("HAVE___INT128", "1");
} else {
build
.define("USE_FIELD_10X26", "1")
.define("USE_SCALAR_8X32", "1");
}
}

/// Checker whether the target architecture is big endian.
fn is_big_endian() -> bool {
let endianess = env::var("CARGO_CFG_TARGET_ENDIAN").expect("No endian is set");
Expand Down

0 comments on commit 56f5555

Please sign in to comment.