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

Downgrade node version #12

Merged
merged 6 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/benches/node_modules
/examples/random-in-node/node_modules
/examples/react-app/dist
/examples/react-app/node_modules
/lib
/lib.browser
/lib.node
/node_modules
/target
/tests/browser
Expand Down
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
.PHONY: build-js
build-js:
npx tsc
build-js: build-js-browser build-js-node

.PHONY: build-js-browser
build-js-browser:
npx tsc --project tsconfig.browser.json && \
rm lib.browser/addon.js && \
rm lib.browser/index.js && mv lib.browser/index.browser.js lib.browser/index.js && \
rm lib.browser/rand.js && mv lib.browser/rand.browser.js lib.browser/rand.js && \
rm lib.browser/wasm_loader.js && mv lib.browser/wasm_loader.browser.js lib.browser/wasm_loader.js

.PHONY: build-js-node
build-js-node:
npx tsc --project tsconfig.node.json && rm lib.node/*.browser.js

.PHONY: build-node-%
build-node-%: export PAIR = $(subst +, ,$(subst build-node-,,$@))
build-node-%:
cargo build --package secp256k1-node --target $(firstword $(PAIR)) -Z build-std=panic_abort,std --release
mkdir -p lib && cp -f target/$(firstword $(PAIR))/release/libsecp256k1_node.so lib/secp256k1-$(lastword $(PAIR)).so
strip lib/secp256k1-$(lastword $(PAIR)).so
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/release/libsecp256k1_node.so lib.node/secp256k1-$(lastword $(PAIR)).so
strip lib.node/secp256k1-$(lastword $(PAIR)).so

.PHONY: build-node-debug
build-node-debug:
Expand All @@ -17,29 +28,33 @@ build-node-debug:
build-node-debug-%: export PAIR = $(subst +, ,$(subst build-node-debug-,,$@))
build-node-debug-%:
cargo build --package secp256k1-node --target $(firstword $(PAIR))
mkdir -p lib && cp -f target/$(firstword $(PAIR))/debug/libsecp256k1_node.so lib/secp256k1-$(lastword $(PAIR)).so
mkdir -p lib.node && cp -f target/$(firstword $(PAIR))/debug/libsecp256k1_node.so lib.node/secp256k1-$(lastword $(PAIR)).so

.PHONY: build-wasm
build-wasm:
RUSTFLAGS="-C link-args=-zstack-size=655360" cargo build --package secp256k1-wasm --target wasm32-unknown-unknown --release
mkdir -p lib && cp -f target/wasm32-unknown-unknown/release/secp256k1_wasm.wasm lib/secp256k1.wasm
wasm-opt --strip-debug --strip-producers --output lib/secp256k1.wasm lib/secp256k1.wasm
node util/wasm-strip.js lib/secp256k1.wasm
wasm-opt -O4 --output lib/secp256k1.wasm lib/secp256k1.wasm
mkdir -p lib.browser && cp -f target/wasm32-unknown-unknown/release/secp256k1_wasm.wasm lib.browser/secp256k1.wasm
wasm-opt --strip-debug --strip-producers --output lib.browser/secp256k1.wasm lib.browser/secp256k1.wasm
node util/wasm-strip.js lib.browser/secp256k1.wasm
wasm-opt -O4 --output lib.browser/secp256k1.wasm lib.browser/secp256k1.wasm
mkdir -p lib.node && cp -f lib.browser/secp256k1.wasm lib.node/secp256k1.wasm

.PHONY: build-wasm-debug
build-wasm-debug:
RUSTFLAGS="-C link-args=-zstack-size=655360" cargo build --package secp256k1-wasm --target wasm32-unknown-unknown
mkdir -p lib && cp -f target/wasm32-unknown-unknown/debug/secp256k1_wasm.wasm lib/secp256k1.wasm
mkdir -p lib.browser && cp -f target/wasm32-unknown-unknown/debug/secp256k1_wasm.wasm lib.browser/secp256k1.wasm
mkdir -p lib.node && cp -f target/wasm32-unknown-unknown/debug/secp256k1_wasm.wasm lib.node/secp256k1.wasm

.PHONY: clean
clean:
rm -rf \
benches/node_modules \
examples/random-in-node/node_modules \
examples/react-app/dist/*.js \
examples/react-app/dist/*.wasm \
examples/react-app/node_modules \
lib \
lib.browser \
lib.node \
node_modules \
target \
tests/browser \
Expand Down Expand Up @@ -71,4 +86,4 @@ test-browser: test-browser-build

.PHONY: test-node
test-node: build-js build-node-debug build-wasm-debug
node --experimental-json-modules tests/index.js | npx tap-difflet -p
npx babel-node -b @babel/preset-env tests/index.js | npx tap-difflet -p
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Generate data and demonstrate arguments/result for different methods of `tiny-secp256k1`.

```
npm install
npm start
```

Expand All @@ -12,6 +13,7 @@ npm start
[React](https://reactjs.org/) application with inputs for testing `tiny-secp256k1` methods.

```
npm install
npm start
```

Expand Down
4 changes: 2 additions & 2 deletions examples/random-in-node/bin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as secp256k1 from "../../lib/index.js";
import { generate } from "./index.js";
import * as secp256k1 from "../../";
import { generate } from "./";

const toHex = (v) =>
v instanceof Uint8Array ? Buffer.from(v).toString("hex") : v;
Expand Down
2 changes: 1 addition & 1 deletion examples/random-in-node/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomBytes } from "crypto";
import * as secp256k1 from "../../lib/index.js";
import * as secp256k1 from "../../";

const eq = (v1, v2) =>
v1.length === v2.length && v1.every((v, i) => v === v2[i]);
Expand Down
Loading