Skip to content

Commit 01932ea

Browse files
committed
chore: Add opus and vpx to the toxcore wasm build.
1 parent d29c42e commit 01932ea

File tree

6 files changed

+162
-89
lines changed

6 files changed

+162
-89
lines changed

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
- name: Build and push
113113
uses: docker/build-push-action@v5
114114
with:
115-
file: other/emscripten/Dockerfile
115+
file: other/docker/wasm/wasm.Dockerfile
116116
push: ${{ github.event_name == 'push' }}
117117
tags: toxchat/c-toxcore:wasm
118118
cache-from: type=registry,ref=toxchat/c-toxcore:wasm

other/docker/wasm/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"

other/docker/wasm/wasm.Dockerfile

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
FROM ubuntu:20.04
2+
3+
ENV DEBIAN_FRONTEND="noninteractive"
4+
5+
# Install dependencies.
6+
RUN apt-get update && apt-get install --no-install-recommends -y \
7+
autoconf \
8+
automake \
9+
ca-certificates \
10+
cmake \
11+
curl \
12+
git \
13+
libtool \
14+
make \
15+
ninja-build \
16+
pkg-config \
17+
python3 \
18+
unzip \
19+
wget \
20+
xz-utils \
21+
&& apt-get clean \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
WORKDIR /work/emsdk
25+
RUN git clone --depth=1 https://github.com/emscripten-core/emsdk /work/emsdk \
26+
&& ./emsdk install 4.0.1 \
27+
&& ./emsdk activate 4.0.1
28+
29+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
30+
WORKDIR /work
31+
32+
# Build libsodium.
33+
RUN . "/work/emsdk/emsdk_env.sh" \
34+
&& tar zxf <(curl -L https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz) \
35+
&& cd /work/libsodium-* \
36+
&& emconfigure ./configure \
37+
--prefix=/wasm \
38+
--enable-static \
39+
--disable-shared \
40+
--without-pthreads \
41+
--disable-ssp \
42+
--disable-asm \
43+
--disable-pie \
44+
&& emmake make -j"$(nproc)" \
45+
&& emmake make install \
46+
&& rm -rf /work/libsodium-*
47+
48+
# Build libvpx.
49+
RUN . "/work/emsdk/emsdk_env.sh" \
50+
&& tar zxf <(curl -L https://github.com/webmproject/libvpx/archive/v1.15.0.tar.gz) \
51+
&& cd /work/libvpx-* \
52+
&& emconfigure ./configure \
53+
--prefix=/wasm \
54+
--enable-static \
55+
--disable-shared \
56+
--target=generic-gnu \
57+
--disable-examples \
58+
--disable-tools \
59+
--disable-docs \
60+
--disable-unit-tests \
61+
--enable-pic \
62+
&& emmake make -j"$(nproc)" \
63+
&& emmake make install \
64+
&& rm -rf /work/libvpx-*
65+
66+
# Build opus.
67+
RUN . "/work/emsdk/emsdk_env.sh" \
68+
&& tar zxf <(curl -L https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz) \
69+
&& cd /work/opus-* \
70+
&& emconfigure ./configure \
71+
--prefix=/wasm \
72+
--enable-static \
73+
--disable-shared \
74+
--host wasm32-unknown-emscripten \
75+
--disable-extra-programs \
76+
--disable-doc \
77+
CFLAGS="-O3 -flto -fPIC" \
78+
&& emmake make -j"$(nproc)" \
79+
&& emmake make install \
80+
&& rm -rf /work/opus-*
81+
82+
# Build an unused binding without toxcore first so emcc caches all the system
83+
# libraries. This makes rebuilds of toxcore below much faster.
84+
RUN . "/work/emsdk/emsdk_env.sh" \
85+
&& mkdir -p /wasm/bin \
86+
&& emcc -O3 -flto \
87+
-s ALLOW_UNIMPLEMENTED_SYSCALLS=1 \
88+
-s EXPORT_NAME=libtoxcore \
89+
-s IGNORE_MISSING_MAIN=1 \
90+
-s MAIN_MODULE=1 \
91+
-s MALLOC=emmalloc \
92+
-s MODULARIZE=1 \
93+
-s STRICT=1 \
94+
-s WEBSOCKET_URL=ws:// \
95+
/wasm/lib/libopus.a \
96+
/wasm/lib/libsodium.a \
97+
/wasm/lib/libvpx.a \
98+
-o /wasm/bin/libtoxcore.js
99+
100+
ENV PKG_CONFIG_PATH="/wasm/lib/pkgconfig"
101+
102+
# Build c-toxcore.
103+
COPY . /work/c-toxcore
104+
RUN . "/work/emsdk/emsdk_env.sh" \
105+
&& cd /work/c-toxcore \
106+
&& emcmake cmake \
107+
-B_build \
108+
-GNinja \
109+
-DCMAKE_INSTALL_PREFIX="/wasm" \
110+
-DCMAKE_C_FLAGS="-O3 -flto -fPIC" \
111+
-DMUST_BUILD_TOXAV=ON \
112+
-DENABLE_SHARED=OFF \
113+
-DBOOTSTRAP_DAEMON=OFF \
114+
-DMIN_LOGGER_LEVEL=TRACE \
115+
. \
116+
&& emmake cmake --build _build \
117+
&& emmake cmake --install _build
118+
119+
# Link together all the libraries.
120+
RUN . "/work/emsdk/emsdk_env.sh" \
121+
&& mkdir -p /wasm/bin \
122+
&& emcc -O3 -flto \
123+
-s ALLOW_UNIMPLEMENTED_SYSCALLS=1 \
124+
-s EXPORT_NAME=libtoxcore \
125+
-s IGNORE_MISSING_MAIN=1 \
126+
-s MAIN_MODULE=1 \
127+
-s MALLOC=emmalloc \
128+
-s MODULARIZE=1 \
129+
-s STRICT=1 \
130+
-s WEBSOCKET_URL=ws:// \
131+
/wasm/lib/libopus.a \
132+
/wasm/lib/libsodium.a \
133+
/wasm/lib/libvpx.a \
134+
/wasm/lib/libtoxcore.a \
135+
-o /wasm/bin/libtoxcore.js
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ===== common =====
2+
# Ignore everything ...
3+
**/*
4+
# ... except sources
5+
!**/*.[ch]
6+
!**/*.cc
7+
!**/*.hh
8+
!CHANGELOG.md
9+
!LICENSE
10+
!README.md
11+
!auto_tests/data/*
12+
!other/bootstrap_daemon/bash-completion/**
13+
!other/bootstrap_daemon/tox-bootstrapd.*
14+
!other/proxy/*.mod
15+
!other/proxy/*.sum
16+
!other/proxy/*.go
17+
# ... and CMake build files (used by most builds).
18+
!**/CMakeLists.txt
19+
!.github/scripts/flags*.sh
20+
!cmake/*.cmake
21+
!other/pkgconfig/*
22+
!other/rpm/*
23+
!so.version

other/emscripten/Dockerfile

Lines changed: 0 additions & 85 deletions
This file was deleted.

other/emscripten/build

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)