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

Feat/ctest passing #143

Closed
wants to merge 12 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
dependency: ['swipl', 'emsdk', 'zlib', 'gmp']
dependency: ['swipl', 'emsdk', 'zlib', 'pcre2']

steps:
- uses: actions/checkout@v3
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ The package can be built using npm or yarn. Please use yarn to
add new dependencies and update yarn.lock file. SWI-Prolog WebAssembly
version is currently built inside Docker with Emscripten.

### Development

To develop with this package, clone the repository and run:

```
# Install dependencies
npm ci

# Build the Webassembly
npm run build

# Run tests
npm t
```

*Note* You need Docker and Node 16 or higher to installed build the package.

## Versioning

The package uses its own versioning scheme using semver. It is
Expand Down
50 changes: 31 additions & 19 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,48 @@ FROM emscripten/emsdk:$EMSDK_VERSION
# Installs build dependencies.
RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils

# Downloads and builds ZLIB.
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt install -y nodejs
RUN sed -i 's/NODE_JS .*/NODE_JS = "\/usr\/bin\/node"/' /emsdk/.emscripten

# Download dependency sources
WORKDIR /wasm
ARG ZLIB_VERSION
RUN wget --no-verbose -qO- https://zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xvz --directory /
ARG PCRE2_NAME
RUN wget --no-verbose -qO- https://zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xvz
RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2

WORKDIR /zlib-$ZLIB_VERSION
RUN emconfigure ./configure
# Build the dependencies and install them in /wasm
WORKDIR /wasm/zlib-$ZLIB_VERSION
RUN emconfigure ./configure --static --prefix=/wasm
RUN EMCC_CFLAGS=-Wno-deprecated-non-prototype emmake make
RUN emmake make install

# Downloads and builds GMP.
ARG GMP_VERSION
RUN wget --no-verbose -qO- https://gmplib.org/download/gmp/gmp-$GMP_VERSION.tar.lz | tar x --lzip --directory /

WORKDIR /gmp-$GMP_VERSION
RUN mkdir /gmp
RUN emconfigure ./configure --host=none --disable-assembly --prefix=/gmp
RUN make
RUN make install
WORKDIR /wasm/pcre2/build
RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \
-DPCRE2GREP_SUPPORT_JIT=OFF \
-G Ninja .. $@
RUN ninja && ninja install

# Clones SWI-Prolog.
ARG SWIPL_VERSION
RUN git clone --depth 1 --branch V$SWIPL_VERSION --recurse-submodules https://github.com/SWI-Prolog/swipl-devel /swipl-devel -j100
# Clone SWI-Prolog. Only make a shallow clone and only clone the
# submodules we need at depth 1.
WORKDIR /
RUN git clone --depth 1 https://github.com/SWI-Prolog/swipl-devel
RUN cd swipl-devel && git submodule update --init --depth 1 \
packages/chr packages/clib packages/clpqr packages/http packages/nlp \
packages/pcre packages/plunit packages/sgml packages/RDF \
packages/semweb packages/zlib

# Build SWIPL
WORKDIR /swipl-devel/build.wasm
RUN mkdir -p /swipl-devel/build.wasm
RUN cmake -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DZLIB_LIBRARY=/zlib-$ZLIB_VERSION/libz.a \
-DZLIB_INCLUDE_DIR=/zlib-$ZLIB_VERSION \
-DGMP_ROOT=/gmp \
-DCMAKE_FIND_ROOT_PATH=/wasm \
-DUSE_GMP=OFF \
-DINSTALL_DOCUMENTATION=OFF \
-DNODE_JS_EXECUTABLE=/usr/bin/node \
-G Ninja ..
RUN ninja

