[vlc-commits] [Git][videolan/vlc][master] 9 commits: wasm-emscripten: Create a target for emscripten in configure.ac

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sun Sep 12 10:31:44 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
6d5ecc87 by Etienne Brateau at 2021-09-12T09:37:27+00:00
wasm-emscripten: Create a target for emscripten in configure.ac

- - - - -
bc1213d4 by Etienne Brateau at 2021-09-12T09:37:27+00:00
contrib: set wasm-emscripten toolchain variables

- add meson_system_name for emscripten
- add CMAKE_SYSTEM_NAME
- add EMSCRIPTEN to toolchain.cmake to workaround the fact that it is not a valid
CMAKE variable.

- - - - -
9eb9a79a by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
contrib: openjpeg: add support for wasm-emscripten

- - - - -
6c81460d by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
contrib: ffmpeg: add support for wasm-emscripten

- - - - -
e4e4124b by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
contrib: libvpx: add support for wasm-emscripten

- - - - -
832400ac by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
core: add initial support for emscripten

posix/sort.c won't be added because qsort_r is not supported.

- add vlc_getProxyUrl stub for emscripten

- implement vlc_thread_id() for emscripten

- add weak attribute support for wasm

Co-Authored-By: Jean-Baptiste Kempf <jb at videolan.org>

- - - - -
77551ed8 by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
vlc_fixups.h: add missing header for clock_nanosleep

- - - - -
d47a0f27 by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
package: add wasm-emscriten build script

Co-Authored-By: Jean-Baptiste Kempf <jb at videolan.org>
Co-Authored-By: Etienne Brateau <etienne.brateau at gmail.com>

- - - - -
9ace5912 by Mehdi Sabwat at 2021-09-12T09:37:27+00:00
ci : add wasm32-emscripten job

- - - - -


15 changed files:

- configure.ac
- contrib/bootstrap
- + contrib/src/ffmpeg/0001-ffmpeg-add-target_os-support-for-emscripten.patch
- contrib/src/ffmpeg/rules.mak
- contrib/src/main.mak
- + contrib/src/openjpeg/emscripten.patch
- contrib/src/openjpeg/rules.mak
- contrib/src/vpx/rules.mak
- extras/ci/gitlab-ci.yml
- + extras/package/wasm-emscripten/build.sh
- include/vlc_common.h
- include/vlc_fixups.h
- src/Makefile.am
- + src/emscripten/netconf.c
- + src/emscripten/thread.c


Changes:

=====================================
configure.ac
=====================================
@@ -378,6 +378,12 @@ case "${host_os}" in
     AC_LIBOBJ([recvmsg])
     AC_LIBOBJ([sendmsg])
     ;;
+  *emscripten*)
+    SYS=emscripten
+    # tdestroy() is a GNU extension
+    CFLAGS="${CFLAGS} -pthread -D_GNU_SOURCE"
+    CXXFLAGS="${CXXFLAGS} -pthread"
+    ;;
   *)
     SYS="${host_os}"
     ;;
@@ -451,6 +457,8 @@ AS_IF([test x$with_pic = xyes], [X86ASMDEFS="${X86ASMDEFS} -DPIC"])
 AC_SUBST([X86ASMFLAGS])
 AC_SUBST([X86ASMDEFS])
 
+AM_CONDITIONAL([HAVE_EMSCRIPTEN], [test "${SYS}" = "emscripten"])
+
 dnl
 dnl Sadly autoconf does not think about testing foo.exe when ask to test
 dnl for program foo on win32


=====================================
contrib/bootstrap
=====================================
@@ -358,6 +358,9 @@ case "${OS}" in
 	*nacl*)
 		add_make_enabled "HAVE_NACL"
 		;;
+	*emscripten*)
+	       add_make_enabled "HAVE_EMSCRIPTEN"
+	       ;;
 esac
 
 #


=====================================
contrib/src/ffmpeg/0001-ffmpeg-add-target_os-support-for-emscripten.patch
=====================================
@@ -0,0 +1,25 @@
+From 4bb53ad8e35f899f14e6d6144e60d8caa5c0651c Mon Sep 17 00:00:00 2001
+From: Mehdi Sabwat <mehdi at videolabs.io>
+Date: Mon, 6 Sep 2021 11:49:03 +0200
+Subject: [PATCH 1/1] ffmpeg: add target_os support for emscripten
+
+---
+ configure | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/configure b/configure
+index d7a3f50..57ca005 100755
+--- a/configure
++++ b/configure
+@@ -5579,6 +5579,8 @@ case $target_os in
+         ;;
+     minix)
+         ;;
++    emscripten)
++	;;
+     none)
+         ;;
+     *)
+-- 
+2.33.0
+


