|
| 1 | +# syntax = docker/dockerfile:1.5 |
| 2 | + |
| 3 | +ARG EMSDK_VERSION_QEMU=3.1.50 |
| 4 | +ARG ZLIB_VERSION=1.3.1 |
| 5 | +ARG GLIB_MINOR_VERSION=2.84 |
| 6 | +ARG GLIB_VERSION=${GLIB_MINOR_VERSION}.0 |
| 7 | +ARG PIXMAN_VERSION=0.44.2 |
| 8 | +ARG FFI_VERSION=v3.4.7 |
| 9 | +ARG MESON_VERSION=1.5.0 |
| 10 | + |
| 11 | +FROM emscripten/emsdk:$EMSDK_VERSION_QEMU AS build-base |
| 12 | +ARG MESON_VERSION |
| 13 | +ENV TARGET=/builddeps/target |
| 14 | +ENV CPATH="$TARGET/include" |
| 15 | +ENV PKG_CONFIG_PATH="$TARGET/lib/pkgconfig" |
| 16 | +ENV EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" |
| 17 | +ENV CFLAGS="-O3 -pthread -DWASM_BIGINT" |
| 18 | +ENV CXXFLAGS="$CFLAGS" |
| 19 | +ENV LDFLAGS="-sWASM_BIGINT -sASYNCIFY=1 -L$TARGET/lib" |
| 20 | +RUN apt-get update && apt-get install -y \ |
| 21 | + autoconf \ |
| 22 | + build-essential \ |
| 23 | + libglib2.0-dev \ |
| 24 | + libtool \ |
| 25 | + pkgconf \ |
| 26 | + ninja-build \ |
| 27 | + python3-pip |
| 28 | +RUN pip3 install meson==${MESON_VERSION} tomli |
| 29 | +RUN mkdir /build |
| 30 | +WORKDIR /build |
| 31 | +RUN mkdir -p $TARGET |
| 32 | +RUN <<EOF |
| 33 | +cat <<EOT > /cross.meson |
| 34 | +[host_machine] |
| 35 | +system = 'emscripten' |
| 36 | +cpu_family = 'wasm32' |
| 37 | +cpu = 'wasm32' |
| 38 | +endian = 'little' |
| 39 | + |
| 40 | +[binaries] |
| 41 | +c = 'emcc' |
| 42 | +cpp = 'em++' |
| 43 | +ar = 'emar' |
| 44 | +ranlib = 'emranlib' |
| 45 | +pkgconfig = ['pkg-config', '--static'] |
| 46 | +EOT |
| 47 | +EOF |
| 48 | + |
| 49 | +FROM build-base AS zlib-dev |
| 50 | +ARG ZLIB_VERSION |
| 51 | +RUN mkdir -p /zlib |
| 52 | +RUN curl -Ls https://zlib.net/zlib-$ZLIB_VERSION.tar.xz | \ |
| 53 | + tar xJC /zlib --strip-components=1 |
| 54 | +WORKDIR /zlib |
| 55 | +RUN emconfigure ./configure --prefix=$TARGET --static |
| 56 | +RUN emmake make install -j$(nproc) |
| 57 | + |
| 58 | +FROM build-base AS libffi-dev |
| 59 | +ARG FFI_VERSION |
| 60 | +RUN mkdir -p /libffi |
| 61 | +RUN git clone https://github.com/libffi/libffi /libffi |
| 62 | +WORKDIR /libffi |
| 63 | +RUN git checkout $FFI_VERSION |
| 64 | +RUN autoreconf -fiv |
| 65 | +RUN emconfigure ./configure --host=wasm32-unknown-linux \ |
| 66 | + --prefix=$TARGET --enable-static \ |
| 67 | + --disable-shared --disable-dependency-tracking \ |
| 68 | + --disable-builddir --disable-multi-os-directory \ |
| 69 | + --disable-raw-api --disable-docs |
| 70 | +RUN emmake make install SUBDIRS='include' -j$(nproc) |
| 71 | + |
| 72 | +FROM build-base AS pixman-dev |
| 73 | +ARG PIXMAN_VERSION |
| 74 | +RUN mkdir /pixman/ |
| 75 | +RUN git clone https://gitlab.freedesktop.org/pixman/pixman /pixman/ |
| 76 | +WORKDIR /pixman |
| 77 | +RUN git checkout pixman-$PIXMAN_VERSION |
| 78 | +RUN <<EOF |
| 79 | +cat <<EOT >> /cross.meson |
| 80 | +[built-in options] |
| 81 | +c_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 82 | +cpp_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 83 | +objc_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 84 | +c_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')] |
| 85 | +cpp_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')] |
| 86 | +EOT |
| 87 | +EOF |
| 88 | +RUN meson setup _build --prefix=$TARGET --cross-file=/cross.meson \ |
| 89 | + --default-library=static \ |
| 90 | + --buildtype=release -Dtests=disabled -Ddemos=disabled |
| 91 | +RUN meson install -C _build |
| 92 | + |
| 93 | +FROM build-base AS glib-dev |
| 94 | +ARG GLIB_VERSION |
| 95 | +ARG GLIB_MINOR_VERSION |
| 96 | +RUN mkdir -p /stub |
| 97 | +WORKDIR /stub |
| 98 | +RUN <<EOF |
| 99 | +cat <<'EOT' > res_query.c |
| 100 | +#include <netdb.h> |
| 101 | +int res_query(const char *name, int class, |
| 102 | + int type, unsigned char *dest, int len) |
| 103 | +{ |
| 104 | + h_errno = HOST_NOT_FOUND; |
| 105 | + return -1; |
| 106 | +} |
| 107 | +EOT |
| 108 | +EOF |
| 109 | +RUN emcc ${CFLAGS} -c res_query.c -fPIC -o libresolv.o |
| 110 | +RUN ar rcs libresolv.a libresolv.o |
| 111 | +RUN mkdir -p $TARGET/lib/ |
| 112 | +RUN cp libresolv.a $TARGET/lib/ |
| 113 | + |
| 114 | +RUN mkdir -p /glib |
| 115 | +RUN curl -Lks https://download.gnome.org/sources/glib/${GLIB_MINOR_VERSION}/glib-$GLIB_VERSION.tar.xz | \ |
| 116 | + tar xJC /glib --strip-components=1 |
| 117 | + |
| 118 | +COPY --link --from=zlib-dev /builddeps/ /builddeps/ |
| 119 | +COPY --link --from=libffi-dev /builddeps/ /builddeps/ |
| 120 | + |
| 121 | +WORKDIR /glib |
| 122 | +RUN <<EOF |
| 123 | +CFLAGS="$CFLAGS -Wno-incompatible-function-pointer-types" ; |
| 124 | +cat <<EOT >> /cross.meson |
| 125 | +[built-in options] |
| 126 | +c_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 127 | +cpp_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 128 | +objc_args = [$(printf "'%s', " $CFLAGS | sed 's/, $//')] |
| 129 | +c_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')] |
| 130 | +cpp_link_args = [$(printf "'%s', " $LDFLAGS | sed 's/, $//')] |
| 131 | +EOT |
| 132 | +EOF |
| 133 | +RUN meson setup _build --prefix=$TARGET --cross-file=/cross.meson \ |
| 134 | + --default-library=static --buildtype=release --force-fallback-for=pcre2 \ |
| 135 | + -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \ |
| 136 | + -Dtests=false -Dglib_debug=disabled -Dglib_assert=false -Dglib_checks=false |
| 137 | +# FIXME: emscripten doesn't provide some pthread functions in the final link, |
| 138 | +# which isn't detected during meson setup. |
| 139 | +RUN sed -i -E "/#define HAVE_POSIX_SPAWN 1/d" ./_build/config.h |
| 140 | +RUN sed -i -E "/#define HAVE_PTHREAD_GETNAME_NP 1/d" ./_build/config.h |
| 141 | +RUN meson install -C _build |
| 142 | + |
| 143 | +FROM build-base |
| 144 | +COPY --link --from=glib-dev /builddeps/ /builddeps/ |
| 145 | +COPY --link --from=pixman-dev /builddeps/ /builddeps/ |
0 commit comments