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

Update to emcc 3.1.26, use Docker for builds, vendor lz4, compile into dist/, GH actions CI, bump deps #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 0 additions & 16 deletions .circleci/config.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: ["*"]

jobs:
wasm-lz4:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org
cache: "npm"

- run: npm ci
- run: npm run build
- run: npm test
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
# found in the LICENSE file in the root directory of this source tree.
# You may not use this file except in compliance with the License.

dist/
node_modules/
wasm-lz4.js
wasm-lz4.wasm
9 changes: 0 additions & 9 deletions .gitmodules

This file was deleted.

4 changes: 1 addition & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang++-3.8",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
"cppStandard": "c++17"
}
],
"version": 4
Expand Down
16 changes: 5 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
# found in the LICENSE file in the root directory of this source tree.
# You may not use this file except in compliance with the License.

FROM apiaryio/emcc:1.37

# allow work_dir to be changed externally
ARG work_dir=/usr/src/app

# set up work_dir
RUN mkdir -p $work_dir
WORKDIR $work_dir
# FROM apiaryio/emcc:1.37
FROM emscripten/emsdk:3.1.26

# move source files into work_dir
COPY package.json $work_dir
COPY package-lock.json $work_dir
COPY package.json /src
COPY package-lock.json /src
RUN npm install
COPY . $work_dir
COPY . /src

# set production node environment
ENV NODE_ENV=production
38 changes: 3 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

https://github.com/lz4/lz4 compiled to WebAssembly. For now only decompression is supported. PRs welcome!

WASM compilation has been tested with Emscripten SDK [2.0.23](https://github.com/emscripten-core/emsdk/tree/2.0.23).

## API

`wasm-lz4` exports a single function:
Expand Down Expand Up @@ -71,36 +69,6 @@ async function doWork() {

## Developing locally

### Building

#### Step 1

First, and most importantly, you need to install emscripten and activate it into your terminal environment.

IMPORTANT: For now we only support emscripten 2.0.23.

```sh
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install sdk-2.0.23-64bit
./emsdk activate sdk-2.0.23-64bit
source ./emsdk_env.sh
```

#### Step 2

Next, clone the module recursively as it includes [lz4](https://github.com/lz4/lz4) as a git submodule:

```sh
$ git clone [email protected]:cruise-automation/wasm-lz4.git --recursive
```

#### Step 3

Run `npm run build` to invoke emcc and compile the code in `wasm-lz4.c` as well as the required lz4 source files from the lz4 git submodule.

#### Step 4

To run the tests, run `npm install` followed by `npm test`.

To run the tests in Docker, first make sure Docker is installed, and then run `npm run docker:test`.
1. Run `npm install` to install dependencies.
2. Run `npm run build` to invoke emcc inside a Docker container and compile the code in `wasm-lz4.c` as well as the required lz4 source files. The output will be in `dist/` on the host machine.
3. Run `npm test` to run the tests.
8 changes: 5 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#!/usr/bin/env bash

# Copyright (c) 2018-present, Cruise LLC
#
Expand All @@ -10,15 +10,17 @@ emcc \
lz4/lib/lz4.c \
lz4/lib/xxhash.c \
lz4/lib/lz4frame.c \
-o wasm-lz4.js wasm-lz4.c `# this runs emscripten on the code in wasm-lz4.c` \
-o dist/wasm-lz4.js src/wasm-lz4.c `# this runs emscripten on the code in wasm-lz4.c` \
-O3 `# compile with all optimizations enabled` \
-s WASM=1 `# compile to .wasm instead of asm.js` \
--pre-js pre.js `# include pre.js at the top of wasm-lz4.js` \
--post-js post.js `# include post.js at the bottom of wasm-lz4.js` \
-s MODULARIZE=1 `# include module boilerplate for better node/webpack interop` \
-s NO_EXIT_RUNTIME=1 `# keep the process around after main exits` \
-s TOTAL_STACK=1048576 `# use a 1MB stack size instead of the default 5MB` \
-s INITIAL_MEMORY=2097152 `# start with a 2MB allocation instead of 16MB, we will dynamically grow` \
-s ALLOW_MEMORY_GROWTH=1 `# need this because we don't know how large decompressed blocks will be` \
-s NODEJS_CATCH_EXIT=0 `# we don't use exit() and catching exit will catch all exceptions` \
-s NODEJS_CATCH_REJECTION=0 `# prevent emscripten from adding an unhandledRejection handler` \
-s "EXPORTED_FUNCTIONS=['_malloc', '_free']" `# index.js uses Module._malloc and Module._free`

cp src/index.js dist/index.js
10 changes: 10 additions & 0 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $SCRIPT_DIR

docker build . -t wasm-lz4

mkdir -p dist

docker run --rm -v "${SCRIPT_DIR}/dist":/src/dist -t wasm-lz4 ./build.sh
Loading