# syntax=docker/dockerfile:1 # # libxslt (with libexslt) and libxml2 compiled to WebAssembly for johnmcm.com's # /infopath-viewer, which draws InfoPath views with XSLT. Its own engine, so # views look the same in every browser and keep working once Chrome removes # its built-in XSLTProcessor. # # Reproducible: the Emscripten image is pinned by version and digest, and both # source tarballs by version and SHA-256, downloaded from GNOME's release # server. Both libraries are built unmodified. # # ./build.ps1 (or) docker build --target export --output type=local,dest=dist . # # Licences: libxslt, libexslt and libxml2 are MIT (LICENSE-libxslt.txt, # LICENSE-libxml2.txt). These build files are published at /source/xslt/. ARG EMSDK_IMAGE=emscripten/emsdk:6.0.10@sha256:e077d54e2b8970575ebc4f185ac1de0b95c05f2b266134d4ba27449af7aebf65 FROM ${EMSDK_IMAGE} AS deps ARG LIBXML2_VERSION=2.15.4 ARG LIBXML2_SHA256=98087fd181d9070724f3fbc65c7377db03038eb92bd882374daff44940138821 ARG LIBXSLT_VERSION=1.1.45 ARG LIBXSLT_SHA256=9acfe68419c4d06a45c550321b3212762d92f41465062ca4ea19e632ee5d216e ENV PREFIX=/opt/xslt # libxml2's configure insists on the pkg-config program. RUN apt-get update && apt-get install -y --no-install-recommends pkg-config=1.8.1-2build1 && rm -rf /var/lib/apt/lists/* WORKDIR /src RUN curl -fsSL -o libxml2.tar.xz https://download.gnome.org/sources/libxml2/2.15/libxml2-${LIBXML2_VERSION}.tar.xz \ && echo "${LIBXML2_SHA256} libxml2.tar.xz" | sha256sum -c - \ && curl -fsSL -o libxslt.tar.xz https://download.gnome.org/sources/libxslt/1.1/libxslt-${LIBXSLT_VERSION}.tar.xz \ && echo "${LIBXSLT_SHA256} libxslt.tar.xz" | sha256sum -c - \ && tar xJf libxml2.tar.xz && tar xJf libxslt.tar.xz # libxml2: the parser, tree, XPath and the XML and HTML writers libxslt needs. # No network code (removed upstream in 2.15), no threads, compression, iconv, # ICU, catalogs, XInclude or schema languages. UTF-8, UTF-16 and the # ISO-8859 family are decoded by libxml2 itself. WORKDIR /src/libxml2-${LIBXML2_VERSION} RUN emconfigure ./configure --prefix=${PREFIX} --disable-shared --enable-static \ --without-python --without-threads --without-thread-alloc \ --without-zlib --without-iconv --without-icu --without-modules \ --without-debug --without-catalog --without-xinclude --without-schemas \ --without-relaxng --without-schematron --without-c14n --without-reader \ --without-writer --without-history --without-readline \ CFLAGS="-Oz" \ && emmake make -j"$(nproc)" libxml2.la \ && emmake make install-libLTLIBRARIES install-pkgconfigDATA install-binSCRIPTS \ && emmake make -C include install # libxslt and libexslt: no Python, crypto (EXSLT random/crypto), debugger, # profiler or plugins (loadable extension modules). WORKDIR /src/libxslt-${LIBXSLT_VERSION} RUN emconfigure ./configure --prefix=${PREFIX} --disable-shared --enable-static \ --with-libxml-prefix=${PREFIX} \ --without-python --without-crypto --without-debugger --without-profiler \ --without-plugins --without-debug \ CFLAGS="-Oz" \ && emmake make -j"$(nproc)" -C libxslt \ && emmake make -j"$(nproc)" -C libexslt \ && emmake make -C libxslt install && emmake make -C libexslt install FROM deps AS wasm WORKDIR /binding COPY src/ ./ RUN mkdir -p /out \ && emcc -Oz -I${PREFIX}/include -I${PREFIX}/include/libxml2 xslt.c \ ${PREFIX}/lib/libexslt.a ${PREFIX}/lib/libxslt.a ${PREFIX}/lib/libxml2.a -lm \ -o /out/xslt.mjs \ -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=createXslt \ -sENVIRONMENT=web,worker,node \ -sALLOW_MEMORY_GROWTH=1 \ -sINITIAL_MEMORY=16777216 \ -sMAXIMUM_MEMORY=536870912 \ -sSTACK_SIZE=8388608 \ -sFILESYSTEM=0 \ -sDYNAMIC_EXECUTION=0 \ -sINCOMING_MODULE_JS_API=print,printErr,locateFile \ -sEXPORTED_FUNCTIONS=_malloc,_free,_xt_transform,_xt_result,_xt_result_len,_xt_error,_xt_release,_xt_add_file,_xt_clear_files,_xt_set_match_names,_xt_missing \ -sEXPORTED_RUNTIME_METHODS=HEAPU8 FROM scratch AS export COPY --from=wasm /out/ /