Skip to content

Commit 08954eb

Browse files
committed
refactor: streamline ffmpeg binary packaging and simplify config parsing
1 parent 96cd6be commit 08954eb

5 files changed

Lines changed: 83 additions & 163 deletions

File tree

‎.github/workflows/onestep.sh‎

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
set -e
88
set -o pipefail
99

10-
export LIB_NAME=$1
10+
export CONFIG_NAME=$1
1111
export PLAT=$2
12+
export MR_PLAT=$PLAT
1213

1314
if [[ -n $3 && "$3" == 'true' ]];then
1415
export DRYRUN=1
@@ -24,10 +25,12 @@ fi
2425

2526
export HOMEBREW_NO_AUTO_UPDATE=1
2627
export RELEASE_DATE=$(TZ=UTC-8 date +'%y%m%d%H%M%S')
27-
export RELEASE_VERSION=$(grep GIT_REPO_VERSION= ./configs/libs/${LIB_NAME}.sh | tail -n 1 | awk -F = '{printf "%s",$2}')
28-
export REPO_DIR=$(grep REPO_DIR= ./configs/libs/${LIB_NAME}.sh | tail -n 1 | awk -F = '{printf "%s",$2}' | tr -d "'\"")
28+
29+
source ./configs/libs/${CONFIG_NAME}.sh
30+
export RELEASE_VERSION=$GIT_REPO_VERSION
2931
export TAG=${LIB_NAME}-${RELEASE_VERSION}-${RELEASE_DATE}
30-
export TITLE="👏👏${LIB_NAME}-${PLAT}-${RELEASE_VERSION}"
32+
33+
export TITLE="👏👏${CONFIG_NAME}-${PLAT}-${RELEASE_VERSION}"
3134

