Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build-ffmpeg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ jobs:
if: runner.os == 'macOS'
run: |
brew unlink gettext libidn2 libpng libtiff libunistring libx11 libxcb libxdmcp
# Build nasm once for both the manylinux and musllinux containers
- name: Build nasm
if: runner.os == 'Linux' && matrix.arch == 'x86_64'
run: python scripts/build-nasm.py tools/bin
- uses: msys2/setup-msys2@v2
if: runner.os == 'Windows'
with:
Expand All @@ -110,6 +114,8 @@ jobs:
CIBW_BEFORE_BUILD: python scripts/build-ffmpeg.py /tmp/vendor
CIBW_BEFORE_BUILD_WINDOWS: python scripts\build-ffmpeg.py C:\cibw\vendor
CIBW_BUILD: cp312-*
# cibuildwheel copies the project to /project in each container
CIBW_ENVIRONMENT_LINUX: PATH=/project/tools/bin:$PATH
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}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair --add-path C:\cibw\vendor\bin -w {dest_dir} {wheel}
CIBW_TEST_COMMAND: python -c "import dummy"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/dist
/output
/source
/tools
19 changes: 19 additions & 0 deletions scripts/build-ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def make_tarball_name() -> str:
else:
return "ffmpeg-unknown"

def nasm_on_path_is_pinned() -> bool:
"""True if a nasm on PATH reports the version pinned in pkg.py.

CI builds one static nasm for the Linux containers (scripts/build-nasm.py).
Any other nasm is ignored so builds always use the pinned version.
"""
nasm = shutil.which("nasm")
if nasm is None:
return False
pinned = nasm_package.source_url.split("/")[-1].removeprefix("nasm-")
pinned = pinned.split(".tar")[0]
out = subprocess.run([nasm, "-v"], capture_output=True, text=True).stdout
found = out.split()[2] if len(out.split()) > 2 else ""
print(f"nasm on PATH: {nasm} ({found}), pinned: {pinned}")
return found == pinned


def main():
parser = argparse.ArgumentParser("build-ffmpeg")
parser.add_argument("destination")
Expand Down Expand Up @@ -132,6 +149,8 @@ def main():
tools = ["gcc", "g++", "curl", "ld", "nasm", "pkg-config"]
for tool in tools:
run(["where", tool])
elif nasm_on_path_is_pinned():
available_tools.add("nasm")

if plat == "Linux" and (is_musllinux or shutil.which("xxd") is None):
with log_group("install system packages"):
Expand Down
55 changes: 55 additions & 0 deletions scripts/build-nasm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Build a static nasm binary once on the CI host.

On the x86_64 Linux runner, cibuildwheel builds both manylinux and musllinux
in separate containers. Without this, each container would build nasm from
source. A statically linked nasm runs under both glibc and musl, so we build it
here and put it on the containers' PATH (see the workflow). build-ffmpeg.py then
uses it, because it reports the version pinned in pkg.py.
"""

import argparse
import os
import platform
import shutil
import subprocess
import tarfile
import tempfile

from pkg import nasm_package


def main() -> None:
parser = argparse.ArgumentParser("build-nasm")
parser.add_argument("destination", help="directory to put the nasm binary in")
args = parser.parse_args()

dest_dir = os.path.abspath(args.destination)
tarball = os.path.abspath(
os.path.join("source", nasm_package.source_url.split("/")[-1])
)

env = os.environ.copy()
if platform.system() == "Linux":
env["LDFLAGS"] = "-static"

with tempfile.TemporaryDirectory() as tmp:
with tarfile.open(tarball) as tar:
tar.extractall(tmp, filter="data")
(src_dir,) = [os.path.join(tmp, name) for name in os.listdir(tmp)]

# --without-zlib uses nasm's bundled zlib, so no system libz.a is needed
subprocess.run(
["./configure", "--without-zlib"], cwd=src_dir, env=env, check=True
)
subprocess.run(
["make", f"-j{os.cpu_count()}", "nasm"], cwd=src_dir, env=env, check=True
)

os.makedirs(dest_dir, exist_ok=True)
shutil.copy2(os.path.join(src_dir, "nasm"), os.path.join(dest_dir, "nasm"))

subprocess.run([os.path.join(dest_dir, "nasm"), "-v"], check=True)


if __name__ == "__main__":
main()
Loading