=====================================
contrib/src/ffmpeg/rules.mak
=====================================
@@ -215,6 +215,10 @@ ifdef HAVE_NACL
 FFMPEGCONF+=--disable-inline-asm --disable-asm --target-os=linux
 endif
 
+ifdef HAVE_EMSCRIPTEN
+FFMPEGCONF+= --arch=wasm32 --target-os=emscripten
+endif
+
 # Build
 PKGS += ffmpeg
 ifeq ($(call need_pkg,"libavcodec >= $(FFMPEG_LAVC_MIN) libavformat >= 53.21.0 libswscale"),)
@@ -247,6 +251,7 @@ endif
 ifdef USE_LIBAV
 	$(APPLY) $(SRC)/ffmpeg/libav_gsm.patch
 endif
+	$(APPLY) $(SRC)/ffmpeg/0001-ffmpeg-add-target_os-support-for-emscripten.patch
 	$(MOVE)
 
 .ffmpeg: ffmpeg


=====================================
contrib/src/main.mak
=====================================
@@ -565,6 +565,9 @@ endif
 ifdef HAVE_DARWIN_OS
 CMAKE_SYSTEM_NAME = Darwin
 endif
+ifdef HAVE_EMSCRIPTEN
+CMAKE_SYSTEM_NAME = Emscripten
+endif
 
 ifdef HAVE_ANDROID
 CFLAGS += -DANDROID_NATIVE_API_LEVEL=$(ANDROID_API)
@@ -620,6 +623,10 @@ ifdef HAVE_CROSS_COMPILE
 	echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
 	echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
 endif
+ifdef HAVE_EMSCRIPTEN
+	# https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake#L268
+	echo "set(EMSCRIPTEN 1)" >> $@
+endif
 
 MESON_SYSTEM_NAME =
 ifdef HAVE_WIN32
@@ -634,12 +641,16 @@ else
 ifdef HAVE_LINUX
 	# android has also system = linux and defines HAVE_LINUX
 	MESON_SYSTEM_NAME = linux
+else
+ifdef HAVE_EMSCRIPTEN
+	MESON_SYSTEM_NAME = emscripten
 else
 	$(error "No meson system name known for this target")
 endif
 endif
 endif
 endif
+endif
 
 crossfile.meson: $(SRC)/gen-meson-crossfile.py
 	$(HOSTVARS_MESON) \


=====================================
contrib/src/openjpeg/emscripten.patch
=====================================
@@ -0,0 +1,29 @@
+From c4c22e82c1fb1d722509e5005cb3ee4b3600b919 Mon Sep 17 00:00:00 2001
+From: Mehdi Sabwat <mehdisabwat at gmail.com>
+Date: Mon, 26 Apr 2021 15:37:44 +0200
+Subject: [PATCH 1/1] emscripten: disable big endian test
+
+This test should not run on the emscripten platform because of :
+https://github.com/emscripten-core/emscripten/blob/dff33368427fba16745c8ce52f11484a67b2855d/cmake/Modules/TestBigEndian.cmake#L5
+---
+ CMakeLists.txt | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 299f74c3..d343905b 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -162,8 +162,10 @@ endif()
+ 
+ #-----------------------------------------------------------------------------
+ # Big endian test:
++if (NOT EMSCRIPTEN)
+ include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
+ TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
++endif()
+ 
+ #-----------------------------------------------------------------------------
+ # Setup file for setting custom ctest vars
+-- 
+2.31.1
+


=====================================
contrib/src/openjpeg/rules.mak
=====================================
@@ -22,6 +22,7 @@ endif
 	$(APPLY) $(SRC)/openjpeg/install.patch
 	$(APPLY) $(SRC)/openjpeg/pic.patch
 	$(APPLY) $(SRC)/openjpeg/openjp2_pthread.patch
+	$(APPLY) $(SRC)/openjpeg/emscripten.patch
 	$(call pkg_static,"./src/lib/openjp2/libopenjp2.pc.cmake.in")
 	$(MOVE)
 