3235
ROOT_DIR=$PWD
3336
DIST_DIR=$ROOT_DIR/build/dist
@@ -37,7 +40,7 @@ function init_platform
3740
{
3841
local plat=$1
3942
echo "---init $plat src--------------------------------------"
40-
./main.sh init -p $plat -l ${LIB_NAME}
43+
./main.sh init -p $plat -l ${CONFIG_NAME}
4144

4245
echo "---generate src log--------------------------------------"
4346
cd build/src/$plat
@@ -52,9 +55,9 @@ function compile_ios_platform
5255
local log_file="$DIST_DIR/ios-compile-log-$RELEASE_VERSION.md"
5356

5457
if [[ $VERBOSE ]];then
55-
./main.sh compile -p ios -c build -l ${LIB_NAME} 2>&1 | tee -a "$log_file"
58+
./main.sh compile -p ios -c build -l ${CONFIG_NAME} 2>&1 | tee -a "$log_file"
5659
else
57-
./main.sh compile -p ios -c build -l ${LIB_NAME} >> "$log_file" 2>&1
60+
./main.sh compile -p ios -c build -l ${CONFIG_NAME} >> "$log_file" 2>&1
5861
fi
5962

6063
cd build/product/ios/universal
@@ -74,41 +77,36 @@ function compile_macos_platform
7477
local extra_args=""
7578

7679
if [[ $VERBOSE ]];then
77-
./main.sh compile -p macos -c build -l ${LIB_NAME} $extra_args 2>&1 | tee -a "$log_file"
80+
./main.sh compile -p macos -c build -l ${CONFIG_NAME} $extra_args 2>&1 | tee -a "$log_file"
7881
else
79-
./main.sh compile -p macos -c build -l ${LIB_NAME} $extra_args >> "$log_file" 2>&1
82+
./main.sh compile -p macos -c build -l ${CONFIG_NAME} $extra_args >> "$log_file" 2>&1
8083
fi
8184

82-
# Copy the architecture-specific binaries to universal/bin before zipping if they were compiled
83-
if [[ "$REPO_DIR" == "ffmpeg8" ]]; then
84-
mkdir -p build/product/macos/universal/bin
85+
# Copy the architecture-specific binaries if they were compiled
86+
if [[ "$ENABLE_BIN" == "1" ]]; then
87+
mkdir -p build/product/macos/universal/${LIB_NAME}/bin
8588
for arch in arm64 x86_64; do
86-
for bin in ffmpeg ffplay ffprobe; do
87-
local bin_file="build/product/macos/${LIB_NAME}-${arch}/bin/$bin"
88-
if [ -f "$bin_file" ]; then
89-
cp "$bin_file" "build/product/macos/universal/bin/$bin-macos-${arch}"
90-
echo "Copied $bin_file to build/product/macos/universal/bin/$bin-macos-${arch}"
91-
fi
92-
done
89+
local bin_dir="build/product/macos/${LIB_NAME}-${arch}/bin"
90+
if [ -d "$bin_dir" ]; then
91+
for bin_path in "$bin_dir"/*; do
92+
if [ -f "$bin_path" ]; then
93+
local bin=$(basename "$bin_path")
94+
# 1. Copy to universal folder before zipping
95+
cp "$bin_path" "build/product/macos/universal/${LIB_NAME}/bin/$bin-macos-${arch}"
96+
echo "Copied $bin_path to build/product/macos/universal/${LIB_NAME}/bin/$bin-macos-${arch}"
97+
98+
# 2. Copy to release assets directory
99+
cp "$bin_path" "$DIST_DIR/$bin-macos-${arch}"
100+
echo "Copied $bin_path to $DIST_DIR/$bin-macos-${arch}"
101+
fi
102+
done
103+
fi
93104
done
94105
fi
95106

96107
cd build/product/macos/universal
97108
zip -ryq $DIST_DIR/${LIB_NAME}-macos-universal-${RELEASE_VERSION}.zip ./*
98109
cd $ROOT_DIR
99-
100-
# Copy the architecture-specific binaries to release assets if they were compiled
101-
if [[ "$REPO_DIR" == "ffmpeg8" ]]; then
102-
for arch in arm64 x86_64; do
103-
for bin in ffmpeg ffplay ffprobe; do
104-
local bin_file="build/product/macos/${LIB_NAME}-${arch}/bin/$bin"
105-
if [ -f "$bin_file" ]; then
106-
cp "$bin_file" "$DIST_DIR/$bin-macos-${arch}"
107-
echo "Copied $bin_file to $DIST_DIR/$bin-macos-${arch}"
108-
fi
109-
done
110-
done
111-
fi
112110
}
113111

114112
function compile_tvos_platform
@@ -118,9 +116,9 @@ function compile_tvos_platform
118116
local log_file="$DIST_DIR/android-compile-log-$RELEASE_VERSION.md"
119117

120118
if [[ $VERBOSE ]];then
121-
./main.sh compile -p tvos -c build -l ${LIB_NAME} 2>&1 | tee -a "$log_file"
119+
./main.sh compile -p tvos -c build -l ${CONFIG_NAME} 2>&1 | tee -a "$log_file"
122120
else
123-
./main.sh compile -p tvos -c build -l ${LIB_NAME} >> "$log_file" 2>&1
121+
./main.sh compile -p tvos -c build -l ${CONFIG_NAME} >> "$log_file" 2>&1
124122
fi
125123

126124
cd build/product/tvos/universal
@@ -137,11 +135,11 @@ function compile_android_platform
137135
echo "---do compile android libs--------------------------------------"
138136

139137
local log_file="$DIST_DIR/android-compile-log-$RELEASE_VERSION.md"
140-
138+
141139
if [[ $VERBOSE ]];then
142-
./main.sh compile -p android -c build -l ${LIB_NAME} 2>&1 | tee -a "$log_file"
140+
./main.sh compile -p android -c build -l ${CONFIG_NAME} 2>&1 | tee -a "$log_file"
143141
else
144-
./main.sh compile -p android -c build -l ${LIB_NAME} >> "$log_file" 2>&1
142+
./main.sh compile -p android -c build -l ${CONFIG_NAME} >> "$log_file" 2>&1
145143
fi
146144

147145
cd build/product/android/universal
@@ -176,7 +174,7 @@ function replace_tag()
176174

177175
function upgrade()
178176
{
179-
local file="configs/libs/${LIB_NAME}.sh"
177+
local file="configs/libs/${CONFIG_NAME}.sh"
180178
case $PLAT in
181179
ios)
182180
replace_tag $file PRE_COMPILE_TAG_IOS
@@ -204,7 +202,7 @@ function upgrade()
204202
esac
205203

206204
git add $file
207-
git commit -m "upgrade $LIB_NAME to $TAG for $PLAT by cd"
205+
git commit -m "upgrade $CONFIG_NAME to $TAG for $PLAT by cd"
208206
git pull --rebase
209207
git push origin
210208
}
@@ -273,9 +271,4 @@ function main()
273271
esac
274272
}
275273

276-
if [[ $LIB_NAME == 'test' ]];then
277-
echo "test" > $DIST_DIR/test.md
278-
publish
279-
else
280-
main
281-
fi
274+
main

‎configs/libs/ffmpeg8-bin.sh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export LIB_NAME='ffmpeg8-bin'
1+
export LIB_NAME='ffmpeg'
2+
export ENABLE_BIN=1
23

34
if [[ "$MR_PLAT" != "macos" ]]; then
45
echo "❌ ffmpeg8-bin is only supported on the macos platform."
@@ -8,7 +9,7 @@ fi
89
export LIPO_LIBS=""
910
export LIB_DEPENDS_BIN="nasm pkg-config"
1011
export GIT_LOCAL_REPO=extra/ffmpeg
11-
export REPO_DIR=ffmpeg8
12+
export REPO_DIR=ffmpeg8-bin
1213
export PATCH_DIR=../../patches/ffmpeg8-bin
1314
export GIT_COMMIT=n8.1.2
1415
export GIT_REPO_VERSION=8.1.2

‎do-compile/apple/ffmpeg.sh‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,52 @@ THIS_DIR=$(DIRNAME=$(dirname "$0"); cd "$DIRNAME"; pwd)
3131
cd "$THIS_DIR"
3232

3333
# ffmpeg config options
34-
source $MR_SHELL_CONFIGS_DIR/ffconfig/module-full.sh
34+
if [[ "$ENABLE_BIN" == "1" ]]; then
35+
source $MR_SHELL_CONFIGS_DIR/ffconfig/module-program.sh
36+
37+
# Prep PKG_CONFIG_PATH with our built universal products
38+
for d in "$MR_PRODUCT_ROOT/universal"/*; do
39+
if [[ -d "$d/lib/pkgconfig" ]]; then
40+
export PKG_CONFIG_PATH="$d/lib/pkgconfig:$PKG_CONFIG_PATH"
41+
fi
42+
done
43+
else
44+
source $MR_SHELL_CONFIGS_DIR/ffconfig/module-full.sh
45+
fi
46+
3547
source $MR_SHELL_CONFIGS_DIR/ffconfig/auto-detect-third-libs.sh
3648

3749
CFG_FLAGS=
3850
CFG_FLAGS="$CFG_FLAGS $COMMON_FF_CFG_FLAGS"
3951
CFG_FLAGS="$CFG_FLAGS $THIRD_CFG_FLAGS"
4052

53+
if [[ "$ENABLE_BIN" == "1" ]]; then
54+
# If sdl2 is not found on host, disable sdl2 and ffplay
55+
if ! pkg-config --exists sdl2 2>/dev/null; then
56+
echo "[!] SDL2 not found, disabling sdl2 and ffplay"
57+
CFG_FLAGS="$CFG_FLAGS --disable-sdl2 --disable-ffplay"
58+
fi
59+
fi
60+
4161
C_FLAGS="$MR_DEFAULT_CFLAGS"
42-
LDFLAGS="$C_FLAGS"
62+
63+
if [[ "$ENABLE_BIN" == "1" ]]; then
64+
EXTRA_LDFLAGS=
65+
# Dynamically query pkg-config to link all available third party static libraries
66+
pkgs="libx264 libx265 libass libbluray dav1d dvdread dvdnav freetype2 fribidi harfbuzz openssl opus libsmb2 uavs3d libunibreak libxml-2.0 libwebp libwebpdecoder libwebpdemux"
67+
enabled_pkgs=""
68+
for pkg in $pkgs; do
69+
if pkg-config --exists "$pkg" 2>/dev/null; then
70+
enabled_pkgs="$enabled_pkgs $pkg"
71+
fi
72+
done
73+
if [ -n "$enabled_pkgs" ]; then
74+
EXTRA_LDFLAGS=$(pkg-config --static --libs $enabled_pkgs)
75+
fi
76+
LDFLAGS="$C_FLAGS $EXTRA_LDFLAGS"
77+
else
78+
LDFLAGS="$C_FLAGS"
79+
fi
4380
# C_FLAGS="$C_FLAGS -I/Users/matt/GitWorkspace/MoltenVK/Package/Release/MoltenVK/include"
4481
# use system xml2 lib
4582
# C_FLAGS="$C_FLAGS $(xml2-config --prefix=${MR_SYS_ROOT}/usr --cflags)"

‎do-compile/apple/ffmpeg8-bin.sh‎

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

‎do-install/main.sh‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ function parse_lib_config() {
3232
exit
3333
fi
3434

35-
export TAG=$vt
3635
# opus-1.3.1-231124151836
3736
# yuv-stable-eb6e7bb-250225223408
38-
LIB_NAME=$(echo $TAG | awk -F - '{print $1}')
37+
export TAG=$vt
38+
3939
local prefix="${LIB_NAME}-"
4040
local suffix=$(echo $TAG | awk -F - '{printf "-%s", $NF}')
4141
# 去掉前缀
4242
local temp=${TAG#$prefix}
4343
# 去掉后缀
44-
VER=${temp%$suffix}
45-
46-
export VER
47-
export LIB_NAME
44+
export VER=${temp%$suffix}
4845
}
4946

5047
function do_install_a_lib()

0 commit comments

Comments
 (0)