-
Notifications
You must be signed in to change notification settings - Fork 3
Enable dynamic build and .cwasm generation for core libraries (gnulib, libtirpc, openssl, zlib) #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enable dynamic build and .cwasm generation for core libraries (gnulib, libtirpc, openssl, zlib) #185
Changes from 1 commit
9577006
474f8d3
cb3d217
d2013a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ if [[ ! -r "$BASE_SYSROOT/include/wasm32-wasi/stdio.h" ]]; then | |
| echo "ERROR: sysroot headers missing at $BASE_SYSROOT"; exit 1 | ||
| fi | ||
|
|
||
| LIND_DYLINK="${LIND_DYLINK:-0}" | ||
| WASM_OPT="${WASM_OPT:-$LIND_WASM_ROOT/tools/binaryen/bin/wasm-opt}" | ||
|
|
||
| CC_WASI="$LLVM_BIN/clang --target=wasm32-unknown-wasi --sysroot=$BASE_SYSROOT" | ||
| AR="$LLVM_BIN/llvm-ar" | ||
| RANLIB="$LLVM_BIN/llvm-ranlib" | ||
|
|
@@ -40,4 +43,63 @@ cp libz.a "$OVERLAY/usr/lib/wasm32-wasi/libz.a" | |
| cp zlib.h zconf.h "$OVERLAY/usr/include/" | ||
|
|
||
| popd >/dev/null | ||
| echo "[zlib] done → $OVERLAY/usr/lib/wasm32-wasi/libz.a" | ||
|
|
||
| if [[ "$LIND_DYLINK" != "1" ]]; then | ||
| echo "[zlib] done ?~F~R $OVERLAY/usr/lib/wasm32-wasi/libz.a" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. broken unicode arrow?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seem to print properly though. Will recheck.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly fine but might just want to avoid this stuff not sure about portability |
||
| exit 0 | ||
| fi | ||
|
|
||
| mkdir -p "$OVERLAY/lib" | ||
| ADD_EXPORT_TOOL="$LIND_WASM_ROOT/tools/add-export-tool/add-export-tool" | ||
|
|
||
| STATIC_LIB="$OVERLAY/usr/lib/wasm32-wasi/libz.a" | ||
| DYNAMIC_LIB_WASM="$OVERLAY/usr/lib/wasm32-wasi/libz.wasm" | ||
| DYNAMIC_LIB_OPT="$OVERLAY/usr/lib/wasm32-wasi/libz.opt.wasm" | ||
| DYNAMIC_LIB_OPT_CWASM="$OVERLAY/usr/lib/wasm32-wasi/libz.opt.cwasm" | ||
| DYNAMIC_STAGED_LIB="$OVERLAY/lib/libz.so" | ||
| "$LLVM_BIN/clang" \ | ||
| --target=wasm32-unknown-wasi \ | ||
| -fPIC \ | ||
| --sysroot "$BASE_SYSROOT" \ | ||
| -fvisibility=default \ | ||
| -Wl,--import-memory \ | ||
| -Wl,--shared-memory \ | ||
| -Wl,--export-dynamic \ | ||
| -Wl,--experimental-pic \ | ||
| -Wl,--unresolved-symbols=import-dynamic \ | ||
| -Wl,-shared \ | ||
| -Wl,--whole-archive \ | ||
| "$STATIC_LIB" \ | ||
| -Wl,--no-whole-archive \ | ||
| "$LIND_WASM_ROOT/src/glibc/build/lind_debug.o" \ | ||
| -g -O0 -o "$DYNAMIC_LIB_WASM" || { echo "[zlib] ERROR: clang compilation failed"; exit 1; } | ||
|
|
||
| if [[ ! -f "$DYNAMIC_LIB_WASM" ]]; then | ||
| echo "[zlib] ERROR: Failed to generate '$DYNAMIC_LIB_WASM'; Exiting.." | ||
| exit 1 | ||
| fi | ||
|
|
||
| "$ADD_EXPORT_TOOL" "$DYNAMIC_LIB_WASM" "$DYNAMIC_LIB_WASM" __wasm_apply_tls_relocs func __wasm_apply_tls_relocs optional || { echo "[zlib] ERROR: add-export-tool tls failed"; exit 1; } | ||
|
|
||
| "$ADD_EXPORT_TOOL" "$DYNAMIC_LIB_WASM" "$DYNAMIC_LIB_WASM" __wasm_apply_global_relocs func __wasm_apply_global_relocs optional || { echo "[zlib] ERROR: add-export-tool global failed"; exit 1; } | ||
|
|
||
| "$ADD_EXPORT_TOOL" "$DYNAMIC_LIB_WASM" "$DYNAMIC_LIB_WASM" __stack_pointer global __stack_pointer optional || { echo "[zlib] ERROR: add-export-tool stack pointer failed"; exit 1; } | ||
|
|
||
|
|
||
| $WASM_OPT --enable-bulk-memory --enable-threads --epoch-injection --pass-arg=epoch-import --asyncify --pass-arg=asyncify-import-globals -O2 --debuginfo "$DYNAMIC_LIB_WASM" -o "$DYNAMIC_LIB_OPT" || { echo "[zlib] ERROR: wasm-opt failed on '$DYNAMIC_LIB_OPT'; Exiting.."; exit 1; } | ||
|
|
||
| if [[ ! -f "$DYNAMIC_LIB_OPT" ]]; then | ||
| echo "[zlib] ERROR: Failed to generate '$DYNAMIC_LIB_OPT'; Exiting.." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # do precompile | ||
| $LIND_WASM_ROOT/scripts/lind_compile --precompile-only "$DYNAMIC_LIB_OPT"|| { echo "[zlib] ERROR: lind_compile failed on '$DYNAMIC_LIB_OPT_CWASM'; Exiting.."; exit 1; } | ||
|
|
||
| if [[ ! -f "$DYNAMIC_LIB_OPT_CWASM" ]]; then | ||
| echo "[zlib] ERROR: Failed to generate '$DYNAMIC_LIB_OPT_CWASM'; Exiting.." | ||
| exit 1 | ||
| fi | ||
|
|
||
| cp "$DYNAMIC_LIB_OPT_CWASM" "$DYNAMIC_STAGED_LIB" | ||
| echo "[zlib] Dynamic shared library staged as $DYNAMIC_STAGED_LIB" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When LIND_DYLINK=1, it configures with --enable-shared --disable-static but then links the static archive (libgnu.a) into a shared wasm. If configure is building a shared lib, why re-link from the .a? If it's building static to
then convert, the configure flags should stay --enable-static