=====================================
contrib/src/vpx/rules.mak
=====================================
@@ -151,6 +151,10 @@ else
 VPX_CONF += --disable-optimizations
 endif
 
+ifdef HAVE_EMSCRIPTEN
+VPX_CONF += --extra-cflags="$(CFLAGS) -pthread"
+endif
+
 # Always enable debug symbols, we strip in the final executables if needed
 VPX_CONF += --enable-debug
 


=====================================
extras/ci/gitlab-ci.yml
=====================================
@@ -20,6 +20,7 @@ variables:
     VLC_ANDROID_IMAGE: registry.videolan.org/vlc-debian-android:20210730131708
     VLC_SNAP_IMAGE: registry.videolan.org/vlc-ubuntu-focal:20210611174203
     VLC_RASPBIAN_IMAGE: registry.videolan.org/vlc-debian-raspbian:20200213203125
+    VLC_WASM_EMSCRIPTEN: registry.videolan.org/vlc-debian-wasm-emscripten:20210601090557
 
 .variables-debian: &variables-debian
         HOST_ARCH: x86_64
@@ -102,6 +103,11 @@ variables:
         ANDROID_ARCH: x86_64
         TRIPLET: x86_64-linux-android
 
+.variables-emscripten-wasm32: &variables-emscripten-wasm32
+        HOST_ARCH: wasm32
+        TRIPLET: $HOST_ARCH-unknown-emscripten
+        EMSDK_VERSION: 2.0.23
+
 # Common rules
 .base-template:
     stage: build
@@ -457,6 +463,24 @@ android-x86_64:
     extends: .android-common
     variables: *variables-android-x86_64
 
+#
+# Webassembly
+#
+
+wasm32-emscripten-build :
+    extends: .docker-template
+    variables: *variables-emscripten-wasm32
+    image:
+        name: $VLC_WASM_EMSCRIPTEN
+    script:
+        - source $EMSCRIPTEN_SDK/emsdk_env.sh
+        - |
+            if [ -n "$VLC_PREBUILT_CONTRIBS_URL" ]; then
+                ./extras/package/wasm-emscripten/build.sh --with-prebuilt-contribs
+            else
+                ./extras/package/wasm-emscripten/build.sh --gen-contrib-archive
+            fi
+
 #
 # VLC Documentation
 #


