|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# https://github.com/kleisauke/glib |
| 4 | + |
| 5 | + |
| 6 | +. ${CONFIG:-config} |
| 7 | + |
| 8 | +. scripts/emsdk-fetch.sh |
| 9 | + |
| 10 | +if pushd ${ROOT}/src |
| 11 | +then |
| 12 | + |
| 13 | + SOURCE_DIR=$PWD |
| 14 | + |
| 15 | + # Working directories |
| 16 | + DEPS=$SOURCE_DIR |
| 17 | + |
| 18 | + # Define default arguments |
| 19 | + |
| 20 | + # JS BigInt to Wasm i64 integration, enabled by default |
| 21 | + WASM_BIGINT=true |
| 22 | + |
| 23 | + # Parse arguments |
| 24 | + while [ $# -gt 0 ]; do |
| 25 | + case $1 in |
| 26 | + --disable-wasm-bigint) WASM_BIGINT=false ;; |
| 27 | + *) echo "ERROR: Unknown parameter: $1" >&2; exit 1 ;; |
| 28 | + esac |
| 29 | + shift |
| 30 | + done |
| 31 | + |
| 32 | + # Configure the ENABLE_* and DISABLE_* expansion helpers |
| 33 | + for arg in WASM_BIGINT; do |
| 34 | + if [ "${!arg}" = "true" ]; then |
| 35 | + declare ENABLE_$arg=true |
| 36 | + else |
| 37 | + declare DISABLE_$arg=true |
| 38 | + fi |
| 39 | + done |
| 40 | + |
| 41 | + # Common compiler flags |
| 42 | + export CFLAGS="-O3" |
| 43 | + export CXXFLAGS="$CFLAGS" |
| 44 | + export LDFLAGS="-L$PREFIX/lib" |
| 45 | + |
| 46 | + |
| 47 | + # Build paths |
| 48 | + export CPATH="$PREFIX/include" |
| 49 | + export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" |
| 50 | + export EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" |
| 51 | + |
| 52 | + # Specific variables for cross-compilation |
| 53 | + export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten |
| 54 | + export MESON_CROSS="$SOURCE_DIR/emscripten-crossfile.meson" |
| 55 | + |
| 56 | + # Run as many parallel jobs as there are available CPU cores |
| 57 | + export MAKEFLAGS="-j$(nproc)" |
| 58 | + |
| 59 | + # Ensure we link against internal/private dependencies |
| 60 | + export PKG_CONFIG="pkg-config --static" |
| 61 | + |
| 62 | + # Dependency version numbers |
| 63 | + VERSION_ZLIB=1.3 |
| 64 | + VERSION_FFI=3.4.4 |
| 65 | + VERSION_GLIB=2.78.0 |
| 66 | + |
| 67 | + # Remove patch version component |
| 68 | + without_patch() { |
| 69 | + echo "${1%.[[:digit:]]*}" |
| 70 | + } |
| 71 | + |
| 72 | + #mkdir $DEPS/zlib |
| 73 | + #curl -Ls https://github.com/madler/zlib/releases/download/v$VERSION_ZLIB/zlib-$VERSION_ZLIB.tar.xz | tar xJC $DEPS/zlib --strip-components=1 |
| 74 | + #cd $DEPS/zlib |
| 75 | + #emconfigure ./configure --prefix=$PREFIX --static |
| 76 | + #make install |
| 77 | + |
| 78 | + #mkdir $DEPS/ffi |
| 79 | + #curl -Ls https://github.com/libffi/libffi/releases/download/v$VERSION_FFI/libffi-$VERSION_FFI.tar.gz | tar xzC $DEPS/ffi --strip-components=1 |
| 80 | + #cd $DEPS/ffi |
| 81 | + ## TODO(kleisauke): Wait for upstream release with PR https://github.com/libffi/libffi/pull/763 included |
| 82 | + #curl -Ls https://github.com/libffi/libffi/compare/v$VERSION_FFI...kleisauke:wasm-vips${ENABLE_WASM_BIGINT:+-bigint}.patch | patch -p1 |
| 83 | + #autoreconf -fiv |
| 84 | + ## Compile without -fexceptions |
| 85 | + #sed -i 's/ -fexceptions//g' configure |
| 86 | + #emconfigure ./configure --host=$CHOST --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking \ |
| 87 | + # --disable-builddir --disable-multi-os-directory --disable-raw-api --disable-structs --disable-docs |
| 88 | + #make install SUBDIRS='include' |
| 89 | + |
| 90 | + if [ -d glib ] |
| 91 | + then |
| 92 | + pushd glib |
| 93 | + else |
| 94 | + mkdir glib |
| 95 | + curl -Lks https://download.gnome.org/sources/glib/$(without_patch $VERSION_GLIB)/glib-$VERSION_GLIB.tar.xz | tar xJC $DEPS/glib --strip-components=1 |
| 96 | + pushd glib |
| 97 | + |
| 98 | + echo " |
| 99 | +
|
| 100 | +TODO(kleisauke): Discuss these patches upstream https://github.com/GNOME/glib/compare/$VERSION_GLIB...kleisauke:wasm-vips-$VERSION_GLIB.patch |
| 101 | +
|
| 102 | +" |
| 103 | + |
| 104 | + curl -Ls https://github.com/GNOME/glib/compare/$VERSION_GLIB...kleisauke:wasm-vips-$VERSION_GLIB.patch | patch -p1 |
| 105 | + fi |
| 106 | + |
| 107 | + |
| 108 | + cat <<END > emscripten-crossfile.meson |
| 109 | +[binaries] |
| 110 | +c = 'emcc' |
| 111 | +cpp = 'em++' |
| 112 | +ar = 'emar' |
| 113 | +ranlib = 'emranlib' |
| 114 | +pkgconfig = ['pkg-config', '--static'] |
| 115 | +# https://docs.gtk.org/glib/cross-compiling.html#cross-properties |
| 116 | +[properties] |
| 117 | +growing_stack = true |
| 118 | +have_c99_vsnprintf = true |
| 119 | +have_c99_snprintf = true |
| 120 | +have_unix98_printf = true |
| 121 | +
|
| 122 | +# Ensure that -s PTHREAD_POOL_SIZE=* is not injected into .pc files |
| 123 | +[built-in options] |
| 124 | +c_thread_count = 0 |
| 125 | +cpp_thread_count = 0 |
| 126 | +
|
| 127 | +[host_machine] |
| 128 | +system = 'emscripten' |
| 129 | +cpu_family = 'wasm32' |
| 130 | +cpu = 'wasm32' |
| 131 | +endian = 'little' |
| 132 | +END |
| 133 | + |
| 134 | + meson setup _build --prefix=$PREFIX --cross-file=emscripten-crossfile.meson --default-library=static --buildtype=release \ |
| 135 | + --force-fallback-for=pcre2,gvdb -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \ |
| 136 | + -Dtests=false -Dglib_assert=false -Dglib_checks=false |
| 137 | + meson install -C _build --tag devel |
| 138 | + popd # glib |
| 139 | + popd # src |
| 140 | + |
| 141 | +fi |
0 commit comments