RUN ctest -j $(nproc) --output-on-failure
81 changes: 58 additions & 23 deletions examples/generation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dist/**/*.wasm"
],
"scripts": {
"build:wasm-docker:build": "docker build --build-arg SWIPL_VERSION=$npm_package_config_swipl_version --build-arg EMSDK_VERSION=$npm_package_config_emsdk_version --build-arg ZLIB_VERSION=$npm_package_config_zlib_version --build-arg GMP_VERSION=$npm_package_config_gmp_version -t swipl-wasm-image docker",
"build:wasm-docker:build": "docker build --build-arg SWIPL_VERSION=$npm_package_config_swipl_version --build-arg EMSDK_VERSION=$npm_package_config_emsdk_version --build-arg ZLIB_VERSION=$npm_package_config_zlib_version --build-arg PCRE2_NAME=$npm_package_config_pcre2_name -t swipl-wasm-image docker",
"build:wasm-docker:create": "docker create --name swipl-wasm swipl-wasm-image",
"build:wasm-docker:remove": "docker rm swipl-wasm",
"build:wasm-docker:extract:data": "docker cp swipl-wasm:/swipl-devel/build.wasm/src/swipl-web.data dist/swipl/swipl-web.data",
Expand All @@ -68,7 +68,7 @@
"lint:tests": "eslint tests --ext .js",
"lint": "run-s lint:types lint:tests",
"update:dep:emsdk": "ts-node scripts/get-latest-emsdk",
"update:dep:gmp": "ts-node scripts/get-latest-gmp",
"update:dep:pcre2": "ts-node scripts/get-latest-pcre2",
"update:dep:swipl": "ts-node scripts/get-latest-swipl",
"update:dep:zlib": "ts-node scripts/get-latest-zlib",
"update:dep": "run-s update:dep:*",
Expand All @@ -84,13 +84,17 @@
"commit": "20b7ede92a13cd37430673bae1c0fcbc9cfcaf9d"
},
"emsdk": {
"version": "3.1.34"
"version": "3.1.38",
"commit": "0329dbaa2593dcb6604caf38893f276b06cc04ef",
"name": "3.1.38"
},
"zlib": {
"version": "1.2.13"
},
"gmp": {
"version": "6.2.1"
"pcre2": {
"version": "10.42.0",
"commit": "52c08847921a324c804cabf2814549f50bce1265",
"name": "pcre2-10.42"
}
},
"bin": {
Expand Down
25 changes: 0 additions & 25 deletions scripts/get-latest-gmp.ts

This file was deleted.

9 changes: 9 additions & 0 deletions scripts/get-latest-pcre2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { updateTag } from './util';

updateTag({
owner: 'PCRE2Project',
repo: 'pcre2',
// Since pcre2 only does major.minor we add .0 to make it the semver we like
getVersion: (tag) => /^pcre2\-\d+.\d+$/.test(tag.name) ? tag.name.slice(6) + '.0' : undefined,
entry: 'pcre2',
});
4 changes: 2 additions & 2 deletions scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export interface IUpdateTagOptions {
export async function updateTag(options: IUpdateTagOptions) {
const data = await getAllTags(options);

let bestElem: { version: string; commit: string } | undefined;
let bestElem: { version: string; commit: string; name?: string } | undefined;
for (const elem of data) {
const version = options.getVersion(elem);
if (version && (!bestElem || isHigherVersion(version, bestElem.version))) {
bestElem = { version, commit: elem.commit.sha }
bestElem = { version, commit: elem.commit.sha, name: elem.name };
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ describe("SWI-Prolog WebAssembly on Node.js", () => {
const atom = swipl.prolog.query("X = atom").once().X;
assert.strictEqual(atom, "atom");
});

it(`[${name}] ` + "should do regex operations enabled by pcre2", async () => {
const swipl = await SWIPL({ arguments: ["-q"], ...addedParams });
assert.strictEqual(swipl.prolog.query("use_module(library(pcre)).").once().success, true);
assert.strictEqual(swipl.prolog.query("re_match(\"^needle\"/i, \"Needle in a haystack\").").once().success, true);
});
}
});