=====================================
extras/package/wasm-emscripten/build.sh
=====================================
@@ -0,0 +1,198 @@
+#! /bin/sh
+# Copyright (C) 2003-2021 the VideoLAN team
+#
+# This file is under the same license as the vlc package.
+
+set -e
+
+diagnostic()
+{
+    echo "### build logs ###: " "$@" 1>&2;
+}
+
+usage()
+{
+    echo "Usage: $0 [--mode=(default=1)]"
+    echo "  --with-prebuilt-contribs | -c"
+    echo "  --mode=1 build all "
+    echo "  --mode=0 incremental build (do not bootstrap and configure) "  
+}
+
+NM="$EMSDK/upstream/bin/llvm-nm"
+get_symbol()
+{
+    echo "$1" | grep vlc_entry_"$2" | cut -d " " -f 3
+}
+
+get_entryname()
+{
+    symbols=$($NM -g "$1")
+    entryname=$(get_symbol "$symbols" _)
+    echo "$entryname"
+}
+
+while test -n "$1"
+do
+    case "$1" in
+        --help|-h)
+            usage
+            exit 0
+            ;;
+        --mode=*)
+            BUILD_MODE="${1#--mode=}"
+            ;;
+	--with-prebuilt-contribs)
+	    VLC_USE_PREBUILT_CONTRIBS=1
+	    ;;
+	--gen-contrib-archive|-c)
+	    GENERATE_ARCHIVE=1
+	    ;;
+        *)
+            echo "Unrecognized options $1"
+            usage
+            exit 1
+            ;;
+    esac
+    shift
+done
+
+BUILD_MODE=${BUILD_MODE:=1}
+VLC_PREBUILT_CONTRIBS_URL=${VLC_PREBUILT_CONTRIBS_URL:-""}
+BUILDDIR_NAME="build-emscripten"
+GENERATE_ARCHIVE=${GENERATE_ARCHIVE:=0}
+VLC_USE_PREBUILT_CONTRIBS=${VLC_USE_PREBUILT_CONTRIBS:=0}
+
+diagnostic "setting MAKEFLAGS"
+if [ -z "$MAKEFLAGS" ]; then
+    UNAMES=$(uname -s)
+    MAKEFLAGS=
+    if which nproc >/dev/null; then
+        MAKEFLAGS=-j$(nproc)
+    elif [ "$UNAMES" = "Darwin" ] && which sysctl >/dev/null; then
+        MAKEFLAGS=-j$(sysctl -n machdep.cpu.thread_count)
+    fi
+    export MAKEFLAGS;
+fi
+
+diagnostic "setting up dir paths"
+
+OLD_PWD=$(pwd)
+VLC_SRCPATH="$(dirname "$0")/../../../"
+cd "$VLC_SRCPATH"
+VLC_SRCPATH=$(pwd)
+cd "$OLD_PWD"
+
+diagnostic "vlc sources path: "
+echo "$VLC_SRCPATH";
+
+diagnostic "vlc tools: bootstrap"
+cd "$VLC_SRCPATH"/extras/tools
+./bootstrap 
+
+diagnostic "vlc tools: make"
+make
+
+# update the PATH
+export PATH=$VLC_SRCPATH/extras/tools/bin:$PATH
+
+diagnostic "sdk tests: checking if autoconf supports emscripten"
+# https://code.videolan.org/-/snippets/1283
+for file in /usr/share/automake-*
+do
+    # This will pick the latest automake version
+    AUTOMAKE_VERSION="$(echo "$file" | cut -d- -f2)"
+done
+
+diagnostic "using automake version: /usr/share/automake-$AUTOMAKE_VERSION"
+if [ -f /usr/share/automake-"$AUTOMAKE_VERSION"/config.sub ]; then
+    /usr/share/automake-"$AUTOMAKE_VERSION"/config.sub wasm32-unknown-emscripten
+fi
+
+mkdir -p "$VLC_SRCPATH"/contrib/contrib-emscripten
+cd "$VLC_SRCPATH"/contrib/contrib-emscripten
+
+diagnostic "vlc contribs: bootstrap"
+../bootstrap --disable-disc --disable-sout --disable-net \
+	     --disable-postproc --disable-gmp --disable-gcrypt --disable-ass \
+	     --disable-gpgerror --disable-harfbuzz --disable-fontconfig \
+	     --disable-asdcplib --disable-caca --disable-gettext \
+             --disable-goom --disable-libplacebo \
+             --disable-lua --disable-luac --disable-sqlite \
+             --disable-medialibrary --disable-mpcdec --disable-schroedinger \
+             --disable-orc --disable-protobuf --disable-sidplay2 \
+             --disable-soxr --disable-spatialaudio --disable-speex \
+             --disable-speexdsp --disable-taglib --disable-zvbi \
+             --disable-rnnoise \
+             --host=wasm32-unknown-emscripten
+
+diagnostic "vlc contribs: make"
+if [ "$VLC_USE_PREBUILT_CONTRIBS" -eq "0" ]; then
+    emmake make
+    if [ "$GENERATE_ARCHIVE" -eq "1" ]; then
+	diagnostic "vlc contribs: generating package"
+	emmake make package
+    fi
+else
+    diagnostic "vlc contribs: using prebuilt contribs"
+    emmake make prebuilt PREBUILT_URL="$VLC_PREBUILT_CONTRIBS_URL"
+fi
+
+diagnostic "starting libvlc build"
+BUILD_PATH=$VLC_SRCPATH/$BUILDDIR_NAME
+mkdir -p "$BUILD_PATH"
+
+diagnostic "vlc build dir: "
+echo "$BUILD_PATH";
+
+cd "$BUILD_PATH"
+if [ $BUILD_MODE -eq 1 ]; then
+    diagnostic "libvlc build: bootstrap"
+    ../bootstrap
+
+    diagnostic "libvlc build: configure"
+    # if_nameindex is not supported in emscripten
+    # ie: not exposed from musl to src/library.js
+    # the test in configure.ac fails because htons is not
+    # in tools/deps_info.py
+
+    # shm.h is a blacklisted module
+    emconfigure "$VLC_SRCPATH"/configure --host=wasm32-unknown-emscripten --enable-debug \
+                        --disable-shared --disable-vlc \
+                        --disable-sout --disable-vlm --disable-xcb --disable-lua \
+                        --disable-addonmanagermodules --disable-ssp \
+                        ac_cv_func_if_nameindex=yes ac_cv_header_sys_shm_h=no \
+                        --with-contrib="$VLC_SRCPATH"/contrib/wasm32-unknown-emscripten
+fi
+
+diagnostic "libvlc build: make"
+emmake make
+
+diagnostic "libvlc build: generate static modules entry points"
+# start by deleting the previous version so that it's not overwritten
+rm -f "$BUILD_PATH"/vlc-modules.c "$BUILD_PATH"/vlc-modules.bc
+
+# create module list
+echo "creating module list"
+FUN_PROTOS=""
+FUN_LIST=""
+
+for file in "$BUILD_PATH"/modules/.libs/*plugin.a
+do
+    ENTRY=$(get_entryname "$file")
+    FUN_PROTOS="$FUN_PROTOS""int $ENTRY (int (*)(void *, void *, int, ...), void *);\n"
+    FUN_LIST="$FUN_LIST""$ENTRY,\n"
+done;
+
+printf "// This file is autogenerated
+#include <stddef.h>
+%b\n
+const void *vlc_static_modules[] = {
+%bNULL
+};\n" "$FUN_PROTOS" "$FUN_LIST" \
+       > "$BUILD_PATH"/vlc-modules.c
+
+diagnostic "vlc static modules: compiling static modules entry points"
+# compile vlc-modules.c
+emcc -pthread -c "$BUILD_PATH"/vlc-modules.c -o "$BUILD_PATH"/vlc-modules.bc
+
+echo "VLC for wasm32-unknown-emscripten built!"


=====================================
include/vlc_common.h
=====================================
@@ -185,7 +185,7 @@
 # define VLC_USED
 #endif
 
-#if defined (__ELF__) || defined (__MACH__)
+#if defined (__ELF__) || defined (__MACH__) || defined (__wasm__)
 # define VLC_WEAK __attribute__((weak))
 #else
 /**


=====================================
include/vlc_fixups.h
=====================================
@@ -691,6 +691,7 @@ int clock_getres(clockid_t clock_id, struct timespec *tp);
 
 #ifndef _WIN32
 # ifndef HAVE_CLOCK_NANOSLEEP
+# include <time.h>
 int clock_nanosleep(clockid_t clock_id, int flags,
         const struct timespec *rqtp, struct timespec *rmtp);
 # endif


=====================================
src/Makefile.am
=====================================
@@ -444,6 +444,19 @@ libvlccore_la_SOURCES += \
 	posix/timer.c
 endif
 
+if HAVE_EMSCRIPTEN
+libvlccore_la_SOURCES += \
+	posix/thread.c \
+	posix/getaddrinfo.c \
+	posix/error.c \
+	posix/dirs.c \
+	posix/filesystem.c \
+	posix/specific.c \
+	posix/timer.c \
+	emscripten/netconf.c \
+	emscripten/thread.c
+endif
+
 if HAVE_DARWIN
 libvlccore_la_SOURCES += \
 	darwin/error.c \
@@ -487,8 +500,10 @@ if !HAVE_LINUX
 libvlccore_la_SOURCES += posix/wait.c
 endif
 if !HAVE_ANDROID
+if !HAVE_EMSCRIPTEN
+libvlccore_la_SOURCES += posix/sort.c
+endif
 libvlccore_la_SOURCES += \
-	posix/sort.c \
 	posix/thread.c
 if !HAVE_DARWIN
 libvlccore_la_SOURCES += \


=====================================
src/emscripten/netconf.c
=====================================
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * vlc_getProxyUrl for emscripten
+ *****************************************************************************
+ * Copyright (C) 2021 - VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <vlc_common.h>
+
+char *vlc_getProxyUrl(const char *url)
+{
+    VLC_UNUSED(url);
+    return NULL;
+}


=====================================
src/emscripten/thread.c
=====================================
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * vlc_thread implementation for emscripten
+ *****************************************************************************
+ * Copyright (C) 2021 - VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <pthread.h>
+
+unsigned long vlc_thread_id(void)
+{
+    return pthread_self();
+}



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e2e52384fb79264cb77121aa8922aba4cddf834b...9ace5912de874bceb95a777f19cd36c2cfc3d437

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e2e52384fb79264cb77121aa8922aba4cddf834b...9ace5912de874bceb95a777f19cd36c2cfc3d437
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list