2015-10-26 15:21:01 +00:00
|
|
|
// Bitcoin secp256k1 bindings
|
|
|
|
// Written in 2015 by
|
|
|
|
// Andrew Poelstra
|
|
|
|
//
|
|
|
|
// To the extent possible under law, the author(s) have dedicated all
|
|
|
|
// copyright and related and neighboring rights to this software to
|
|
|
|
// the public domain worldwide. This software is distributed without
|
|
|
|
// any warranty.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the CC0 Public Domain Dedication
|
|
|
|
// along with this software.
|
|
|
|
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
//! # Build script
|
|
|
|
|
|
|
|
// Coding conventions
|
|
|
|
#![deny(non_upper_case_globals)]
|
|
|
|
#![deny(non_camel_case_types)]
|
|
|
|
#![deny(non_snake_case)]
|
|
|
|
#![deny(unused_mut)]
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
2018-07-30 02:53:20 +00:00
|
|
|
extern crate cc;
|
2015-10-26 15:21:01 +00:00
|
|
|
|
2019-01-09 12:15:28 +00:00
|
|
|
use std::env;
|
2018-08-21 18:41:42 +00:00
|
|
|
|
2015-10-26 15:21:01 +00:00
|
|
|
fn main() {
|
2019-10-29 11:19:53 +00:00
|
|
|
if cfg!(feature = "external-symbols") {
|
|
|
|
println!("cargo:rustc-link-lib=static=secp256k1");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:11:43 +00:00
|
|
|
// Actual build
|
2018-07-30 02:53:20 +00:00
|
|
|
let mut base_config = cc::Build::new();
|
2015-10-26 17:59:40 +00:00
|
|
|
base_config.include("depend/secp256k1/")
|
2015-10-26 21:26:45 +00:00
|
|
|
.include("depend/secp256k1/include")
|
2015-10-26 17:59:40 +00:00
|
|
|
.include("depend/secp256k1/src")
|
2018-08-26 18:58:33 +00:00
|
|
|
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
|
2018-07-24 17:30:04 +00:00
|
|
|
.define("SECP256K1_BUILD", Some("1"))
|
2020-05-13 08:40:39 +00:00
|
|
|
.define("ENABLE_MODULE_ECDH", Some("1"))
|
2020-09-15 01:42:20 +00:00
|
|
|
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
|
|
|
|
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
|
2020-05-13 08:40:39 +00:00
|
|
|
.define("ECMULT_GEN_PREC_BITS", Some("4"))
|
2015-10-26 17:59:40 +00:00
|
|
|
// TODO these three should be changed to use libgmp, at least until secp PR 290 is merged
|
|
|
|
.define("USE_NUM_NONE", Some("1"))
|
|
|
|
.define("USE_FIELD_INV_BUILTIN", Some("1"))
|
2020-05-13 08:40:39 +00:00
|
|
|
.define("USE_SCALAR_INV_BUILTIN", Some("1"));
|
|
|
|
|
2019-08-07 18:00:35 +00:00
|
|
|
if cfg!(feature = "lowmemory") {
|
|
|
|
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory
|
|
|
|
} else {
|
|
|
|
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
|
|
|
|
}
|
2019-10-28 21:05:38 +00:00
|
|
|
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
|
2019-06-11 20:32:54 +00:00
|
|
|
#[cfg(feature = "endomorphism")]
|
|
|
|
base_config.define("USE_ENDOMORPHISM", Some("1"));
|
2019-05-21 07:37:15 +00:00
|
|
|
#[cfg(feature = "recovery")]
|
|
|
|
base_config.define("ENABLE_MODULE_RECOVERY", Some("1"));
|
2015-10-26 17:59:40 +00:00
|
|
|
|
2019-01-09 12:15:28 +00:00
|
|
|
if let Ok(target_endian) = env::var("CARGO_CFG_TARGET_ENDIAN") {
|
2018-08-31 08:26:06 +00:00
|
|
|
if target_endian == "big" {
|
|
|
|
base_config.define("WORDS_BIGENDIAN", Some("1"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 20:13:21 +00:00
|
|
|
match &env::var("TARGET").unwrap() as &str {
|
|
|
|
"wasm32-unknown-unknown"|"wasm32-wasi" =>
|
|
|
|
{ base_config.include("wasm-sysroot"); },
|
|
|
|
_ => {},
|
2020-04-16 17:07:14 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 17:59:40 +00:00
|
|
|
// secp256k1
|
2016-01-14 18:35:54 +00:00
|
|
|
base_config.file("depend/secp256k1/contrib/lax_der_parsing.c")
|
2015-10-26 17:59:40 +00:00
|
|
|
.file("depend/secp256k1/src/secp256k1.c")
|
|
|
|
.compile("libsecp256k1.a");
|
2015-10-26 15:21:01 +00:00
|
|
|
}
|
|
|
|
|