Skip to content

Commit 526b86f

Browse files
Change build.rs based on mimblewimble/rust-secp256k1-zkp#71
1 parent e430462 commit 526b86f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

secp256k1-sys/build.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,38 @@ use std::env;
2727

2828
fn main() {
2929
// Actual build
30+
if cfg!(feature = "external-symbols") {
31+
println!("cargo:rustc-link-lib=static=secp256k1-zkp");
32+
return;
33+
}
34+
35+
// Check whether we can use 64-bit compilation
36+
let use_64bit_compilation = if env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "64" {
37+
let check = cc::Build::new().file("depend/check_uint128_t.c")
38+
.cargo_metadata(false)
39+
.try_compile("check_uint128_t")
40+
.is_ok();
41+
if !check {
42+
println!("cargo:warning=Compiling in 32-bit mode on a 64-bit architecture due to lack of uint128_t support.");
43+
}
44+
check
45+
} else {
46+
false
47+
};
48+
49+
// Actual Build
3050
let mut base_config = cc::Build::new();
3151
base_config.include("depend/secp256k1/")
3252
.include("depend/secp256k1/include")
3353
.include("depend/secp256k1/src")
3454
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
3555
.define("SECP256K1_BUILD", Some("1"))
3656
.define("ENABLE_MODULE_ECDH", Some("1"))
57+
.define("ENABLE_MODULE_GENERATOR", Some("1"))
58+
.define("ENABLE_MODULE_RECOVERY", Some("1"))
59+
.define("ENABLE_MODULE_RANGEPROOF", Some("1"))
60+
.define("ENABLE_MODULE_BULLETPROOF", Some("1"))
61+
.define("ENABLE_MODULE_AGGSIG", Some("1"))
3762
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
3863
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
3964
.define("ECMULT_GEN_PREC_BITS", Some("4"))
@@ -47,6 +72,14 @@ fn main() {
4772
} else {
4873
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
4974
}
75+
76+
77+
if let Ok(target_endian) = env::var("CARGO_CFG_TARGET_ENDIAN") {
78+
if target_endian == "big" {
79+
base_config.define("WORDS_BIGENDIAN", Some("1"));
80+
}
81+
}
82+
5083
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
5184
#[cfg(feature = "recovery")]
5285
base_config.define("ENABLE_MODULE_RECOVERY", Some("1"));
@@ -57,6 +90,16 @@ fn main() {
5790
_ => {},
5891
}
5992

93+
94+
if use_64bit_compilation {
95+
base_config.define("USE_FIELD_5X52", Some("1"))
96+
.define("USE_SCALAR_4X64", Some("1"))
97+
.define("HAVE___INT128", Some("1"));
98+
} else {
99+
base_config.define("USE_FIELD_10X26", Some("1"))
100+
.define("USE_SCALAR_8X32", Some("1"));
101+
}
102+
60103
// secp256k1
61104
base_config.file("depend/secp256k1/contrib/lax_der_parsing.c")
62105
.file("depend/secp256k1/src/secp256k1.c")

0 commit comments

Comments
 (0)