Skip to content

Commit

Permalink
Update to emscripten 3.1.64
Browse files Browse the repository at this point in the history
 - Patch missing __secs_to_zone, due to emscripten-core/emscripten#21379
 - Better fix for tuklib_integer.cmake usage error in liblzma when compiling with emscripten
 - Fix lzma test failure
  • Loading branch information
HeavenVolkoff committed Aug 1, 2024
1 parent 8c650dd commit e814f49
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
32 changes: 17 additions & 15 deletions wasm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

ARG SYSROOT='/emsdk/upstream/emscripten/cache/sysroot'

# FIX-ME: Can't use emscripten version > 3.1.61, because 3.1.62 introduced a change in https://github.com/emscripten-core/emscripten/pull/21379
# that makes the compilation of libarchive fail with the following error:
# error: undefined symbol: __secs_to_zone (referenced by root reference (e.g. compiled C/C++ code))
FROM docker.io/emscripten/emsdk:3.1.61 as base
FROM docker.io/emscripten/emsdk:3.1.64 as base

SHELL ["/bin/bash", "-euxc"]

# Work around bug in emscripten 3.1.62+, introduced in https://github.com/emscripten-core/emscripten/pull/21379
# that makes the compilation of libarchive fail with the following error:
# error: undefined symbol: __secs_to_zone (referenced by root reference (e.g. compiled C/C++ code))
COPY fix_tz.patch /root/
RUN patch -F5 -lp1 -d / -t </root/fix_tz.patch

RUN apt-get update -y && apt-get install -y pkg-config

# Change emscripten default compilation configs
COPY settings.sh /settings.sh
RUN /settings.sh

ENV FFLAGS="-fasynchronous-unwind-tables -fexceptions"
ENV CFLAGS="-Oz -flto -fwasm-exceptions --minify=0 --closure=0 --no-entry -pipe -Wall -Werror=format-security ${FFLAGS}"
ENV CFLAGS="-r -Oz -flto -fwasm-exceptions --minify=0 --closure=0 --no-entry -pipe -Wall -Werror=format-security ${FFLAGS}"
ENV LDFLAGS="-pipe ${FFLAGS}"
ENV CXXFLAGS="$CFLAGS"

Expand Down Expand Up @@ -45,7 +48,7 @@ RUN emcmake cmake \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=On \
-DENABLE_TESTING=Off \
-DENABLE_PROGRAMS=Off \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc)
RUN emmake make install

Expand All @@ -65,7 +68,7 @@ RUN emcmake cmake \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=On \
-DLZ4_BUILD_CLI=Off \
-DLZ4_BUILD_LEGACY_LZ4C=Off \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc)
RUN emmake make install

Expand All @@ -89,7 +92,7 @@ RUN emcmake cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DBUILD_SHARED_LIBS=Off \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=On \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc)
RUN emmake make install

Expand All @@ -101,9 +104,6 @@ FROM base as lzma
RUN curl -fsSL https://github.com/tukaani-project/xz/releases/download/v5.6.2/xz-5.6.2.tar.xz \
| tar -xJf- -C /src --strip-components 1

# Patch out big endian test, it sometimes fails for no reason and WebASM is always little endian
RUN sed -i -e 's/test_big_endian(WORDS_BIGENDIAN)/set(WORDS_BIGENDIAN OFF)/g' cmake/tuklib_integer.cmake

# Compile & install
WORKDIR /src/build
# Note: DENABLE_THREADS=OFF must be uppercase
Expand All @@ -112,14 +112,16 @@ RUN emcmake cmake \
-DBUILD_SHARED_LIBS=Off \
-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=On \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=On \
-DCMAKE_C_BYTE_ORDER=LITTLE_ENDIAN \
-DCMAKE_CXX_BYTE_ORDER=LITTLE_ENDIAN \
-DHAVE_POSIX_SPAWN=0 -DHAVE_PTHREAD_H=0 -DHAVE_LIBPTHREAD=0 -DPTHREAD_IN_LIBC=0 -DHAVE_POSIX_SPAWNP=0 \
-DWORDS_BIGENDIAN=0 \
-DENABLE_THREADS=OFF \
-DENABLE_SMALL=On \
-DBUILD_TESTING=Off \
-DCREATE_XZ_SYMLINKS=Off \
-DCREATE_LZMA_SYMLINKS=Off \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
# Only build liblzma, because the xz utilities are not compatible with WebASM yet
RUN emmake make -j$(nproc) liblzma
# Work-around make install requiring this files to exist to not fail
Expand All @@ -146,7 +148,7 @@ RUN emcmake cmake \
-DZSTD_BUILD_CONTRIB=Off \
-DZSTD_BUILD_PROGRAMS=Off \
-DZSTD_MULTITHREAD_SUPPORT=Off \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc)
RUN emmake make install

Expand All @@ -171,7 +173,7 @@ RUN emcmake cmake \
-DENABLE_STATIC_LIB=On \
-DENABLE_SHARED_LIB=Off \
-DENABLE_TESTS=Off \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc)
RUN emmake make install

Expand Down Expand Up @@ -237,7 +239,7 @@ RUN emcmake cmake \
-DENABLE_TEST=Off \
-DPOSIX_REGEX_LIB=libc \
-DLIBARCHIVE_STATIC=1 \
..
.. || { cat /src/build/CMakeFiles/CMakeError.log; exit 1; }
RUN emmake make -j$(nproc) 2>&1
RUN emmake make install

Expand Down
2 changes: 1 addition & 1 deletion wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mkdir -p "$_dist"
if [ "$_manager" = 'podman' ]; then
$_manager build --jobs 4 --tag archive-wasm:latest --security-opt label=disable --network host --format docker "$__dir"
else
$_manager build --allow "network.host" --network host --tag archive-wasm:latest --load "$__dir"
$_manager build --network host --tag archive-wasm:latest --load "$__dir"
fi

_id="$($_manager create archive-wasm:latest true)"
Expand Down
42 changes: 42 additions & 0 deletions wasm/fix_tz.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--- /emsdk/upstream/emscripten/system/lib/libc/musl/src/time/__tz.c 2024-07-22 03:41:44.000000000 +0000
+++ /root/__tz.c 2024-08-01 18:13:42.962355411 +0000
@@ -114,11 +114,6 @@

#define VEC(...) ((const unsigned char[]){__VA_ARGS__})

-static uint32_t zi_read32(const unsigned char *z)
-{
- return (unsigned)z[0]<<24 | z[1]<<16 | z[2]<<8 | z[3];
-}
-
static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t n)
{
size_t y;
@@ -131,6 +126,11 @@
}
#endif

+static uint32_t zi_read32(const unsigned char *z)
+{
+ return (unsigned)z[0]<<24 | z[1]<<16 | z[2]<<8 | z[3];
+}
+
static void do_tzset()
{
#ifdef __EMSCRIPTEN__
@@ -280,7 +280,6 @@
#endif
}

-#ifndef __EMSCRIPTEN__
/* Search zoneinfo rules to find the one that applies to the given time,
* and determine alternate opposite-DST-status rule that may be needed. */

@@ -440,7 +439,6 @@
*zonename = __tzname[1];
UNLOCK(lock);
}
-#endif

static void __tzset()
{

0 comments on commit e814f49

Please sign in to comment.