From 87aacd06191587885e86c95c4e50a5a8bbcb5959 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:13:45 +1000 Subject: [PATCH 1/7] WIP --- docker/Dockerfile | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 13a386fc..a49ad8a9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,39 +1,48 @@ # Builds SWI-Prolog WebAssembly version. # https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650 ARG EMSDK_VERSION -FROM emscripten/emsdk:$EMSDK_VERSION +FROM emscripten/emsdk:$EMSDK_VERSION as swipl-devel -# Installs build dependencies. -RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils +# Clone SWI-Prolog. Only make a shallow clone and only clone the +# submodules we need at depth 1. +ARG SWIPL_VERSION +RUN git clone --depth 1 https://github.com/SWI-Prolog/swipl-devel --branch V$SWIPL_VERSION +RUN cd swipl-devel && git submodule update --init --depth 1 -j 100 \ + packages/chr packages/clib packages/clpqr packages/http packages/nlp \ + packages/pcre packages/plunit packages/sgml packages/RDF \ + packages/semweb packages/zlib +FROM emscripten/emsdk:$EMSDK_VERSION as zlib # Download dependency sources WORKDIR /wasm ARG ZLIB_VERSION -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 - # 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 +FROM emscripten/emsdk:$EMSDK_VERSION as pcre +# Download dependency sources +WORKDIR /wasm +ARG PCRE2_NAME +RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2 +# Build the dependencies and install them in /wasm WORKDIR /wasm/pcre2/build RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \ -DPCRE2GREP_SUPPORT_JIT=OFF \ -G Ninja .. $@ RUN ninja && ninja install -# Clone SWI-Prolog. Only make a shallow clone and only clone the -# submodules we need at depth 1. -WORKDIR / -ARG SWIPL_VERSION -RUN git clone --depth 1 https://github.com/SWI-Prolog/swipl-devel --branch V$SWIPL_VERSION -RUN cd swipl-devel && git submodule update --init --depth 1 -j 100 \ - packages/chr packages/clib packages/clpqr packages/http packages/nlp \ - packages/pcre packages/plunit packages/sgml packages/RDF \ - packages/semweb packages/zlib +FROM emscripten/emsdk:$EMSDK_VERSION + +# Installs build dependencies. +RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils + +COPY --from=swipl-devel /swipl-devel /swipl-devel +COPY --from=zlib /wasm /wasm +COPY --from=pcre /wasm /wasm # Build SWIPL WORKDIR /swipl-devel/build.wasm From 4f34990bde268f38a6daf23db10e8e7a192e9172 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:16:38 +1000 Subject: [PATCH 2/7] WIP --- docker/Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index a49ad8a9..66ed9e6f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -28,12 +28,6 @@ FROM emscripten/emsdk:$EMSDK_VERSION as pcre WORKDIR /wasm ARG PCRE2_NAME RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2 -# Build the dependencies and install them in /wasm -WORKDIR /wasm/pcre2/build -RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \ - -DPCRE2GREP_SUPPORT_JIT=OFF \ - -G Ninja .. $@ -RUN ninja && ninja install FROM emscripten/emsdk:$EMSDK_VERSION @@ -44,6 +38,13 @@ COPY --from=swipl-devel /swipl-devel /swipl-devel COPY --from=zlib /wasm /wasm COPY --from=pcre /wasm /wasm +# Build the pcre dependencies and install them in /wasm +WORKDIR /wasm/pcre2/build +RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \ + -DPCRE2GREP_SUPPORT_JIT=OFF \ + -G Ninja .. $@ +RUN ninja && ninja install + # Build SWIPL WORKDIR /swipl-devel/build.wasm RUN mkdir -p /swipl-devel/build.wasm From aadfda2a17c192fb4f5203568b9929d8be356e4e Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:20:16 +1000 Subject: [PATCH 3/7] WIP --- docker/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 66ed9e6f..97520127 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -34,9 +34,9 @@ FROM emscripten/emsdk:$EMSDK_VERSION # Installs build dependencies. RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils -COPY --from=swipl-devel /swipl-devel /swipl-devel -COPY --from=zlib /wasm /wasm -COPY --from=pcre /wasm /wasm +COPY --from=swipl-devel /swipl-devel ./swipl-devel +COPY --from=zlib /wasm ./wasm +COPY --from=pcre /wasm ./wasm # Build the pcre dependencies and install them in /wasm WORKDIR /wasm/pcre2/build From b48340b52182da449b955b7681d197de4f404ce4 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:47:42 +1000 Subject: [PATCH 4/7] WIP --- docker/Dockerfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 97520127..0e5c1396 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,9 @@ # Builds SWI-Prolog WebAssembly version. # https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650 ARG EMSDK_VERSION -FROM emscripten/emsdk:$EMSDK_VERSION as swipl-devel +FROM emscripten/emsdk:$EMSDK_VERSION as swipl-devel-build + +RUN apt-get update && apt-get install -y git # Clone SWI-Prolog. Only make a shallow clone and only clone the # submodules we need at depth 1. @@ -10,7 +12,8 @@ RUN git clone --depth 1 https://github.com/SWI-Prolog/swipl-devel --branch V$SWI RUN cd swipl-devel && git submodule update --init --depth 1 -j 100 \ packages/chr packages/clib packages/clpqr packages/http packages/nlp \ packages/pcre packages/plunit packages/sgml packages/RDF \ - packages/semweb packages/zlib + packages/semweb packages/zlib && cd .. +WORKDIR / FROM emscripten/emsdk:$EMSDK_VERSION as zlib # Download dependency sources @@ -22,19 +25,21 @@ WORKDIR /wasm/zlib-$ZLIB_VERSION RUN emconfigure ./configure --static --prefix=/wasm RUN EMCC_CFLAGS=-Wno-deprecated-non-prototype emmake make RUN emmake make install +WORKDIR / FROM emscripten/emsdk:$EMSDK_VERSION as pcre # Download dependency sources WORKDIR /wasm ARG PCRE2_NAME RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2 +WORKDIR / FROM emscripten/emsdk:$EMSDK_VERSION # Installs build dependencies. RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils -COPY --from=swipl-devel /swipl-devel ./swipl-devel +COPY --from=swipl-devel-build /swipl-devel ./swipl-devel COPY --from=zlib /wasm ./wasm COPY --from=pcre /wasm ./wasm From f4acbda331a139484def51b95af156ef82842666 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 12:23:32 +1000 Subject: [PATCH 5/7] WIP --- docker/Dockerfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0e5c1396..f7734ed8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,19 +3,18 @@ ARG EMSDK_VERSION FROM emscripten/emsdk:$EMSDK_VERSION as swipl-devel-build -RUN apt-get update && apt-get install -y git - # Clone SWI-Prolog. Only make a shallow clone and only clone the # submodules we need at depth 1. +WORKDIR / ARG SWIPL_VERSION RUN git clone --depth 1 https://github.com/SWI-Prolog/swipl-devel --branch V$SWIPL_VERSION RUN cd swipl-devel && git submodule update --init --depth 1 -j 100 \ packages/chr packages/clib packages/clpqr packages/http packages/nlp \ packages/pcre packages/plunit packages/sgml packages/RDF \ - packages/semweb packages/zlib && cd .. -WORKDIR / + packages/semweb packages/zlib FROM emscripten/emsdk:$EMSDK_VERSION as zlib + # Download dependency sources WORKDIR /wasm ARG ZLIB_VERSION @@ -25,23 +24,22 @@ WORKDIR /wasm/zlib-$ZLIB_VERSION RUN emconfigure ./configure --static --prefix=/wasm RUN EMCC_CFLAGS=-Wno-deprecated-non-prototype emmake make RUN emmake make install -WORKDIR / FROM emscripten/emsdk:$EMSDK_VERSION as pcre # Download dependency sources WORKDIR /wasm ARG PCRE2_NAME RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2 -WORKDIR / FROM emscripten/emsdk:$EMSDK_VERSION # Installs build dependencies. -RUN apt-get update && apt-get install -y bzip2 lzip ninja-build xz-utils +RUN apt-get update +RUN apt-get install -y ninja-build -COPY --from=swipl-devel-build /swipl-devel ./swipl-devel -COPY --from=zlib /wasm ./wasm -COPY --from=pcre /wasm ./wasm +COPY --from=swipl-devel-build /swipl-devel /swipl-devel +COPY --from=zlib /wasm /wasm +COPY --from=pcre /wasm /wasm # Build the pcre dependencies and install them in /wasm WORKDIR /wasm/pcre2/build From e736f6aa889473cd40e71d8bf28bb82f79c738ee Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 12:29:41 +1000 Subject: [PATCH 6/7] chore: parralelize ninja and zlib build --- docker/Dockerfile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f7734ed8..0fcf46fc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,12 @@ # Builds SWI-Prolog WebAssembly version. # https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650 ARG EMSDK_VERSION + +FROM emscripten/emsdk:$EMSDK_VERSION AS ninja +# Installs build dependencies. +RUN apt-get update +RUN apt-get install -y ninja-build + FROM emscripten/emsdk:$EMSDK_VERSION as swipl-devel-build # Clone SWI-Prolog. Only make a shallow clone and only clone the @@ -25,13 +31,24 @@ RUN emconfigure ./configure --static --prefix=/wasm RUN EMCC_CFLAGS=-Wno-deprecated-non-prototype emmake make RUN emmake make install -FROM emscripten/emsdk:$EMSDK_VERSION as pcre +FROM emscripten/emsdk:$EMSDK_VERSION as pcre-clone # Download dependency sources WORKDIR /wasm ARG PCRE2_NAME RUN git clone --branch=$PCRE2_NAME --depth 1 https://github.com/PCRE2Project/pcre2 -FROM emscripten/emsdk:$EMSDK_VERSION +FROM ninja as pcre + +COPY --from=pcre-clone /wasm /wasm +# Build the pcre dependencies and install them in /wasm +WORKDIR /wasm/pcre2/build +RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \ + -DPCRE2GREP_SUPPORT_JIT=OFF \ + -G Ninja .. $@ +RUN ninja +RUN ninja install + +FROM ninja # Installs build dependencies. RUN apt-get update From ee8950effd0d0492db49129a2b965b573224bb7c Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 6 Aug 2023 12:34:24 +1000 Subject: [PATCH 7/7] chore: remove repeat build step --- docker/Dockerfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0fcf46fc..291a817b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -58,13 +58,6 @@ COPY --from=swipl-devel-build /swipl-devel /swipl-devel COPY --from=zlib /wasm /wasm COPY --from=pcre /wasm /wasm -# Build the pcre dependencies and install them in /wasm -WORKDIR /wasm/pcre2/build -RUN emcmake cmake -DCMAKE_INSTALL_PREFIX=/wasm \ - -DPCRE2GREP_SUPPORT_JIT=OFF \ - -G Ninja .. $@ -RUN ninja && ninja install - # Build SWIPL WORKDIR /swipl-devel/build.wasm RUN mkdir -p /swipl-devel/build.wasm