Skip to content

Commit 46a0a82

Browse files
committed
glib-emsdk, wasi sdk fetch
1 parent a0d3dcd commit 46a0a82

File tree

7 files changed

+260
-2
lines changed

7 files changed

+260
-2
lines changed

scripts/emsdk-fetch.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ if \$MVP
193193
then
194194
# -mcpu=generic would activate those https://reviews.llvm.org/D125728
195195
# https://github.com/emscripten-core/emscripten/pull/17689
196-
197-
CPU="-sSUPPORT_LONGJMP=emscripten -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-mutable-globals -m32"
196+
# -fPIC not allowed with -mno-mutable-globals
197+
# -mno-sign-ext not allowed with pthread
198+
CPU="-sSUPPORT_LONGJMP=emscripten -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
198199
else
199200
CPU="-mcpu=bleeding-edge -m32"
200201
fi

sources.wasm/glib.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

wasisdk/bin/wasi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
WASI_CFG="--sysroot=${WASI_SDK_PREFIX}/share/wasi-sysroot -iwithsysroot /include/c++/v1 -I${WASISDK}/hotfix"
4+
WASI_DEF="-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_GETPID"
5+
6+
# wasi assembly
7+
WASI_ALL="${WASI_CFG} ${WASI_DEF} -fPIC -fno-rtti -fno-exceptions"
8+
9+
10+
WASI_ALL="$WASI_ALL -Wno-unused-but-set-variable -Wno-unused-command-line-argument -Wno-unsupported-floating-point-opt"
11+
12+
# wasi linking
13+
WASI_LNK="-lwasi-emulated-getpid -lwasi-emulated-mman -lwasi-emulated-signal -lwasi-emulated-process-clocks"
14+
15+
16+
export CC="${WASI_SDK_PREFIX}/bin/clang ${WASI_ALL}"
17+
export CXX="${WASI_SDK_PREFIX}/bin/clang++ ${WASI_ALL}"
18+
export CPP="${WASI_SDK_PREFIX}/bin/clang-cpp ${WASI_CFG} ${WASI_DEF}"
19+
20+
if echo $0|grep -q c++$
21+
then
22+
if echo "$@"|grep -q shared
23+
then
24+
echo "WASI SHARED: $@"
25+
# unsupported ATM
26+
$CXX $@ ${CXX_LIBS} ${WASI_LNK}
27+
else
28+
$CXX $@ ${CXX_LIBS} ${WASI_LNK}
29+
fi
30+
else
31+
# preprocessor or c compiler
32+
if echo $0|grep -q cpp$
33+
then
34+
$CPP $@
35+
else
36+
$CC $@
37+
fi
38+
fi
39+

wasisdk/bin/wasi-cmake

Whitespace-only changes.

wasisdk/bin/wasi-exec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
shift
3+
shift
4+
FN=$(realpath $1)
5+
shift
6+
#echo "WASI-EXEC : $FN $@"
7+
cd /
8+
export PS1="[PyDK:wasi] \w $ "
9+
#wasm3 $FN $@
10+
wasmtime run --mapdir /::/ $@

wasisdk/bin/wasi-run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
echo "WASI: $@"
3+
WASM=$1
4+
shift
5+
wasmtime run --mapdir /::/ $WASM -- $@

wasisdk/hotfix/dlfcn.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef _DLFCN_H
2+
#define _DLFCN_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <features.h>
9+
10+
#define RTLD_LAZY 1
11+
#define RTLD_NOW 2
12+
#define RTLD_NOLOAD 4
13+
#define RTLD_NODELETE 4096
14+
#define RTLD_GLOBAL 256
15+
#define RTLD_LOCAL 0
16+
17+
#define RTLD_NEXT ((void *)-1)
18+
#define RTLD_DEFAULT ((void *)0)
19+
20+
#define RTLD_DI_LINKMAP 2
21+
22+
int dlclose(void *) {
23+
puts("int dlclose(void)");
24+
return 0;
25+
}
26+
27+
const char *errormsg = "dlerror";
28+
char *dlerror(void) {
29+
return (char *)dlerror;
30+
}
31+
32+
void *dlopen(const char *, int) {
33+
puts("void *dlopen(const char *, int)");
34+
return NULL;
35+
}
36+
37+
void *dlsym(void *__restrict, const char *__restrict) {
38+
puts("void *dlsym(void *__restrict, const char *__restrict)");
39+
return NULL;
40+
}
41+
42+
43+
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
44+
typedef struct {
45+
const char *dli_fname;
46+
void *dli_fbase;
47+
const char *dli_sname;
48+
void *dli_saddr;
49+
} Dl_info;
50+
int dladdr(const void *, Dl_info *);
51+
int dlinfo(void *, int, void *);
52+
#endif
53+
54+
#if _REDIR_TIME64
55+
__REDIR(dlsym, __dlsym_time64);
56+
#endif
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif

0 commit comments

Comments
 (0)