Skip to content

Switch to ESM / Wasm builds #45

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

Merged
merged 11 commits into from
Oct 28, 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
30 changes: 16 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
emsdk: [ "tot", "latest" ]
fail-fast: false
steps:
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: "Set up Emsdk"
run: |
mkdir $HOME/emsdk
Expand Down Expand Up @@ -75,39 +78,38 @@ jobs:
source $HOME/emsdk/emsdk_env.sh
emcc --version
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
emmake make -j2 binaryen_js
cp ./bin/binaryen_js.js ../../index.js
emmake make -j2 binaryen_wasm
cp ./bin/binaryen_wasm.js ../../index.js
cd ../..
- name: "Test binaryen.js"
run: |
node ./tests/sanity
- name: "Build binaryen.wasm"
- name: "Build wasm-opt"
run: |
cd ./binaryen/build
source $HOME/emsdk/emsdk_env.sh
emcc --version
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
emmake make -j2 binaryen_wasm
cp ./bin/binaryen_wasm.js ../../wasm.js
emmake make -j2 wasm-opt
echo '#!/usr/bin/env node' | cat - ./bin/wasm-opt.js > ../../bin/wasm-opt
cd ../..
- name: "Test binaryen.wasm"
- name: "Test wasm-opt"
run: |
node ./tests/sanity --wasm
- name: "Build wasm-opt"
node ./bin/wasm-opt --help
- name: "Build wasm2js"
run: |
cd ./binaryen/build
source $HOME/emsdk/emsdk_env.sh
emcc --version
emmake make -j2 wasm-opt
echo '#!/usr/bin/env node' | cat - ./bin/wasm-opt.js > ../../bin/wasm-opt
emmake make -j2 wasm2js
echo '#!/usr/bin/env node' | cat - ./bin/wasm2js.js > ../../bin/wasm2js
cd ../..
- name: "Test wasm-opt"
- name: "Test wasm2js"
run: |
node ./bin/wasm-opt --help
node ./bin/wasm2js --help
- name: "Push changes to GitHub"
if: github.event_name == 'schedule' && matrix.emsdk == 'tot'
run: |
git add ./binaryen ./index.js ./wasm.js ./bin/wasm-opt
git add ./binaryen ./index.js ./bin/wasm-opt ./bin/wasm2js
npm version $VERSION --no-git-tag-version --force
if [ $RELEASE ]; then
echo "Committing release ("$VERSION") ..."
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ $> npm install binaryen
```

```js
var binaryen = require("binaryen");
import Binaryen from "binaryen";
const binaryen = await Binaryen();

// Create a module with a single function
var myModule = new binaryen.Module();
Expand Down Expand Up @@ -71,6 +72,10 @@ or you can use one of the [previous versions](https://github.com/AssemblyScript/

Replace `VERSION` with a [specific version](https://github.com/AssemblyScript/binaryen.js/releases) or omit it (not recommended in production) to use main/latest.

### Command line

The package includes Node.js builds of [wasm-opt](https://github.com/WebAssembly/binaryen#wasm-opt) and [wasm2js](https://github.com/WebAssembly/binaryen#wasm2js).

API
---

Expand Down
3 changes: 3 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
2 changes: 1 addition & 1 deletion bin/wasm-opt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions bin/wasm2js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
declare module binaryen {

const isReady: boolean;
const ready: Promise<typeof binaryen>;

type Type = number;

const none: Type;
Expand Down Expand Up @@ -1829,4 +1826,6 @@ declare module binaryen {
}
}

export = binaryen;
declare function Binaryen(): Promise<typeof binaryen>;

export default Binaryen;
803 changes: 488 additions & 315 deletions index.js

Large diffs are not rendered by default.

Loading