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