Re-support WASM via simple stub headers
libsecp256k1 really only barely uses libc at all, and in practice, things like memcpy/memcmp get optimized into something other than a libc call. Thus, if we provide simple stub headers, things seem to work with wasm-pack just fine.
This commit is contained in:
parent
9aa768df10
commit
d9d398ccc9
23
.travis.yml
23
.travis.yml
|
@ -1,19 +1,24 @@
|
|||
language: rust
|
||||
# cache:
|
||||
# directories:
|
||||
# - cargo_web
|
||||
cache:
|
||||
directories:
|
||||
- wasm
|
||||
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
- 1.22.0
|
||||
distro: bionic
|
||||
os:
|
||||
- linux
|
||||
- windows
|
||||
|
||||
addons:
|
||||
chrome: stable
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
- nodejs
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
|
@ -46,8 +51,10 @@ script:
|
|||
cd no_std_test &&
|
||||
cargo run --release | grep -q "Verified Successfully";
|
||||
fi
|
||||
- #if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||
#CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web &&
|
||||
#cargo web build --verbose --target=asmjs-unknown-emscripten &&
|
||||
#cargo web test --verbose --target=asmjs-unknown-emscripten;
|
||||
#fi
|
||||
- if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||
clang --version &&
|
||||
CARGO_TARGET_DIR=wasm cargo install --verbose --force wasm-pack &&
|
||||
sed -i 's/\[lib\]/[lib]\ncrate-type = ["cdylib", "rlib"]/' Cargo.toml &&
|
||||
CC=clang-9 wasm-pack build &&
|
||||
CC=clang-9 wasm-pack test --node;
|
||||
fi
|
||||
|
|
|
@ -46,6 +46,10 @@ rand_core = "0.4"
|
|||
serde_test = "1.0"
|
||||
bitcoin_hashes = "0.7"
|
||||
|
||||
[target.wasm32-unknown-unknown.dev-dependencies]
|
||||
wasm-bindgen-test = "0.3"
|
||||
rand = { version = "0.6", features = ["wasm-bindgen"] }
|
||||
|
||||
[dependencies.rand]
|
||||
version = "0.6"
|
||||
optional = true
|
||||
|
|
|
@ -84,6 +84,10 @@ fn main() {
|
|||
.define("USE_SCALAR_8X32", Some("1"));
|
||||
}
|
||||
|
||||
if env::var("TARGET").unwrap() == "wasm32-unknown-unknown" {
|
||||
base_config.include("wasm-sysroot");
|
||||
}
|
||||
|
||||
// secp256k1
|
||||
base_config.file("depend/secp256k1/contrib/lax_der_parsing.c")
|
||||
.file("depend/secp256k1/src/secp256k1.c")
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#include <stddef.h>
|
||||
void *memset(void *s, int c, size_t n);
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
27
src/lib.rs
27
src/lib.rs
|
@ -1060,6 +1060,33 @@ mod tests {
|
|||
assert_tokens(&sig.compact(), &[Token::BorrowedBytes(&SIG_BYTES[..])]);
|
||||
assert_tokens(&sig.readable(), &[Token::BorrowedStr(SIG_STR)]);
|
||||
}
|
||||
|
||||
// For WASM, just run through our general tests in this file all at once.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
extern crate wasm_bindgen_test;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use self::wasm_bindgen_test::*;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[wasm_bindgen_test]
|
||||
fn stuff() {
|
||||
test_manual_create_destroy();
|
||||
test_raw_ctx();
|
||||
// Note that, sadly, WASM doesn't currently properly unwind panics, so use of the library
|
||||
// via unsafe primitives may cause abort() instead of catch-able panics.
|
||||
/*assert!(std::panic::catch_unwind(|| {
|
||||
test_panic_raw_ctx();
|
||||
}).is_err());*/
|
||||
test_preallocation();
|
||||
capabilities();
|
||||
signature_serialize_roundtrip();
|
||||
signature_display();
|
||||
signature_lax_der();
|
||||
sign_and_verify();
|
||||
sign_and_verify_extreme();
|
||||
sign_and_verify_fail();
|
||||
test_bad_slice();
|
||||
test_low_s();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "unstable"))]
|
||||
|
|
Loading…
Reference in New Issue