diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1a1dd641..25ad4578f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,11 @@ jobs: - name: Build environment information run: 'echo "Matrix OS: ${{ matrix.os }} on $HOSTNAME with $(getconf _NPROCESSORS_ONLN) cores"' + - name: Set git credentials + run: | + git config --global user.name "GitHub Action" + git config --global user.email "retro.gaming.ai@gmail.com" + # Check-out the repository under $GITHUB_WORKSPACE, so the job can # access it - name: Checkout main repo @@ -66,7 +71,7 @@ jobs: frontend/src/generated tools/dist tools/repos/emsdk - key: restore-depends-${{ matrix.os }}-${{ hashFiles('tools/depends/native/emscripten/*', 'tools/depends/wasm/ade/*', 'tools/depends/wasm/opencv/*') }} + key: restore-depends-${{ matrix.os }}-${{ hashFiles('tools/depends/native/emscripten/*', 'tools/depends/wasm/ade/*', 'tools/depends/wasm/codecbox.js/*', 'tools/depends/wasm/ffmpeg/*', 'tools/depends/wasm/libvpx/*', 'tools/depends/wasm/opencv/*', 'tools/depends/wasm/x264/*') }} - name: Build depends if: steps.restore-depends.outputs.cache-hit != 'true' diff --git a/tools/Makefile b/tools/Makefile index bbddcb36c..f8d636cec 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -57,7 +57,11 @@ SHELL := /bin/bash include depends/native/emscripten/package.mk include depends/wasm/ade/package.mk +include depends/wasm/codecbox.js/package.mk +include depends/wasm/ffmpeg/package.mk +include depends/wasm/libvpx/package.mk include depends/wasm/opencv/package.mk +include depends/wasm/x264/package.mk ################################################################################ # @@ -73,8 +77,12 @@ include depends/wasm/opencv/package.mk CHECKOUT_DEPENDS = \ $(S)/checkout-ade \ + $(S)/checkout-codecbox.js \ $(S)/checkout-emscripten \ + $(S)/checkout-ffmpeg \ + $(S)/checkout-libvpx \ $(S)/checkout-opencv \ + $(S)/checkout-x264 \ $(S)/patch-opencv \ # @@ -82,6 +90,7 @@ CHECKOUT_DEPENDS = \ # BUILD_DEPENDS = \ + $(S)/build-ffmpeg \ $(S)/build-opencv \ # @@ -89,6 +98,7 @@ BUILD_DEPENDS = \ # INSTALL_DEPENDS = \ + $(S)/install-ffmpeg \ $(S)/install-opencv \ # @@ -104,18 +114,34 @@ install: $(INSTALL_DEPENDS) # .PHONY: ade +.PHONY: codecbox.js .PHONY: emscripten +.PHONY: ffmpeg +.PHONY: libvpx .PHONY: opencv +.PHONY: x264 ade: \ $(S)/install-ade +codecbox.js: \ + $(S)/install-codecbox.js + emscripten: \ $(S)/build-emscripten +ffmpeg: \ + $(S)/install-ffmpeg + +libvpx: \ + $(S)/install-libvpx + opencv: \ $(S)/install-opencv +x264: \ + $(S)/install-x264 + ################################################################################ # # Build system procedures diff --git a/tools/build-depends.sh b/tools/build-depends.sh index da171c51e..29c2aa4d9 100755 --- a/tools/build-depends.sh +++ b/tools/build-depends.sh @@ -33,6 +33,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/build-paths.sh" +function install_npm_utilies() { + cd "${SCRIPT_DIR}" + yarn install +} + # # Dispatch function # @@ -61,6 +66,8 @@ function dispatch() { } function depends-all() { + install_npm_utilies + # Dependencies to build BUILD_DEPENDS="emscripten " @@ -71,18 +78,30 @@ function depends-all() { BUILD_DEPENDS+="opencv " fi + # Build FFmpeg + if [ ! -f "${DISTRIBUTION_LIB_DIR}/libavutil.a.a" ]; then + rm -f "${STAMP_DIR}/build-ffmpeg" + BUILD_DEPENDS+="ffmpeg " + fi + make -C "${TOOL_DIR}" -j$(getconf _NPROCESSORS_ONLN) ${BUILD_DEPENDS} } function depends-checkout() { + install_npm_utilies + make -C "${TOOL_DIR}" checkout -j10 } function depends-build() { + install_npm_utilies + make -C "${TOOL_DIR}" build -j$(getconf _NPROCESSORS_ONLN) } function depends-install() { + install_npm_utilies + make -C "${TOOL_DIR}" install } diff --git a/tools/depends/wasm/codecbox.js/0001-Fix-error-building-OpenH264.patch b/tools/depends/wasm/codecbox.js/0001-Fix-error-building-OpenH264.patch new file mode 100644 index 000000000..42d8d3d0a --- /dev/null +++ b/tools/depends/wasm/codecbox.js/0001-Fix-error-building-OpenH264.patch @@ -0,0 +1,35 @@ +From 4e97a5d5673d8e496634da9b2ba3b9ed1513c04e Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Sat, 11 Jul 2020 11:03:54 -0700 +Subject: [PATCH 1/2] Fix error building OpenH264 + +Error was: + + codec/common/mips/copy_mb_mmi.c:94:35: error: invalid use of a cast in + a inline asm context requiring an l-value: remove the cast or build + with -fheinous-gnu-extensions + + : [pDst]"+&r"((unsigned char *)pDst), [pSrc]"+&r"((unsigned char *)pSrc) + ~~~~~~~~~~~~~~~~~^~~~ +--- + Gruntfile.js | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Gruntfile.js b/Gruntfile.js +index 7f0d90d..123f403 100644 +--- a/Gruntfile.js ++++ b/Gruntfile.js +@@ -251,8 +251,8 @@ module.exports = function (grunt) { + }, + openh264: { + repo: 'https://github.com/cisco/openh264.git', +- make: 'emmake make SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake, +- install: 'emmake make ARCH=mips PREFIX=' + distPath + ' install-headers install-shared', ++ make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake, ++ install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared', + }, + zlib: { + repo: 'https://github.com/madler/zlib.git', +-- +2.20.1 + diff --git a/tools/depends/wasm/codecbox.js/0002-Fix-errors-building-with-latest-llvm.patch b/tools/depends/wasm/codecbox.js/0002-Fix-errors-building-with-latest-llvm.patch new file mode 100644 index 000000000..37449aae1 --- /dev/null +++ b/tools/depends/wasm/codecbox.js/0002-Fix-errors-building-with-latest-llvm.patch @@ -0,0 +1,43 @@ +From e7df34d0fcb6f2f3ebd924fd5afa372181a4e4c1 Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Sun, 12 Jul 2020 20:16:28 -0700 +Subject: [PATCH 2/2] Fix errors building with latest llvm + +Errors were: + +[lame] + +>> error: undefined symbol: popen (referenced by top-level compiled C/C++ code) + +[openh264] + +>> error: undefined symbol: pthread_attr_setscope (referenced by top-level compiled C/C++ code) +--- + Gruntfile.js | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Gruntfile.js b/Gruntfile.js +index 123f403..35de85c 100644 +--- a/Gruntfile.js ++++ b/Gruntfile.js +@@ -231,7 +231,7 @@ module.exports = function (grunt) { + }, + lame: { + repo: 'https://github.com/rbrito/lame.git', +- configure: 'emconfigure ./configure CFLAGS=-O3 --prefix=' + distPath + ' --enable-shared=no --disable-gtktest ' + ++ configure: 'emconfigure ./configure CFLAGS="-O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0" --prefix=' + distPath + ' --enable-shared=no --disable-gtktest ' + + ' --disable-decoder --disable-cpml', + }, + libvpx: { +@@ -251,7 +251,7 @@ module.exports = function (grunt) { + }, + openh264: { + repo: 'https://github.com/cisco/openh264.git', +- make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake, ++ make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake, + install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared', + }, + zlib: { +-- +2.20.1 + diff --git a/tools/depends/wasm/codecbox.js/0003-Enable-select-filter.patch b/tools/depends/wasm/codecbox.js/0003-Enable-select-filter.patch new file mode 100644 index 000000000..7461e489b --- /dev/null +++ b/tools/depends/wasm/codecbox.js/0003-Enable-select-filter.patch @@ -0,0 +1,24 @@ +From 2b2406260b117af9dc08b66de42f1990c48cd842 Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Sun, 26 Jul 2020 13:26:54 -0700 +Subject: [PATCH 3/3] Enable select filter + +--- + Gruntfile.js | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Gruntfile.js b/Gruntfile.js +index 35de85c..e1f615d 100644 +--- a/Gruntfile.js ++++ b/Gruntfile.js +@@ -176,6 +176,7 @@ module.exports = function (grunt) { + 'pad', + 'rotate', + 'scale', ++ 'select', + 'setdar', + 'setsar', + 'showinfo', +-- +2.17.1 + diff --git a/tools/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch b/tools/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch new file mode 100644 index 000000000..5338ebd99 --- /dev/null +++ b/tools/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch @@ -0,0 +1,46 @@ +From e74a69bac5b0861ac22ce0b105a8457d66729a3b Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Fri, 31 Jul 2020 20:43:59 -0700 +Subject: [PATCH 4/4] Don't call bash with -x + +--- + Gruntfile.js | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/Gruntfile.js b/Gruntfile.js +index e1f615d..1357ebe 100644 +--- a/Gruntfile.js ++++ b/Gruntfile.js +@@ -240,7 +240,7 @@ module.exports = function (grunt) { + needPatch: false, + configure: 'emconfigure ./configure --prefix=' + distPath + ' --disable-examples --disable-docs ' + + ' --disable-runtime-cpu-detect --disable-multithread --target=generic-gnu --extra-cflags=-O3', +- make: 'emmake make SHELL="/bin/bash -x" -j' + paraMake, ++ make: 'emmake make SHELL="/bin/bash" -j' + paraMake, + postMake: 'emranlib libvpx.a', // https://github.com/emscripten-core/emscripten/issues/9705 + }, + x264: { +@@ -248,17 +248,17 @@ module.exports = function (grunt) { + needPatch: false, + configure: 'emconfigure ./configure --disable-thread --disable-asm --disable-opencl ' + + ' --host=i686-pc-linux-gnu --disable-cli --enable-shared --disable-gpl --prefix=' + distPath, +- make: 'emmake make SHELL="/bin/bash -x" -j' + paraMake ++ make: 'emmake make SHELL="/bin/bash" -j' + paraMake + }, + openh264: { + repo: 'https://github.com/cisco/openh264.git', +- make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake, ++ make: 'emmake make USE_ASM=No SHELL="/bin/bash" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake, + install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared', + }, + zlib: { + repo: 'https://github.com/madler/zlib.git', + configure: 'emconfigure ./configure --prefix=' + distPath + ' --static', +- make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash -x" -j' + paraMake, ++ make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash" -j' + paraMake, + }, + ffmpeg: { + repo: 'https://github.com/FFmpeg/FFmpeg.git', +-- +2.17.1 + diff --git a/tools/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch b/tools/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch new file mode 100644 index 000000000..aa94e5390 --- /dev/null +++ b/tools/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch @@ -0,0 +1,29 @@ +From 031f2a2b50a187a68b130bf6da1f8d0d39de445e Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Sat, 1 Aug 2020 12:33:14 -0700 +Subject: [PATCH 5/5] Don't download FFmpeg + +--- + Gruntfile.js | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/Gruntfile.js b/Gruntfile.js +index 1357ebe..e60efa9 100644 +--- a/Gruntfile.js ++++ b/Gruntfile.js +@@ -260,12 +260,6 @@ module.exports = function (grunt) { + configure: 'emconfigure ./configure --prefix=' + distPath + ' --static', + make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash" -j' + paraMake, + }, +- ffmpeg: { +- repo: 'https://github.com/FFmpeg/FFmpeg.git', +- // select your ffmpeg config +- configure: ffmpegCustomConfig, +- //configure: ffmpegFullConfig, +- }, + }; + + var cloneDepth = 50; +-- +2.17.1 + diff --git a/tools/depends/wasm/codecbox.js/package.mk b/tools/depends/wasm/codecbox.js/package.mk new file mode 100644 index 000000000..96c1ccf97 --- /dev/null +++ b/tools/depends/wasm/codecbox.js/package.mk @@ -0,0 +1,125 @@ +################################################################################ +# +# Copyright (C) 2020-2023 retro.ai +# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp +# +# SPDX-License-Identifier: Apache-2.0 +# See the file LICENSE.md for more information. +# +################################################################################ + +# Dependency name and version +CODECBOX_JS_REPO_NAME = codecbox.js +CODECBOX_JS_VERSION = c31de35d32cc9e3f01dd577b3c27df7f24e599ed +CODECBOX_JS_REMOTE_REPO = https://github.com/duanyao/$(CODECBOX_JS_REPO_NAME).git + +################################################################################ +# +# Paths +# +################################################################################ + +# Checkout directory +REPO_DIR_CODECBOX_JS = $(REPO_DIR)/$(CODECBOX_JS_REPO_NAME) + +# Build directory +BUILD_DIR_CODECBOX_JS = $(BUILD_DIR)/$(CODECBOX_JS_REPO_NAME) + +# Repo directory for grunt +REPO_DIR_GRUNT = $(REPO_DIR)/grunt + +################################################################################ +# +# Configuration +# +################################################################################ + +CODECBOX_JS_BUILD_DEPENDS = \ + $(S)/checkout-codecbox.js \ + $(S)/build-emscripten \ + +################################################################################ +# +# Checkout +# +# Dependency: Run `yarn install` first +# +################################################################################ + +$(S)/checkout-codecbox.js: $(S)/.precheckout \ + $(TOOL_DIR)/depends/wasm/codecbox.js/0001-Fix-error-building-OpenH264.patch \ + $(TOOL_DIR)/depends/wasm/codecbox.js/0002-Fix-errors-building-with-latest-llvm.patch \ + $(TOOL_DIR)/depends/wasm/codecbox.js/0003-Enable-select-filter.patch \ + $(TOOL_DIR)/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch \ + $(TOOL_DIR)/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch \ + $(TOOL_DIR)/depends/wasm/x264/0001-Remove-problematic-configure-test.patch + # Clone repo + [ -d "$(REPO_DIR_CODECBOX_JS)" ] || ( \ + git clone "$(CODECBOX_JS_REMOTE_REPO)" "$(REPO_DIR_CODECBOX_JS)" \ + ) + + # Reset repo state + git -C "$(REPO_DIR_CODECBOX_JS)" reset --hard $(CODECBOX_JS_VERSION) + + # Remove stale dependencies + rm -rf "$(REPO_DIR_CODECBOX_JS)/build" + + # Patch repo + cd "$(REPO_DIR_CODECBOX_JS)" && git am < \ + "$(TOOL_DIR)/depends/wasm/codecbox.js/0001-Fix-error-building-OpenH264.patch" + cd "$(REPO_DIR_CODECBOX_JS)" && git am < \ + "$(TOOL_DIR)/depends/wasm/codecbox.js/0002-Fix-errors-building-with-latest-llvm.patch" + cd "$(REPO_DIR_CODECBOX_JS)" && git am < \ + "$(TOOL_DIR)/depends/wasm/codecbox.js/0003-Enable-select-filter.patch" + cd "$(REPO_DIR_CODECBOX_JS)" && git am < \ + "$(TOOL_DIR)/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch" + cd "$(REPO_DIR_CODECBOX_JS)" && git am < \ + "$(TOOL_DIR)/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch" + + # Install grunt + cd "$(REPO_DIR_CODECBOX_JS)" && \ + npm install + + # Clone depends + cd "$(REPO_DIR_CODECBOX_JS)" && \ + npx grunt init --force + + # Patch depends + #cd "$(REPO_DIR_CODECBOX_JS)/build/x264" && git am < \ + # "$(TOOL_DIR)/depends/wasm/x264/0001-Remove-problematic-configure-test.patch" + + touch "$@" + +################################################################################ +# +# Build +# +################################################################################ + +$(S)/build-codecbox.js: $(S)/.prebuild $(CODECBOX_JS_BUILD_DEPENDS) + # Deep-copy repo to build folder for now + [ -d "$(BUILD_DIR_CODECBOX_JS)" ] || ( \ + cp -r "$(REPO_DIR_CODECBOX_JS)" "$(BUILD_DIR_CODECBOX_JS)" \ + ) + + # Source Emscripten environment, then build Codecbox.js and dependencies + cd "$(BUILD_DIR_CODECBOX_JS)" && \ + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + npx grunt configure-deps && \ + npx grunt make-deps + + touch "$@" + +################################################################################ +# +# Install +# +################################################################################ + +$(S)/install-codecbox.js: $(S)/.precheckout $(S)/build-codecbox.js + install -d "$(TOOL_DIR)/dist" + + # Copy dist folder + cp -r "${BUILD_DIR_CODECBOX_JS}/build/dist"/* "$(TOOL_DIR)/dist" + + touch "$@" diff --git a/tools/depends/wasm/ffmpeg/package.mk b/tools/depends/wasm/ffmpeg/package.mk new file mode 100644 index 000000000..5028cd037 --- /dev/null +++ b/tools/depends/wasm/ffmpeg/package.mk @@ -0,0 +1,373 @@ +################################################################################ +# +# Copyright (C) 2020-2023 retro.ai +# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp +# +# SPDX-License-Identifier: Apache-2.0 +# See the file LICENSE.md for more information. +# +################################################################################ + +# Dependency name and version +FFMPEG_REPO_NAME = ffmpeg +FFMPEG_VERSION = n4.4 +FFMPEG_REMOTE_REPO = https://github.com/FFmpeg/FFmpeg.git +FFMPEG_LIB = libavutil.a + +################################################################################ +# +# Paths +# +################################################################################ + +# Checkout directory +REPO_DIR_FFMPEG = $(REPO_DIR)/$(FFMPEG_REPO_NAME) + +# Build directory +BUILD_DIR_FFMPEG = $(BUILD_DIR)/$(FFMPEG_REPO_NAME) + +# Build output +BUILD_FILE_FFMPEG = $(BUILD_DIR_FFMPEG)/libavutil/$(FFMPEG_LIB) + +# Install output +INSTALL_FILE_FFMPEG = $(DISTRIBUTION_DIR)/lib/$(FFMPEG_LIB) + +################################################################################ +# +# Configuration +# +################################################################################ + +# TODO: Remove codecbox.js dependency +FFMPEG_BUILD_DEPENDS = \ + $(S)/checkout-codecbox.js \ + $(S)/checkout-ffmpeg \ + $(S)/build-emscripten \ + $(S)/install-codecbox.js \ + #$(S)/install-libvpx \ + #$(S)/install-x264 \ + +# You can change items in FF_DECODERS, FF_DEMUXERS, FF_PARSERS, FF_ENCODERS, +# FF_MUXERS and FF_FILTERS to select components of ffmpeg +FF_DECODERS = \ + aac \ + aac_latm \ + ac3 \ + ac3_fixed \ + cook \ + h263 \ + h263i \ + h263p \ + h264 \ + hevc \ + libvpx_vp8 \ + libvpx_vp9 \ + mjpeg \ + mjpegb \ + mp2 \ + mp2float \ + mp3 \ + mp3adu \ + mp3adufloat \ + mp3float \ + mp3on4 \ + mp3on4float \ + mpeg1video \ + mpeg2video \ + mpeg4 \ + mpegvideo \ + msmpeg4v1 \ + msmpeg4v2 \ + msmpeg4v3 \ + opus \ + pcm_alaw \ + pcm_bluray \ + pcm_dvd \ + pcm_f32be \ + pcm_f32le \ + pcm_f64be \ + pcm_f64le \ + pcm_lxf \ + pcm_mulaw \ + pcm_s16be \ + pcm_s16be_planar \ + pcm_s16le \ + pcm_s16le_planar \ + pcm_s24be \ + pcm_s24daud \ + pcm_s24le \ + pcm_s24le_planar \ + pcm_s32be \ + pcm_s32le \ + pcm_s32le_planar \ + pcm_s8 \ + pcm_s8_planar \ + pcm_u16be \ + pcm_u16le \ + pcm_u24be \ + pcm_u24le \ + pcm_u32be \ + pcm_u32le \ + pcm_u8 \ + ra_144 \ + ra_288 \ + ralf \ + rv10 \ + rv20 \ + rv30 \ + rv40 \ + sipr \ + vc1 \ + vc1image \ + vorbis \ + vp6 \ + vp6a \ + vp6f \ + wmalossless \ + wmapro \ + wmav1 \ + wmav2 \ + wmavoice \ + wmv1 \ + wmv2 \ + wmv3 \ + wmv3image \ + zlib \ + +FF_DEMUXERS = \ + aac \ + ac3 \ + asf \ + avi \ + flac \ + flv \ + m4v \ + matroska \ + mjpeg \ + mov \ + mp3 \ + mpegps \ + mpegts \ + mpegtsraw \ + mpegvideo \ + ogg \ + pcm_alaw \ + pcm_f32be \ + pcm_f32le \ + pcm_f64be \ + pcm_f64le \ + pcm_mulaw \ + pcm_s16be \ + pcm_s16le \ + pcm_s24be \ + pcm_s24le \ + pcm_s32be \ + pcm_s32le \ + pcm_s8 \ + pcm_u16be \ + pcm_u16le \ + pcm_u24be \ + pcm_u24le \ + pcm_u32be \ + pcm_u32le \ + pcm_u8 \ + rm \ + vc1 \ + vc1t \ + +FF_PARSERS = \ + aac \ + aac_latm \ + h264 \ + hevc \ + opus \ + +FF_ENCODERS = \ + aac \ + libopus \ + libvpx_vp8 \ + libvpx_vp9 \ + libx264 \ + libx264rgb \ + vorbis \ + libmp3lame \ + libopenh264 \ + +FF_MUXERS = \ + mp3 \ + mp4 \ + oga \ + ogg \ + webm \ + +FF_FILTERS = \ + adelay \ + aformat \ + aresample \ + ashowinfo \ + ass \ + atrim \ + concat \ + copy \ + crop \ + cropdetect \ + format \ + join \ + pad \ + rotate \ + scale \ + select \ + setdar \ + setsar \ + showinfo \ + trim \ + vflip \ + volume \ + volumedetect \ + +FFMPEG_STANDARD_OPTIONS = \ + --disable-logging \ + --prefix="$(TOOL_DIR)/dist" \ + +FFMPEG_LICENSING_OPTIONS = \ + --enable-gpl \ + --enable-version3 \ + +FFMPEG_CONFIGURATION_OPTIONS = \ + --disable-runtime-cpudetect \ + +FFMPEG_PROGRAM_OPTIONS = \ + --disable-programs \ + --disable-ffplay \ + --disable-ffprobe \ + +FFMPEG_DOCUMENTATION_OPTIONS = \ + --disable-doc \ + +FFMPEG_COMPONENT_OPTIONS = \ + --disable-pthreads \ + --disable-w32threads \ + --disable-network \ + +FFMPEG_EXTERNAL_LIBRARIES = \ + --enable-libvpx \ + --enable-libx264 \ + --enable-libmp3lame \ + --enable-libopus \ + --enable-libopenh264 \ + --disable-xlib \ + --disable-iconv \ + +FFMPEG_TOOLCHAIN_OPTIONS = \ + --arch=x86_32 \ + --cpu=generic \ + --enable-cross-compile \ + --target-os=none \ + --cc="emcc" \ + --pkg-config="$(BUILD_DIR_CODECBOX_JS)/pkg_config" \ + --ranlib="emranlib" \ + --extra-cflags="-I$(BUILD_DIR_CODECBOX_JS)/build/dist/include -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -fno-stack-protector" \ + --extra-ldflags="-L$(BUILD_DIR_CODECBOX_JS)/build/dist/lib" \ + --optflags="-O3" \ + +FFMPEG_OPTIMIZATION_OPTIONS = \ + --disable-asm \ + +FFMPEG_DEVELOPER_OPTIONS = \ + --disable-debug \ + --disable-stripping \ + +FFMPEG_CONFIG_SHARED = \ + $(FFMPEG_STANDARD_OPTIONS) \ + $(FFMPEG_LICENSING_OPTIONS) \ + $(FFMPEG_CONFIGURATION_OPTIONS) \ + $(FFMPEG_PROGRAM_OPTIONS) \ + $(FFMPEG_DOCUMENTATION_OPTIONS) \ + $(FFMPEG_COMPONENT_OPTIONS) \ + $(FFMPEG_EXTERNAL_LIBRARIES) \ + $(FFMPEG_TOOLCHAIN_OPTIONS) \ + $(FFMPEG_OPTIMIZATION_OPTIONS) \ + $(FFMPEG_DEVELOPER_OPTIONS) \ + +FFMPEG_FULL_CONFIG = \ + $(FFMPEG_CONFIG_SHARED) \ + --enable-protocol=file \ + +FFMPEG_CUSTOM_CONFIG = \ + $(FFMPEG_CONFIG_SHARED) \ + --disable-everything \ + --enable-protocol=file \ + $(foreach decoder,$(FF_DECODERS),--enable-decoder=$(decoder) ) \ + $(foreach demuxer,$(FF_DEMUXERS),--enable-demuxer=$(demuxer) ) \ + $(foreach parser,$(FF_PARSERS),--enable-parser=$(parser) ) \ + $(foreach muxer,$(FF_MUXERS),--enable-muxer=$(muxer) ) \ + $(foreach encoder,$(FF_ENCODERS),--enable-encoder=$(encoder) ) \ + $(foreach filter,$(FF_FILTERS),--enable-filter=$(filter) ) \ + +# Select your FFmpeg config +#FFMPEG_CONFIGURE_OPTIONS = $(FFMPEG_FULL_CONFIG) +FFMPEG_CONFIGURE_OPTIONS = $(FFMPEG_CUSTOM_CONFIG) + +################################################################################ +# +# Checkout +# +################################################################################ + +$(S)/checkout-ffmpeg: $(S)/.precheckout + [ -d "$(REPO_DIR_FFMPEG)" ] || ( \ + git clone -b $(FFMPEG_VERSION) "$(FFMPEG_REMOTE_REPO)" "$(REPO_DIR_FFMPEG)" \ + ) + + @# TODO: Repository sync is delegated to the CI system. + + touch "$@" + +################################################################################ +# +# Build +# +################################################################################ + +$(BUILD_FILE_FFMPEG): $(S)/.prebuild $(FFMPEG_BUILD_DEPENDS) + # Deep-copy repo to build folder for now + [ -d "$(BUILD_DIR_FFMPEG)" ] || ( \ + cp -r "$(REPO_DIR_FFMPEG)" "$(BUILD_DIR_FFMPEG)" \ + ) + + # Activate PATH and other environment variables in the current terminal and + # configure FFmpeg + [ -f "$(BUILD_DIR_FFMPEG)/ffbuild/.config" ] || ( \ + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + cd "${BUILD_DIR_FFMPEG}" && \ + emconfigure ./configure $(FFMPEG_CONFIGURE_OPTIONS) \ + ) + + # Activate PATH and other environment variables in the current terminal and + # build FFmpeg + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_FFMPEG}" -j$(shell getconf _NPROCESSORS_ONLN) + + touch "$@" + +$(S)/build-ffmpeg: $(BUILD_FILE_FFMPEG) + touch "$@" + +################################################################################ +# +# Install +# +################################################################################ + +$(INSTALL_FILE_FFMPEG): $(S)/.preinstall $(S)/build-ffmpeg + mkdir -p "$(DISTRIBUTION_DIR)" + + # Activate PATH and other environment variables in the current terminal and + # install FFmpeg + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_FFMPEG}" install + + touch "$@" + +$(S)/install-ffmpeg: $(INSTALL_FILE_FFMPEG) + touch "$@" diff --git a/tools/depends/wasm/ffmpeg/pkg_config b/tools/depends/wasm/ffmpeg/pkg_config new file mode 100755 index 000000000..237e02396 --- /dev/null +++ b/tools/depends/wasm/ffmpeg/pkg_config @@ -0,0 +1,25 @@ +#!/bin/bash +################################################################################ +# +# Copyright (C) 2021-2023 retro.ai +# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp +# +# SPDX-License-Identifier: Apache-2.0 +# See the file LICENSE.md for more information. +# +################################################################################ + +# Enable strict shell mode +set -o errexit +set -o nounset +set -o pipefail + +# Get the absolute path to this script +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Set pkgconfig environment variables +PKG_CONFIG_PATH="${SCRIPT_DIR}/dist/lib/pkgconfig" +export PKG_CONFIG_PATH + +# Run pkgconfig +exec /usr/bin/pkg-config "$@" diff --git a/tools/depends/wasm/libvpx/package.mk b/tools/depends/wasm/libvpx/package.mk new file mode 100644 index 000000000..70af98501 --- /dev/null +++ b/tools/depends/wasm/libvpx/package.mk @@ -0,0 +1,125 @@ +################################################################################ +# +# Copyright (C) 2020-2023 retro.ai +# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp +# +# SPDX-License-Identifier: Apache-2.0 +# See the file LICENSE.md for more information. +# +################################################################################ + +# Dependency name and version +LIBVPX_REPO_NAME = libvpx +LIBVPX_VERSION = v1.9.0 +LIBVPX_REMOTE_REPO = https://github.com/webmproject/$(LIBVPX_REPO_NAME).git +LIBVPX_LIB = libvpx.a + +################################################################################ +# +# Paths +# +################################################################################ + +# Checkout directory +REPO_DIR_LIBVPX = $(REPO_DIR)/$(LIBVPX_REPO_NAME) + +# Build directory +BUILD_DIR_LIBVPX = $(BUILD_DIR)/$(LIBVPX_REPO_NAME) + +# Build output +BUILD_FILE_LIBVPX = $(BUILD_DIR_LIBVPX)/$(LIBVPX_LIB) + +# Install output +INSTALL_FILE_LIBVPX = $(DISTRIBUTION_DIR)/lib/$(LIBVPX_LIB) + +################################################################################ +# +# Configuration +# +################################################################################ + +LIBVPX_BUILD_DEPENDS = \ + $(S)/checkout-libvpx \ + $(S)/build-emscripten \ + +LIBVPX_BUILD_OPTIONS = \ + --prefix="$(DISTRIBUTION_DIR)" \ + --target=generic-gnu \ + --extra-cflags="-O3" \ +# --enable-ccache \ # TODO + +LIBVPX_ADVANCED_OPTIONS = \ + --disable-examples \ + --disable-tools \ + --disable-docs \ + --disable-multithread \ + --disable-runtime-cpu-detect \ + +LIBVPX_CONFIGURE_OPTIONS = \ + $(LIBVPX_BUILD_OPTIONS) \ + $(LIBVPX_ADVANCED_OPTIONS) \ + +################################################################################ +# +# Checkout +# +################################################################################ + +$(S)/checkout-libvpx: $(S)/.precheckout + [ -d "$(REPO_DIR_LIBVPX)" ] || ( \ + git clone -b $(LIBVPX_VERSION) "$(LIBVPX_REMOTE_REPO)" "$(REPO_DIR_LIBVPX)" \ + ) + + @# TODO: Repository sync is delegated to the CI system. + + touch "$@" + +################################################################################ +# +# Build +# +################################################################################ + +$(BUILD_FILE_LIBVPX): $(S)/.prebuild $(LIBVPX_BUILD_DEPENDS) + # Deep-copy repo to build folder for now + [ -d "$(BUILD_DIR_LIBVPX)" ] || ( \ + cp -r "$(REPO_DIR_LIBVPX)" "$(BUILD_DIR_LIBVPX)" \ + ) + + # Activate PATH and other environment variables in the current terminal and + # configure libvpx + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + cd "${BUILD_DIR_LIBVPX}" && \ + emconfigure ./configure \ + $(LIBVPX_CONFIGURE_OPTIONS) + + # Activate PATH and other environment variables in the current terminal and + # build libvpx + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_LIBVPX}" \ + SHELL="/bin/bash" \ + -j$(shell getconf _NPROCESSORS_ONLN) \ + + touch "$@" + +$(S)/build-libvpx: $(BUILD_FILE_LIBVPX) + touch "$@" + +################################################################################ +# +# Install +# +################################################################################ + +$(INSTALL_FILE_LIBVPX): $(S)/.preinstall $(S)/build-libvpx + mkdir -p "$(DISTRIBUTION_DIR)" + + # Activate PATH and other environment variables in the current terminal and + # install libvpx + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_LIBVPX}" install + + touch "$@" + +$(S)/install-libvpx: $(INSTALL_FILE_LIBVPX) + touch "$@" diff --git a/tools/depends/wasm/x264/0001-Remove-problematic-configure-test.patch b/tools/depends/wasm/x264/0001-Remove-problematic-configure-test.patch new file mode 100644 index 000000000..70057b4ed --- /dev/null +++ b/tools/depends/wasm/x264/0001-Remove-problematic-configure-test.patch @@ -0,0 +1,43 @@ +From 873a1c043a300aa214276e924f183d10a70a3249 Mon Sep 17 00:00:00 2001 +From: juztamau5 +Date: Sat, 11 Jul 2020 06:58:06 -0700 +Subject: [PATCH] Remove problematic configure test + +The test compiles a file and uses the "strings" program to search for +text in the binary output. + +On 2020-06-05, a STRINGS parameter was added to configure that allows the +caller to specify the path to the strings binary. This should be set to a +version of "strings" that can search wasm files. + +See: + + https://code.videolan.org/videolan/x264/-/commit/235ce6130168f4deee55c88ecda5ab84d81d125b +--- + configure | 10 ---------- + 1 file changed, 10 deletions(-) + +diff --git a/configure b/configure +index 78aa1140..14ca3f99 100755 +--- a/configure ++++ b/configure +@@ -1015,16 +1015,6 @@ ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment" + + # skip endianness check for Intel Compiler and MSVS, as all supported platforms are little. each have flags that will cause the check to fail as well + CPU_ENDIAN="little-endian" +-if [ $compiler = GNU ]; then +- echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c +- $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed" +- if (${STRINGS} -a conftest.o | grep -q BIGE) && (${STRINGS} -a conftest.o | grep -q FPendian) ; then +- define WORDS_BIGENDIAN +- CPU_ENDIAN="big-endian" +- elif !(${STRINGS} -a conftest.o | grep -q EGIB && ${STRINGS} -a conftest.o | grep -q naidnePF) ; then +- die "endian test failed" +- fi +-fi + + if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then + [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static" +-- +2.20.1 + diff --git a/tools/depends/wasm/x264/package.mk b/tools/depends/wasm/x264/package.mk new file mode 100644 index 000000000..debed49d3 --- /dev/null +++ b/tools/depends/wasm/x264/package.mk @@ -0,0 +1,130 @@ +################################################################################ +# +# Copyright (C) 2020-2023 retro.ai +# This file is part of retro-dapp - https://github.com/RetroAI/retro-dapp +# +# SPDX-License-Identifier: Apache-2.0 +# See the file LICENSE.md for more information. +# +################################################################################ + +# Dependency name and version +X264_REPO_NAME = x264 +X264_VERSION = stable +X264_REMOTE_REPO = https://code.videolan.org/videolan/$(X264_REPO_NAME).git +X264_LIB = libx264.a + +################################################################################ +# +# Paths +# +################################################################################ + +# Checkout directory +REPO_DIR_X264 = $(REPO_DIR)/$(X264_REPO_NAME) + +# Build directory +BUILD_DIR_X264 = $(BUILD_DIR)/$(X264_REPO_NAME) + +# Build output +BUILD_FILE_X264 = $(BUILD_DIR_X264)/$(X264_LIB) + +# Install output +INSTALL_FILE_X264 = $(DISTRIBUTION_DIR)/lib/$(X264_LIB) + +################################################################################ +# +# Configuration +# +################################################################################ + +X264_BUILD_DEPENDS = \ + $(S)/checkout-x264 \ + $(S)/build-emscripten \ + +X264_STANDARD_OPTIONS = \ + --prefix="$(DISTRIBUTION_DIR)" \ + +X264_CONFIGURATION_OPTIONS = \ + --disable-cli \ + --enable-shared \ + --disable-opencl \ + --disable-gpl \ + --disable-thread \ + +X264_ADVANCED_OPTIONS = \ + --disable-asm \ + +X264_CROSS_COMPILATION = \ + --host=i686-pc-linux-gnu \ + +X264_CONFIGURE_OPTIONS = \ + $(X264_STANDARD_OPTIONS) \ + $(X264_CONFIGURATION_OPTIONS) \ + $(X264_ADVANCED_OPTIONS) \ + $(X264_CROSS_COMPILATION) \ + +################################################################################ +# +# Checkout +# +################################################################################ + +$(S)/checkout-x264: $(S)/.precheckout + [ -d "$(REPO_DIR_X264)" ] || ( \ + git clone -b $(X264_VERSION) "$(X264_REMOTE_REPO)" "$(REPO_DIR_X264)" \ + ) + + @# TODO: Repository sync is delegated to the CI system. + + touch "$@" + +################################################################################ +# +# Build +# +################################################################################ + +$(BUILD_FILE_X264): $(S)/.prebuild $(X264_BUILD_DEPENDS) + # Deep-copy repo to build folder for now + [ -d "$(BUILD_DIR_X264)" ] || ( \ + cp -r "$(REPO_DIR_X264)" "$(BUILD_DIR_X264)" \ + ) + + # Activate PATH and other environment variables in the current terminal and + # configure x264 + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + cd "${BUILD_DIR_X264}" && \ + emconfigure ./configure \ + $(X264_CONFIGURE_OPTIONS) + + # Activate PATH and other environment variables in the current terminal and + # build x264 + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_X264}" \ + SHELL="/bin/bash" \ + -j$(shell getconf _NPROCESSORS_ONLN) \ + + touch "$@" + +$(S)/build-x264: $(BUILD_FILE_X264) + touch "$@" + +################################################################################ +# +# Install +# +################################################################################ + +$(INSTALL_FILE_X264): $(S)/.preinstall $(S)/build-x264 + mkdir -p "$(DISTRIBUTION_DIR)" + + # Activate PATH and other environment variables in the current terminal and + # install x264 + . "$(REPO_DIR_EMSDK)/emsdk_set_env.sh" && \ + emmake make -C "${BUILD_DIR_X264}" install + + touch "$@" + +$(S)/install-x264: $(INSTALL_FILE_X264) + touch "$@" diff --git a/tools/setup_paths.mk b/tools/setup_paths.mk index 8f6339ab9..15a19653e 100644 --- a/tools/setup_paths.mk +++ b/tools/setup_paths.mk @@ -17,6 +17,9 @@ # Directory for tooling TOOL_DIR = $(shell pwd) +# Directory for dependency definitions +DEPENDS_DIR = $(TOOL_DIR)/depends + # Directory of stamps for tracking build progress STAMP_DIR = $(TOOL_DIR)/stamps