Skip to content

Commit e8e08a9

Browse files
Support more architectures
Signed-off-by: 吴小白 <296015668@qq.com>
1 parent 9e63121 commit e8e08a9

File tree

4 files changed

+153
-6
lines changed

4 files changed

+153
-6
lines changed

.github/workflows/build-ffmpeg.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,42 @@ jobs:
8585
with:
8686
name: output-${{ matrix.os }}
8787
path: output/
88+
89+
cross-build:
90+
runs-on: ${{ matrix.os }}
91+
strategy:
92+
fail-fast: false
93+
matrix:
94+
os: [ "ubuntu-24.04" ]
95+
build: [ "manylinux_", "musllinux_" ]
96+
# arch: [ "loongarch64", "ppc64le", "riscv64", "s390x" ]
97+
arch: [ "ppc64le" ]
98+
steps:
99+
- uses: actions/checkout@v6
100+
- uses: actions/setup-python@v6
101+
with:
102+
python-version: "3.13"
103+
- uses: docker/setup-qemu-action@v3
104+
- name: Build FFmpeg
105+
env:
106+
CIBW_ARCHS: ${{ matrix.arch }}
107+
CIBW_BEFORE_ALL_LINUX: ./scripts/install-static-clang.sh
108+
CIBW_BEFORE_BUILD_LINUX: python scripts/build-ffmpeg.py /tmp/vendor --community
109+
CIBW_BUILD: cp311-${{ matrix.build }}${{ matrix.arch }}
110+
CIBW_ENVIRONMENT_LINUX: >
111+
CC="/opt/clang/bin/clang"
112+
CXX="/opt/clang/bin/clang++"
113+
LDFLAGS="-fuse-ld=lld"
114+
CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_ARCH
115+
CIBW_REPAIR_WHEEL_COMMAND_LINUX: LD_LIBRARY_PATH=/tmp/vendor/lib:$LD_LIBRARY_PATH auditwheel repair --exclude libmvec.so.1 --exclude libmvec-2.so --exclude libmvec.so --exclude libmvec -w {dest_dir} {wheel}
116+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair --add-path C:\cibw\vendor\bin -w {dest_dir} {wheel}
117+
CIBW_TEST_COMMAND: python -c "import dummy"
118+
run: |
119+
pip install cibuildwheel delvewheel
120+
cibuildwheel --output-dir output
121+
rm -f output/*.whl
122+
- name: Upload FFmpeg
123+
uses: actions/upload-artifact@v6
124+
with:
125+
name: output-${{ matrix.build }}${{ matrix.arch }}
126+
path: output/

scripts/build-ffmpeg.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,19 @@ def download_tars(packages: list[Package]) -> None:
274274
raise
275275

276276
def make_tarball_name() -> str:
277-
isArm64 = platform.machine() in {"arm64", "aarch64"}
277+
machine = platform.machine().lower()
278+
isArm64 = machine in {"arm64", "aarch64"}
278279

279280
if sys.platform.startswith("win"):
280281
return "ffmpeg-windows-aarch64" if isArm64 else "ffmpeg-windows-x86_64"
281-
elif sys.platform.startswith("linux"):
282-
if is_musllinux:
283-
return "ffmpeg-musllinux-aarch64" if isArm64 else "ffmpeg-musllinux-x86_64"
284-
else:
285-
return "ffmpeg-manylinux-aarch64" if isArm64 else "ffmpeg-manylinux-x86_64"
282+
286283
elif sys.platform.startswith("darwin"):
287284
return "ffmpeg-macos-arm64" if isArm64 else "ffmpeg-macos-x86_64"
285+
286+
elif sys.platform.startswith("linux"):
287+
prefix = "ffmpeg-musllinux-" if is_musllinux else "ffmpeg-manylinux-"
288+
return prefix + machine
289+
288290
else:
289291
return "ffmpeg-unknown"
290292

@@ -403,6 +405,17 @@ def main():
403405
]
404406
)
405407

408+
if plat == "Linux" and "RUNNER_ARCH" in os.environ:
409+
ffmpeg_package.build_arguments.extend(
410+
[
411+
"--enable-cross-compile",
412+
"--target-os=linux",
413+
"--arch=" + platform.machine().lower(),
414+
"--cc=/opt/clang/bin/clang",
415+
"--cxx=/opt/clang/bin/clang++",
416+
]
417+
)
418+
406419
ffmpeg_package.build_arguments.extend(
407420
[
408421
"--disable-encoder=avui,dca,mlp,opus,s302m,sonic,sonic_ls,truehd,vorbis",

scripts/cibuildpkg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ def _build_with_autoconf(self, package: Package, for_builder: bool) -> None:
226226
configure_args += ["--target=x86_64-darwin20-gcc"]
227227
elif platform.system() == "Windows":
228228
configure_args += ["--target=x86_64-win64-gcc"]
229+
elif platform.system() == "Linux":
230+
if "RUNNER_ARCH" in os.environ:
231+
prepend_env(env, "CFLAGS", "-pthread")
232+
prepend_env(env, "CXXFLAGS", "-pthread")
233+
prepend_env(env, "LDFLAGS", "-pthread")
229234

230235
if package.name == "ffmpeg" and platform.system() == "Windows":
231236
prepend_env(env, "LDFLAGS", "-LC:/PROGRA~1/OpenSSL/lib")

scripts/install-static-clang.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# Stop at any error, show all commands
4+
set -exuo pipefail
5+
6+
TOOLCHAIN_PATH=/opt/clang
7+
8+
# Download static-clang
9+
DEFAULT_ARCH="$(uname -m)"
10+
if [ "${STATIC_CLANG_ARCH:-}" == "" ]; then
11+
STATIC_CLANG_ARCH="${RUNNER_ARCH:-${DEFAULT_ARCH}}"
12+
fi
13+
case "${STATIC_CLANG_ARCH}" in
14+
ARM64|aarch64|arm64|arm64/*) GO_ARCH=arm64;;
15+
ARM|armv7l|armv8l|arm|arm/v7) GO_ARCH=arm;; # assume arm/v7 for arm
16+
X64|x86_64|amd64|amd64/*) GO_ARCH=amd64;;
17+
X86|i686|386) GO_ARCH=386;;
18+
ppc64le) GO_ARCH=ppc64le;;
19+
riscv64) GO_ARCH=riscv64;;
20+
s390x) GO_ARCH=s390x;;
21+
*) echo "No static-clang toolchain for ${CLANG_ARCH}">2; exit 1;;
22+
esac
23+
STATIC_CLANG_VERSION=21.1.8.1
24+
STATIC_CLANG_FILENAME="static-clang-linux-${GO_ARCH}.tar.xz"
25+
STATIC_CLANG_URL="https://github.com/mayeut/static-clang-images/releases/download/v${STATIC_CLANG_VERSION}/${STATIC_CLANG_FILENAME}"
26+
pushd /tmp
27+
cat<<'EOF' | grep "${STATIC_CLANG_FILENAME}" > "${STATIC_CLANG_FILENAME}.sha256"
28+
583980309e73fa753c0791e05deceac7cb06c5444956d61189f1d651941bcd8e static-clang-linux-386.tar.xz
29+
f539f1fd24bcc07ecc220594022907865914236540091fbf189cb496a9a3751c static-clang-linux-amd64.tar.xz
30+
d0c8b7fac4734cc8048fda3b1f33ccdf24d26f81a52df53348e5fa84ab4b203a static-clang-linux-arm.tar.xz
31+
57fb9cf798b3a2c4b0f3c31c0b7fe3803b5319d2af075407e1aef0cd57882f65 static-clang-linux-arm64.tar.xz
32+
5a2b296e9030d0320d9e4eac8859e5db0504cf1d4169981af233cb339292fa4c static-clang-linux-loong64.tar.xz
33+
c8541b2d36f0fd8f13ddabe1292b6fb7550a742e76e0f1f70fb29fcee073be4a static-clang-linux-ppc64le.tar.xz
34+
b311137f955b55139b02e8c1d7ec259628404a0563d136df7a817a33784bd2bf static-clang-linux-riscv64.tar.xz
35+
de74fd8e5de244d36398684b2afa67add2311df6ccfa24f3c08a1d777ca814fa static-clang-linux-s390x.tar.xz
36+
EOF
37+
curl -fsSLO "${STATIC_CLANG_URL}"
38+
sha256sum -c "${STATIC_CLANG_FILENAME}.sha256"
39+
tar -C /opt -xf "${STATIC_CLANG_FILENAME}"
40+
popd
41+
42+
# configure target triple
43+
case "${AUDITWHEEL_POLICY}-${AUDITWHEEL_ARCH}" in
44+
manylinux*-armv7l) TARGET_TRIPLE=armv7-unknown-linux-gnueabihf;;
45+
musllinux*-armv7l) TARGET_TRIPLE=armv7-alpine-linux-musleabihf;;
46+
manylinux*-ppc64le) TARGET_TRIPLE=powerpc64le-unknown-linux-gnu;;
47+
musllinux*-ppc64le) TARGET_TRIPLE=powerpc64le-alpine-linux-musl;;
48+
manylinux*-*) TARGET_TRIPLE=${AUDITWHEEL_ARCH}-unknown-linux-gnu;;
49+
musllinux*-*) TARGET_TRIPLE=${AUDITWHEEL_ARCH}-alpine-linux-musl;;
50+
esac
51+
case "${AUDITWHEEL_POLICY}-${AUDITWHEEL_ARCH}" in
52+
*-riscv64) M_ARCH="-march=rv64gc";;
53+
*-x86_64) M_ARCH="-march=x86-64";;
54+
*-armv7l) M_ARCH="-march=armv7a";;
55+
manylinux*-i686) M_ARCH="-march=k8 -mtune=generic";; # same as gcc manylinux2014 / manylinux_2_28
56+
musllinux*-i686) M_ARCH="-march=pentium-m -mtune=generic";; # same as gcc musllinux_1_2
57+
esac
58+
GCC_TRIPLE=$(gcc -dumpmachine)
59+
60+
cat<<EOF >"${TOOLCHAIN_PATH}/bin/${AUDITWHEEL_PLAT}.cfg"
61+
-target ${TARGET_TRIPLE}
62+
${M_ARCH:-}
63+
--gcc-toolchain=${DEVTOOLSET_ROOTPATH:-}/usr
64+
--gcc-triple=${GCC_TRIPLE}
65+
EOF
66+
67+
cat<<EOF >"${TOOLCHAIN_PATH}/bin/clang.cfg"
68+
@${AUDITWHEEL_PLAT}.cfg
69+
EOF
70+
71+
cat<<EOF >"${TOOLCHAIN_PATH}/bin/clang++.cfg"
72+
@${AUDITWHEEL_PLAT}.cfg
73+
EOF
74+
75+
cat<<EOF >"${TOOLCHAIN_PATH}/bin/clang-cpp.cfg"
76+
@${AUDITWHEEL_PLAT}.cfg
77+
EOF
78+
79+
# override entrypoint to add the toolchain to PATH
80+
mv /usr/local/bin/manylinux-entrypoint /usr/local/bin/manylinux-entrypoint-org
81+
cat<<EOF >/usr/local/bin/manylinux-entrypoint
82+
#!/bin/bash
83+
84+
set -eu
85+
86+
export PATH="${TOOLCHAIN_PATH}/bin:\${PATH}"
87+
exec /usr/local/bin/manylinux-entrypoint-org "\$@"
88+
EOF
89+
90+
chmod +x /usr/local/bin/manylinux-entrypoint

0 commit comments

Comments
 (0)