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