Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix browser version #89

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
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
59 changes: 0 additions & 59 deletions .circleci/config.yml

This file was deleted.

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

jobs:
Test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
node_version:
- 10
- 12
- 14
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Cache
uses: actions/cache@v2
with:
path: |
'node_modules'
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json') }}

- name: Setup node
uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node_version }}
node-arch: ${{ matrix.node_arch }}

- name: Install dependencies
run: npm install

- name: Lint
run: npm run standard

- name: Run tests
run: |
npm run test:node
npm run test:native

- name: Install emscripten
shell: bash
run: script/install-emscripten.sh

- name: Build WASM version
run: npm run build:browser

- name: Test WASM version
run: npm run test:browser

Skip:
if: contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-latest
steps:
- name: Skip CI 🚫
run: echo skip ci
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ build
.clang_complete

/browser.js
emsdk-portable
emsdk-*
package-lock.json

*.wasm
*.o
*.a
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

25 changes: 2 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
image: Visual Studio 2015

environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "12.14.1"

platform:
- x86
- x64

install:
- ps: Install-Product node $env:nodejs_version
- git submodule update --init
- node --version
- npm --version
- npm install

test_script:
- npm run standard
- npm run test:node

# empty appveyor
build: off

branches:
only:
- master
- non-existing
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"browser": "./browser",
"scripts": {
"build:node": "node-gyp rebuild",
"build:browser": "script/build-browser-version.sh",
"build:browser": "bash -c ./script/build-browser-version.sh",
"build": "npm run build:node && npm run build:browser",
"test:native": "script/test-native.js",
"test:native": "node ./script/test-native.js",
"test:node": "mocha test/js/*.js",
"test:browser": "SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
"test:browser": "cross-env SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
"test": "npm run test:node && npm run test:browser",
"benchmark": "node benchmark/marker-index.benchmark.js",
"prepublishOnly": "npm run build:browser",
Expand All @@ -35,6 +35,7 @@
},
"devDependencies": {
"chai": "^2.0.0",
"cross-env": "^7.0.3",
"mocha": "^2.3.4",
"random-seed": "^0.2.0",
"standard": "^4.5.4",
Expand Down
24 changes: 19 additions & 5 deletions script/build-browser-version.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/usr/bin/env bash

source emsdk-portable/emsdk_env.sh
# Activate emscripten
EMSDK_PATH="./emsdk-2.0.9/emsdk"
$EMSDK_PATH activate 2.0.9

# Build

mkdir -p build

## Compile pcre

emcc \
-o build/pcre.o \
-O3 \
-I vendor/pcre/10.23/src \
-I vendor/pcre/include \
-D HAVE_CONFIG_H \
-D PCRE2_CODE_UNIT_WIDTH=16 \
-c \
vendor/pcre/pcre2_chartables.c \
vendor/pcre/10.23/src/pcre2_auto_possess.c \
vendor/pcre/10.23/src/pcre2_compile.c \
Expand All @@ -36,6 +42,14 @@ emcc \
vendor/pcre/10.23/src/pcre2_valid_utf.c \
vendor/pcre/10.23/src/pcre2_xclass.c

mv ./*.o build/

emar \
rcs build/pcre.a \
build/*.o

### Compile superstring

em++ \
--bind \
-o browser.js \
Expand All @@ -44,13 +58,13 @@ em++ \
-I src/core \
-I vendor/libcxx \
-I vendor/pcre/include \
-D HAVE_CONFIG_H \
-D PCRE2_CODE_UNIT_WIDTH=16 \
-xc++ \
-s TOTAL_MEMORY=134217728 \
--pre-js src/bindings/em/prologue.js \
--post-js src/bindings/em/epilogue.js \
src/core/*.cc \
src/bindings/em/*.cc \
build/pcre.o \
-s TOTAL_MEMORY=134217728 \
build/pcre.a \
--memory-init-file 0 \
"$@"
13 changes: 4 additions & 9 deletions script/install-emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

EMSCRIPTEN_DOWNLOAD_URL='https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz'
EMSDK_PATH="./emsdk-portable/emsdk"
EMSCRIPTEN_DOWNLOAD_URL='https://codeload.github.com/emscripten-core/emsdk/tar.gz/2.0.9'
EMSDK_PATH="./emsdk-2.0.9/emsdk"

if [ ! -f $EMSDK_PATH ]; then
echo 'Downloading emscripten SDK installer...'
Expand All @@ -12,11 +12,6 @@ fi

echo 'Installing emscripten SDK...'

# Workaround https://github.com/juj/emsdk/pull/74
sed -i{} "s_/kripken/emscripten/'_/kripken/emscripten'_" $EMSDK_PATH
sed -i{} "s_/WebAssembly/binaryen/'_/WebAssembly/binaryen'_" $EMSDK_PATH

$EMSDK_PATH update
$EMSDK_PATH list
$EMSDK_PATH install sdk-1.37.9-64bit
$EMSDK_PATH activate sdk-1.37.9-64bit
$EMSDK_PATH install 2.0.9
$EMSDK_PATH activate 2.0.9 --permanent
3 changes: 2 additions & 1 deletion src/bindings/em/patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "patch.h"
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <emscripten/wire.h>

using std::runtime_error;
using std::string;
Expand Down Expand Up @@ -83,7 +84,7 @@ void change_set_noop(Patch::Change &change, T const &) {}
EMSCRIPTEN_BINDINGS(Patch) {
emscripten::class_<Patch>("Patch")
.constructor<>()
.constructor<emscripten::val>(WRAP_STATIC(&constructor), emscripten::allow_raw_pointers())
.constructor(WRAP_STATIC(&constructor), emscripten::allow_raw_pointers())
Copy link
Contributor Author

@aminya aminya Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is related to emscripten-core/emscripten#11274.

Currently, the template parameters seem to be deduced from the given constructor

.function("splice", splice)
.function("splice", splice_with_text)
.function("spliceOld", WRAP(&Patch::splice_old))
Expand Down