Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to WASM and Rust Node.js addon (N-API). #53

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
},
},
],
};
281 changes: 281 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
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-browser:
name: Test in 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 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

test-node:
name: Test in Node.js
needs: [test-browser]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- name: Fetch code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Rust nightly with rust-src
run: rustup toolchain install nightly --component rust-src

- 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: Download compiled wasm
uses: actions/download-artifact@v2
with:
name: wasm
path: lib

- name: Build JS
run: make build-js

- name: Add target x86_64-unknown-linux-musl and musl-tools
if: runner.os == 'Linux'
run: |
rustup toolchain install nightly --target x86_64-unknown-linux-musl
sudo apt-get install musl-tools

- name: Build addon (Linux)
if: runner.os == 'Linux'
run: make build-addon-x86_64-unknown-linux-musl+x64-linux.so

- name: Build addon (macOS)
if: runner.os == 'macOS'
run: make build-addon-x86_64-apple-darwin+x64-darwin.dylib

- name: Build addon (Windows)
if: runner.os == 'Windows'
run: make build-addon-x86_64-pc-windows-msvc+x64-win32.dll

- name: Run tests and coverage
run: |
make test-node-raw-ci
make test-node-coverage-raw

- name: Upload addon (Linux)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib/secp256k1-x64-linux.so

- name: Upload addon (macOS)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-darwin.dylib
path: lib/secp256k1-x64-darwin.dylib

- name: Upload addon (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v2
with:
name: secp256k1-x64-win32.dll
path: lib/secp256k1-x64-win32.dll

package:
name: Create package
needs: [test-node]
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 Linux addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib

- name: Download compiled macOS addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-darwin.dylib
path: lib

- name: Download compiled Windows addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-win32.dll
path: lib

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

- name: Create package
run: |
mkdir package
# Copy LICENSE, README.md
cp LICENSE package/LICENSE
cp README.md package/README.md
# Copy js, addon, wasm
cp -r lib package/lib
# Copy package.json, on-install.js, rust-toolchain
cp package.json package/package.json
node util/update-package-json.js package/package.json
cp util/on-install.js package/on-install.js
cp rust-toolchain package/rust-toolchain
# Copy addon source
cp -r secp256k1 package/secp256k1
cp -r secp256k1-node package/secp256k1-node
cp -r secp256k1-wasm package/secp256k1-wasm
cp Cargo.lock package/Cargo.lock
cp Cargo.toml package/Cargo.toml
# Run `npm pack`
cd package
npm pack

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

benchmark:
name: Benchmark
needs: [test-node]
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 addon
uses: actions/download-artifact@v2
with:
name: secp256k1-x64-linux.so
path: lib

- 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.

Loading