Commit 9a04374f authored by Jerome Wu's avatar Jerome Wu

Optimize bash scripts

parent 74e8907e
#!/bin/bash -x #!/bin/bash
set -eo pipefail set -euo pipefail
EM_VERSION=1.39.18-upstream EM_VERSION=1.39.18-upstream
...@@ -10,4 +10,4 @@ docker run \ ...@@ -10,4 +10,4 @@ docker run \
-v $PWD:/src \ -v $PWD:/src \
-v $PWD/wasm/cache:/emsdk_portable/.data/cache/wasm \ -v $PWD/wasm/cache:/emsdk_portable/.data/cache/wasm \
trzeci/emscripten:$EM_VERSION \ trzeci/emscripten:$EM_VERSION \
sh -c 'bash -x ./build.sh' sh -c 'bash ./build.sh'
#!/bin/bash -x #!/bin/bash
set -eo pipefail set -eo pipefail
ROOT=$PWD SCRIPT_ROOT=$(dirname $0)/wasm/build-scripts
BUILD_DIR=$ROOT/build
# verify Emscripten version # verify Emscripten version
emcc -v emcc -v
# build x264 # build x264
$ROOT/wasm/build-scripts/build-x264.sh $ROOT/third_party/x264 $BUILD_DIR $SCRIPT_ROOT/build-x264.sh
# configure FFmpeg with Emscripten # configure FFmpeg with Emscripten
$ROOT/wasm/build-scripts/configure.sh $BUILD_DIR $SCRIPT_ROOT/configure-ffmpeg.sh
# # build dependencies # build ffmpeg.wasm
$ROOT/wasm/build-scripts/make.sh $SCRIPT_ROOT/build-ffmpeg.sh
# # build ffmpeg.wasm
$ROOT/wasm/build-scripts/build-ffmpeg.sh $BUILD_DIR
#!/bin/bash -x #!/bin/bash
set -eo pipefail set -eo pipefail
source $(dirname $0)/var.sh
BUILD_DIR=$1
mkdir -p wasm/dist mkdir -p wasm/dist
ARGS=( emmake make -j
FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include -I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-Qunused-arguments -Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
-o wasm/dist/ffmpeg-core.js fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
-O3 # optimize code with performance first fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
--closure 1 # code size optimization -o wasm/dist/ffmpeg-core.js
-s USE_SDL=2 # use SDL2 -s USE_SDL=2 # use SDL2
-s USE_PTHREADS=1 # enable pthreads support -s USE_PTHREADS=1 # enable pthreads support
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread -s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
...@@ -22,5 +21,7 @@ ARGS=( ...@@ -22,5 +21,7 @@ ARGS=(
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs -s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs -s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB -s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
$OPTIM_FLAGS
) )
emcc "${ARGS[@]}" echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
emcc "${FLAGS[@]}"
#!/bin/bash -x #!/bin/bash
set -eo pipefail set -euo pipefail
source $(dirname $0)/var.sh
ROOT=$1 X264_PATH=third_party/x264
BUILD_DIR=$2 FLAGS=(
OPT_FLAGS="-O3 --closure 1"
if [[ "$OSTYPE" == "darwin"* ]]; then
# As closure compiler requires java 6 and
# I don't find a way to install it in github actions
OPT_FLAGS="-O3"
fi
cd $ROOT
ARGS=(
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include --prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-gnu # use i686 linux --host=i686-gnu # use i686 linux
--enable-static # enable building static library --enable-static # enable building static library
--disable-cli # disable cli tools --disable-cli # disable cli tools
--disable-asm # disable asm optimization --disable-asm # disable asm optimization
--extra-cflags="-s USE_PTHREADS=1 $OPT_FLAGS" # flags to use pthread and code optimization --extra-cflags="-c -s USE_PTHREADS=1 $OPTIM_FLAGS" # flags to use pthread and code optimization
) )
emconfigure ./configure "${ARGS[@]}" echo "FLAGS=${FLAGS[@]}"
emmake make install-lib-static -j4 (cd $X264_PATH && emconfigure ./configure "${FLAGS[@]}")
cd - emmake make -C $X264_PATH install-lib-static -j
#!/bin/bash -x #!/bin/bash
set -eo pipefail set -euo pipefail
source $(dirname $0)/var.sh
BUILD_DIR=$1 CFLAGS="-s USE_PTHREADS=1 -I$BUILD_DIR/include $OPTIM_FLAGS"
CFLAGS="-s USE_PTHREADS -I$BUILD_DIR/include -O3 --closure 1"
LDFLAGS="$CFLAGS -L$BUILD_DIR/lib" LDFLAGS="$CFLAGS -L$BUILD_DIR/lib"
ARGS=( FLAGS=(
--target-os=none # use none to prevent any os specific configurations --target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization --arch=x86_32 # use x86_32 to achieve minimal architectural optimization
--enable-cross-compile # enable cross compile --enable-cross-compile # enable cross compile
...@@ -17,6 +17,8 @@ ARGS=( ...@@ -17,6 +17,8 @@ ARGS=(
--enable-gpl # required by x264 --enable-gpl # required by x264
--enable-libx264 # enable x264 --enable-libx264 # enable x264
--disable-debug # disable debug info, required by closure --disable-debug # disable debug info, required by closure
--disable-runtime-cpudetect # disable runtime cpu detect
--disable-autodetect # disable external libraries auto detect
--extra-cflags="$CFLAGS" --extra-cflags="$CFLAGS"
--extra-cxxflags="$CFLAGS" --extra-cxxflags="$CFLAGS"
--extra-ldflags="$LDFLAGS" --extra-ldflags="$LDFLAGS"
...@@ -29,4 +31,5 @@ ARGS=( ...@@ -29,4 +31,5 @@ ARGS=(
--objcc=emcc --objcc=emcc
--dep-cc=emcc --dep-cc=emcc
) )
emconfigure ./configure "${ARGS[@]}" echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
emconfigure ./configure "${FLAGS[@]}"
#!/bin/bash -x
set -eo pipefail
emmake make -j4
#!/bin/bash
#
# Common variables for all scripts
set -euo pipefail
# Flags for code optimization, focus on speed instead
# of size
OPTIM_FLAGS=(
-O3
)
# Directory to install headers and libraries
BUILD_DIR=build
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Use closure complier only in linux environment
OPTIM_FLAGS=(
"${OPTIM_FLAGS[@]}"
--closure 1
)
fi
# Convert array to string
OPTIM_FLAGS="${OPTIM_FLAGS[@]}"
echo "OPTIM_FLAGS=$OPTIM_FLAGS"
echo "BUILD_DIR=$BUILD_DIR"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment