git clone https://gist.github.com/acfa1c09522705efa5eb0541d2d00887.git glib-emscripten
cd glib-emscripten
docker build -t glib-emscripten .
docker run -it --rm -v $(pwd):/src glib-emscripten
-
-
Save kleisauke/acfa1c09522705efa5eb0541d2d00887 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" | |
export CXXFLAGS="$CFLAGS" | |
export LDFLAGS="-L$TARGET/lib -O3" | |
[ "$WASM_BIGINT" = "true" ] || export LDFLAGS+=" -sWASM_BIGINT=0" | |
# 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_ARGS="--cross-file=$SOURCE_DIR/emscripten-cross.ini" | |
# Run as many parallel jobs as there are available CPU cores | |
export MAKEFLAGS="-j$(nproc)" | |
# Ensure we link against internal/private dependencies | |
export PKG_CONFIG="pkg-config --static" | |
# Dependency version numbers | |
VERSION_ZLIB=1.3.1 | |
VERSION_FFI=3.4.7 | |
VERSION_GLIB=2.84.0 | |
# Remove patch version component | |
without_patch() { | |
echo "${1%.[[:digit:]]*}" | |
} | |
mkdir $DEPS/zlib | |
curl -Ls https://github.com/madler/zlib/releases/download/v$VERSION_ZLIB/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 | |
[ "$WASM_BIGINT" = "true" ] || curl -Ls https://github.com/libffi/libffi/compare/v$VERSION_FFI...kleisauke:disable-wasm-bigint.patch | patch -p1 | |
# 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 | |
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 | |
# Propagate -pthread into CFLAGS to ensure GObject/GIO is compiled with the atomics/bulk-memory features | |
CFLAGS="$CFLAGS -pthread" meson setup _build --prefix=$TARGET $MESON_ARGS --default-library=static --buildtype=release \ | |
--force-fallback-for=pcre2,gvdb -Dintrospection=disabled -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dsysprof=disabled -Dnls=disabled \ | |
-Dglib_debug=disabled -Dtests=false -Dglib_assert=false -Dglib_checks=false | |
meson install -C _build --tag devel |
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 docker.io/emscripten/emsdk:4.0.4 | |
RUN apt-get update \ | |
&& apt-get install -qqy \ | |
build-essential \ | |
libglib2.0-dev \ | |
pkgconf \ | |
# needed for Meson | |
ninja-build \ | |
python3-pip \ | |
# needed by GLib | |
python3-packaging \ | |
&& pip3 install meson | |
CMD ["./build.sh"] |
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++' | |
ar = 'emar' | |
ranlib = 'emranlib' | |
pkg-config = ['pkg-config', '--static'] | |
exe_wrapper = 'node' | |
[properties] | |
needs_exe_wrapper = true | |
# Ensure that `-sPTHREAD_POOL_SIZE=4` 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' |
Thanks for the script, it's very useful for making https://github.com/DSchroer/openscad-wasm possible!
No problem, I'm glad it's useful.
Could you please update... zlib
1.2.13
is not available anymore, current version is now1.3
(could be downloaded viahttps
too).
The latest revision of this gist should fix this.
Thank you so much for this @kleisauke! With this I was able to update glib on emscripten-forge (emscripten-forge/recipes#1164)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script, it's very useful for making https://github.com/DSchroer/openscad-wasm possible!
Could you please update... zlib
1.2.13
is not available anymore, current version is now1.3
(could be downloaded viahttps
too).