git clone https://gist.github.com/acfa1c09522705efa5eb0541d2d00887.git glib-emscripten
cd glib-emscripten
docker build -t glib-emscripten .
docker run --platform linux/amd64 --rm -v $(pwd):/src glib-emscripten ./build.sh
-
-
Save bferguson3/7beed9bf087df55691b8afe94a7eb9eb to your computer and use it in GitHub Desktop.
Build script for https://github.com/emscripten-core/emscripten/issues/11066.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
SOURCE_DIR=$PWD | |
# Working directories | |
DEPS=$SOURCE_DIR/deps | |
TARGET=$SOURCE_DIR/target | |
rm -rf $DEPS/ | |
mkdir $DEPS | |
mkdir -p $TARGET | |
# Define default arguments | |
# JS BigInt to Wasm i64 integration, enabled by default | |
WASM_BIGINT=true | |
# Parse arguments | |
while [ $# -gt 0 ]; do | |
case $1 in | |
--disable-wasm-bigint) WASM_BIGINT=false ;; | |
*) echo "ERROR: Unknown parameter: $1" >&2; exit 1 ;; | |
esac | |
shift | |
done | |
# Common compiler flags | |
export CFLAGS="-O3 -pthread -fPIC" | |
if [ "$WASM_BIGINT" = "true" ]; then | |
# libffi needs to detect WASM_BIGINT support at compile time | |
export CFLAGS+=" -DWASM_BIGINT" | |
fi | |
export CXXFLAGS="$CFLAGS" | |
export LDFLAGS="-L$TARGET/lib -O3" | |
if [ "$WASM_BIGINT" = "true" ]; then export LDFLAGS+=" -sWASM_BIGINT"; fi | |
# Build paths | |
export CPATH="$TARGET/include" | |
export PKG_CONFIG_PATH="$TARGET/lib/pkgconfig" | |
export EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" | |
# Specific variables for cross-compilation | |
export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten | |
export MESON_CROSS="$SOURCE_DIR/emscripten-crossfile.meson" | |
# Run as many parallel jobs as there are available CPU cores | |
export MAKEFLAGS="-j$(nproc)" | |
# Dependency version numbers | |
VERSION_ZLIB=1.2.13 | |
VERSION_FFI=3.4.4 | |
VERSION_GLIB=2.75.0 | |
# Remove patch version component | |
without_patch() { | |
echo "${1%.[[:digit:]]*}" | |
} | |
mkdir $DEPS/zlib | |
curl -Ls http://zlib.net/zlib-$VERSION_ZLIB.tar.xz | tar xJC $DEPS/zlib --strip-components=1 | |
cd $DEPS/zlib | |
emconfigure ./configure --prefix=$TARGET --static | |
make install | |
mkdir $DEPS/ffi | |
curl -Ls https://github.com/libffi/libffi/releases/download/v$VERSION_FFI/libffi-$VERSION_FFI.tar.gz | tar xzC $DEPS/ffi --strip-components=1 | |
cd $DEPS/ffi | |
# TODO(kleisauke): https://github.com/hoodmane/libffi-emscripten/issues/16 | |
curl -Ls https://github.com/libffi/libffi/compare/v$VERSION_FFI...kleisauke:wasm-vips.patch | patch -p1 | |
autoreconf -fiv | |
# Compile without -fexceptions | |
sed -i 's/ -fexceptions//g' configure | |
emconfigure ./configure --host=$CHOST --prefix=$TARGET --enable-static --disable-shared --disable-dependency-tracking \ | |
--disable-builddir --disable-multi-os-directory --disable-raw-api --disable-structs --disable-docs | |
make install SUBDIRS='include' | |
mkdir $DEPS/glib | |
curl -Lks https://download.gnome.org/sources/glib/$(without_patch $VERSION_GLIB)/glib-$VERSION_GLIB.tar.xz | tar xJC $DEPS/glib --strip-components=1 | |
cd $DEPS/glib | |
# TODO(kleisauke): Discuss these patches upstream | |
curl -Ls https://github.com/GNOME/glib/compare/$VERSION_GLIB...kleisauke:wasm-vips-$VERSION_GLIB.patch | patch -p1 | |
meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ | |
--force-fallback-for=pcre2,gvdb -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \ | |
-Dtests=false -Dglib_assert=false -Dglib_checks=false | |
meson install -C _build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/emscripten-core/emsdk | |
FROM emscripten/emsdk:3.1.25 | |
RUN apt-get update \ | |
&& apt-get install -qqy \ | |
autoconf \ | |
build-essential \ | |
libglib2.0-dev \ | |
libtool \ | |
pkgconf \ | |
# needed for Meson | |
ninja-build \ | |
python3-pip \ | |
# https://github.com/mesonbuild/meson/pull/10969 | |
&& pip3 install git+https://github.com/kleisauke/meson@wasm-vips |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[binaries] | |
c = 'emcc' | |
cpp = 'em++' | |
ld = 'wasm-ld' | |
ar = 'emar' | |
ranlib = 'emranlib' | |
pkgconfig = ['emconfigure', 'pkg-config'] | |
# https://docs.gtk.org/glib/cross-compiling.html#cross-properties | |
[properties] | |
growing_stack = true | |
have_c99_vsnprintf = true | |
have_c99_snprintf = true | |
have_unix98_printf = true | |
# Ensure that `-s PTHREAD_POOL_SIZE=*` is not injected into .pc files | |
[built-in options] | |
c_thread_count = 0 | |
cpp_thread_count = 0 | |
[host_machine] | |
system = 'emscripten' | |
cpu_family = 'wasm32' | |
cpu = 'wasm32' | |
endian = 'little' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment