Skip to content

Commit

Permalink
Merge pull request #55 from fanatid/to-wasm-update
Browse files Browse the repository at this point in the history
Upgrade to WASM
  • Loading branch information
junderw authored Apr 15, 2021
2 parents 5a311f1 + 88eb5f3 commit 364d214
Show file tree
Hide file tree
Showing 68 changed files with 27,565 additions and 1,389 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
node: true,
browser: true,
es2020: true,
},
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
rules: {
"@typescript-eslint/explicit-module-boundary-types": "off",
},
overrides: [
{
files: ["*.ts"],
rules: {
"@typescript-eslint/explicit-module-boundary-types": ["error"],
},
},
],
};
162 changes: 162 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: CI

on: [push, pull_request]

env:
NODE_VERSION: 14.0.0

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Rust nightly with wasm32-unknown-unknown, clippy and rustfmt
run: |
rustup toolchain install nightly \
--target wasm32-unknown-unknown \
--component clippy \
--component rustfmt
- name: Install Node.js@${{ env.NODE_VERSION }}
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Node.js dependencies
run: npm ci

- name: Run lint
run: |
make lint
test:
name: Test in Node.js / browser (electron)
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Rust nightly with wasm32-unknown-unknown
run: rustup toolchain install nightly --target wasm32-unknown-unknown

- name: Install Node.js@${{ env.NODE_VERSION }}
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Node.js dependencies
run: npm ci

- uses: actions/cache@v2
id: binaryen-cache
with:
path: binaryen-version_100
key: binaryen-version_100

- name: Install wasm-opt (binaryen)
if: steps.binaryen-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_100/binaryen-version_100-x86_64-linux.tar.gz
tar zxvf binaryen-version_100-x86_64-linux.tar.gz binaryen-version_100/bin/wasm-opt
- name: Build wasm
run: export PATH=$PATH:./binaryen-version_100/bin/ && make build-wasm

- name: Build JS
run: make build-js

- name: Run Node.js tests and coverage
run: |
make test-node-raw-ci
make test-node-coverage-raw
- name: Run browser (electron) tests
env:
DISPLAY: :99.0
run: |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
make test-browser-build-raw
make test-browser-raw-ci
- name: Upload wasm
uses: actions/upload-artifact@v2
with:
name: wasm
path: lib/secp256k1.wasm

package:
name: Create package
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Node.js@${{ env.NODE_VERSION }}
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Node.js dependencies
run: npm ci

- name: Build JS
run: make build-js

- name: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib

- name: Create package
run: npm pack

- name: Upload package
uses: actions/upload-artifact@v2
with:
name: package
path: tiny-secp256k1-*

benchmark:
name: Benchmark
needs: [test]
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Node.js@${{ env.NODE_VERSION }}
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Node.js dependencies
run: npm ci

- name: Build JS
run: make build-js

- name: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib

- name: Install benchmark dependencies
run: cd benches && npm ci

- name: Run benchmark
run: cd benches && npm start
54 changes: 54 additions & 0 deletions .github/workflows/gh-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches:
- main

env:
NODE_VERSION: 14.0.0

jobs:
publish-react-app:
name: Publish react example
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Rust nightly with wasm32-unknown-unknown
run: rustup toolchain install nightly --target wasm32-unknown-unknown

- name: Install Node.js dependencies
run: |
npm ci
cd examples/react-app && npm ci
- uses: actions/cache@v2
id: binaryen-cache
with:
path: binaryen-version_100
key: binaryen-version_100

- name: Install wasm-opt (binaryen)
if: steps.binaryen-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_100/binaryen-version_100-x86_64-linux.tar.gz
tar zxvf binaryen-version_100-x86_64-linux.tar.gz binaryen-version_100/bin/wasm-opt
- name: Build wasm
run: export PATH=$PATH:./binaryen-version_100/bin/ && make build-wasm

- name: Build JS
run: make build-js

- name: Build react-app
run: cd examples/react-app && npm run build

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@4.1.1
with:
branch: gh-pages
folder: examples/react-app/dist
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
build/
coverage/
node_modules/
tests/bundle.js
package-lock.json
/.nyc_output
/benches/node_modules
/coverage
/examples/random-in-node/node_modules
/examples/react-app/dist
/examples/react-app/node_modules
/lib
/node_modules
/target
/tests/browser
/types
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "native/secp256k1"]
path = native/secp256k1
[submodule "util/gen-fixtures/secp256k1"]
path = util/gen-fixtures/secp256k1
url = https://github.com/bitcoin-core/secp256k1.git
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "secp256k1-wasm"
version = "0.0.0"
authors = ["Kirill Fomichev <fanatid@ya.ru>"]
edition = "2018"
description = "A Rust library for building tiny-secp256k1 WASM."
license = "MIT"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
# `[patch.crates-io]` is not working :(
# `more-features` branch add features: ecdh, extrakeys, schnorrsig.
# This reuqired because LTO do not strip not used functions in resulted WASM file.
# secp256k1-sys PR: https://github.com/rust-bitcoin/rust-secp256k1/pull/287
secp256k1-sys = { version = "0.4.0", default-features = false, git = "https://github.com/TheBlueMatt/rust-secp256k1", branch = "2021-03-no-vis" }
# secp256k1-sys = { version = "0.4.0", default-features = false, git = "https://github.com/fanatid/rust-secp256k1", branch = "more-features" }

[profile.release]
lto = true
panic = "abort"
codegen-units = 1
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM debian:buster

RUN apt update && \
# Install common dependencies
apt install -y \
cmake \
curl \
g++ \
gcc \
git \
make \
wget \
# LLVM script
gnupg \
lsb-release \
software-properties-common \
# Electron
libasound2 \
libgbm1 \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libxi6 \
libxss1 \
libxtst6 \
xvfb && \
# Install LLVM:12
curl -sSf https://apt.llvm.org/llvm.sh | bash -s -- 12 && \
ln -s $(which clang-12) /usr/bin/clang && \
# Install Node.js:14
curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
apt install nodejs -y && \
# Install Rust nightly
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \
--default-toolchain nightly \
--profile minimal \
--component clippy,rustfmt,rust-src \
--target wasm32-unknown-unknown && \
# Install wasm-opt from binaryen
git clone --depth 1 --branch version_100 https://github.com/WebAssembly/binaryen.git /binaryen && \
cd /binaryen && \
cmake . && \
make -j$(nproc) && \
make install && \
rm -rf /binaryen && \
# Remove apt files
rm -rf /var/lib/{apt,dpkg,cache,log}/

CMD Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & export DISPLAY=':99.0' && bash
Loading

0 comments on commit 364d214

Please sign in to comment.