Skip to content

Commit d876a70

Browse files
committed
fix(build): add glibc FFmpeg build for Linux native addon linking
The Linux FFmpeg deps were built on Alpine (musl libc) but build-prebuilds links the native addon on Ubuntu (glibc). Static libraries compiled with musl cannot be linked into shared objects on glibc systems, causing: libmp3lame.a: relocation R_X86_64_PC32 against 'stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC Changes: - Add docker/Dockerfile.linux-x64-glibc for Ubuntu 24.04-based builds - Add build-linux-x64-glibc job to build-ffmpeg.yml - Update build-prebuilds.yml to use glibc variant for Linux - Fix nasm download with retries and GitHub mirror fallback The deps-vN releases now include both musl (for standalone binaries) and glibc (for native addon linking) Linux artifacts.
1 parent 38b10a4 commit d876a70

3 files changed

Lines changed: 393 additions & 6 deletions

File tree

.github/workflows/build-ffmpeg.yml

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,80 @@ jobs:
134134
retention-days: 7
135135
compression-level: 0 # Already compressed, faster upload
136136

137+
# ============================================================================
138+
# Linux x64 Build (glibc) - For native addon linking on Ubuntu/Debian
139+
# ============================================================================
140+
# The musl build above produces fully static binaries but its static libraries
141+
# cannot be linked into shared objects on glibc systems. This build produces
142+
# static libraries compatible with glibc for use by build-prebuilds.yml.
143+
# ============================================================================
144+
build-linux-x64-glibc:
145+
name: Build Linux x64 (glibc)
146+
runs-on: ubuntu-24.04
147+
permissions:
148+
contents: read
149+
150+
steps:
151+
- name: Checkout
152+
uses: actions/checkout@v6
153+
154+
- name: Set up Docker Buildx
155+
uses: docker/setup-buildx-action@v3
156+
157+
- name: Build FFmpeg in Ubuntu container
158+
uses: docker/build-push-action@v6
159+
with:
160+
context: .
161+
file: ./docker/Dockerfile.linux-x64-glibc
162+
push: false
163+
load: true
164+
tags: ffmpeg-builder:linux-x64-glibc
165+
cache-from: type=gha,scope=linux-x64-glibc-v${{ env.CACHE_VERSION }}
166+
cache-to: type=gha,mode=max,scope=linux-x64-glibc-v${{ env.CACHE_VERSION }}
167+
168+
- name: Extract binaries and dev files from container
169+
run: |
170+
mkdir -p artifacts/linux-x64-glibc/{bin,lib,include}
171+
docker create --name extract-glibc ffmpeg-builder:linux-x64-glibc
172+
173+
# Extract binaries
174+
docker cp extract-glibc:/build/bin/ffmpeg artifacts/linux-x64-glibc/bin/ffmpeg
175+
docker cp extract-glibc:/build/bin/ffprobe artifacts/linux-x64-glibc/bin/ffprobe
176+
177+
# Extract development files (needed for native addon compilation)
178+
docker cp extract-glibc:/build/lib/. artifacts/linux-x64-glibc/lib/
179+
docker cp extract-glibc:/build/include/. artifacts/linux-x64-glibc/include/
180+
181+
docker rm extract-glibc
182+
183+
# Verify glibc linking (should show libc.so.6)
184+
echo "Verifying glibc binary..."
185+
file artifacts/linux-x64-glibc/bin/ffmpeg
186+
ldd artifacts/linux-x64-glibc/bin/ffmpeg || echo "Note: ldd may fail if glibc versions differ"
187+
188+
# Get version info
189+
chmod +x artifacts/linux-x64-glibc/bin/ffmpeg
190+
./artifacts/linux-x64-glibc/bin/ffmpeg -version > artifacts/linux-x64-glibc/version.txt 2>&1 || true
191+
192+
# Verify dev files extracted
193+
echo "=== Library files ==="
194+
ls -la artifacts/linux-x64-glibc/lib/
195+
echo "=== Pkgconfig files ==="
196+
ls -la artifacts/linux-x64-glibc/lib/pkgconfig/ || echo "Warning: No pkgconfig directory"
197+
198+
- name: Package artifacts
199+
run: |
200+
cd artifacts
201+
tar -cvf linux-x64-glibc.tar linux-x64-glibc/
202+
203+
- name: Upload artifact
204+
uses: actions/upload-artifact@v6
205+
with:
206+
name: ffmpeg-linux-x64-glibc
207+
path: artifacts/linux-x64-glibc.tar
208+
retention-days: 7
209+
compression-level: 0
210+
137211
# ============================================================================
138212
# macOS Builds - Native runners for both architectures
139213
# ============================================================================
@@ -195,8 +269,22 @@ jobs:
195269
rm -rf x264 x265_git libvpx aom aom_build opus-* lame-* nasm-*
196270
197271
echo "=== Building nasm ==="
198-
curl -sL https://www.nasm.us/pub/nasm/releasebuilds/2.16.03/nasm-2.16.03.tar.bz2 | tar xj
199-
cd nasm-2.16.03
272+
NASM_VERSION="2.16.03"
273+
NASM_URL="https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.bz2"
274+
NASM_GITHUB="https://github.com/netwide-assembler/nasm/archive/refs/tags/nasm-${NASM_VERSION}.tar.gz"
275+
276+
# Try primary source with retries, fallback to GitHub mirror
277+
if curl -fSL --retry 3 --retry-delay 5 "$NASM_URL" -o nasm.tar.bz2 2>/dev/null; then
278+
echo "Downloaded nasm from primary source"
279+
tar xjf nasm.tar.bz2
280+
else
281+
echo "Primary nasm download failed, trying GitHub mirror..."
282+
curl -fSL --retry 3 "$NASM_GITHUB" -o nasm.tar.gz
283+
tar xzf nasm.tar.gz
284+
mv nasm-nasm-${NASM_VERSION} nasm-${NASM_VERSION}
285+
fi
286+
287+
cd nasm-${NASM_VERSION}
200288
./configure --prefix="$TARGET"
201289
make -j$(sysctl -n hw.ncpu)
202290
make install
@@ -795,7 +883,7 @@ jobs:
795883
release-deps:
796884
name: Create Dependencies Release
797885
runs-on: ubuntu-24.04
798-
needs: [build-linux-x64, build-macos]
886+
needs: [build-linux-x64, build-linux-x64-glibc, build-macos]
799887
# Run if: manually triggered with deps_version input OR tag push matches deps-*
800888
if: inputs.deps_version != '' || startsWith(github.ref, 'refs/tags/deps-')
801889
permissions:
@@ -879,7 +967,7 @@ jobs:
879967
ls -la release/
880968
881969
# Verify all expected platforms present and have correct structure
882-
for platform in linux-x64 darwin-x64 darwin-arm64; do
970+
for platform in linux-x64 linux-x64-glibc darwin-x64 darwin-arm64; do
883971
if [ ! -f "release/ffmpeg-${platform}.tar.gz" ]; then
884972
echo "ERROR: Missing ffmpeg-${platform}.tar.gz"
885973
exit 1
@@ -903,10 +991,14 @@ jobs:
903991
**Do not use directly** - these are consumed by `ci.yml` and `build-prebuilds.yml`.
904992
905993
### Files
906-
- `ffmpeg-linux-x64.tar.gz` - Linux x64 (musl, fully static)
994+
- `ffmpeg-linux-x64.tar.gz` - Linux x64 (musl, fully static binaries)
995+
- `ffmpeg-linux-x64-glibc.tar.gz` - Linux x64 (glibc, for native addon linking)
907996
- `ffmpeg-darwin-x64.tar.gz` - macOS Intel
908997
- `ffmpeg-darwin-arm64.tar.gz` - macOS Apple Silicon
909998
999+
**Note:** `build-prebuilds.yml` uses `linux-x64-glibc` for native addon builds because
1000+
musl-compiled static libraries cannot be linked into shared objects on glibc systems.
1001+
9101002
### Codec Versions
9111003
- FFmpeg: ${{ env.FFMPEG_VERSION }}
9121004
- x264: ${{ env.X264_VERSION }}

.github/workflows/build-prebuilds.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ jobs:
8989
with:
9090
repo: ${{ github.repository }}
9191
version: tags/deps-${{ env.DEPS_VERSION }}
92-
file: ffmpeg-${{ matrix.platform }}.tar.gz
92+
# Use glibc variant for Linux (musl libs can't link into glibc shared objects)
93+
file: ffmpeg-${{ matrix.platform }}${{ runner.os == 'Linux' && '-glibc' || '' }}.tar.gz
9394
target: ffmpeg-${{ matrix.platform }}.tar.gz
9495
token: ${{ secrets.GITHUB_TOKEN }}
9596

0 commit comments

Comments
 (0)