From 39ec37c17d122da0c98c3279e6a6b0f4efb75c4a Mon Sep 17 00:00:00 2001 From: omartijn <44672243+omartijn@users.noreply.github.com> Date: Fri, 10 Jul 2026 02:28:55 +0200 Subject: [PATCH] [ffmpeg] support GNU-frontend clang and non-Windows hosts for Windows targets (#52810) Co-authored-by: Martijn Otto Co-authored-by: Claude Fable 5 --- ports/ffmpeg/portfile.cmake | 26 ++++++++++++++++++++++++-- ports/ffmpeg/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/f-/ffmpeg.json | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ports/ffmpeg/portfile.cmake b/ports/ffmpeg/portfile.cmake index 5d634064db..fa73a16e0f 100644 --- a/ports/ffmpeg/portfile.cmake +++ b/ports/ffmpeg/portfile.cmake @@ -104,7 +104,11 @@ if(VCPKG_DETECTED_CMAKE_RC_COMPILER) list(APPEND prog_env "${RC_path}") endif() -if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) +# A GNU-frontend clang links through the compiler driver (the detected +# CMAKE_LINKER flags are driver-style, not lld-link-style), so leave +# configure's default LD=CC in place there. +if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW + AND NOT VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "clang(-[0-9]+)?(\\.exe)?$") get_filename_component(LD_path "${VCPKG_DETECTED_CMAKE_LINKER}" DIRECTORY) get_filename_component(LD_filename "${VCPKG_DETECTED_CMAKE_LINKER}" NAME) set(ENV{LD} "${LD_filename}") @@ -856,15 +860,33 @@ if(VCPKG_TARGET_IS_WINDOWS) message(FATAL_ERROR "Unsupported target architecture") endif() + # llvm-lib implements the lib.exe interface; use it when building on + # a host without the MSVC tools + if(CMAKE_HOST_WIN32) + set(LIB_TOOL lib.exe) + else() + find_program(LIB_TOOL NAMES llvm-lib llvm-lib-22 llvm-lib-19 REQUIRED) + endif() foreach(DEF_FILE ${DEF_FILES}) get_filename_component(DEF_FILE_DIR "${DEF_FILE}" DIRECTORY) get_filename_component(DEF_FILE_NAME "${DEF_FILE}" NAME) string(REGEX REPLACE "-[0-9]*\\.def" "${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}" OUT_FILE_NAME "${DEF_FILE_NAME}") + if(NOT CMAKE_HOST_WIN32) + # ffmpeg's makedef emits no LIBRARY statement; lib.exe infers the + # DLL name from the def filename but llvm-lib leaves it EMPTY, + # producing import entries no Windows loader can resolve. + get_filename_component(DEF_BASE_NAME "${DEF_FILE}" NAME_WE) + file(READ "${DEF_FILE}" DEF_CONTENTS) + if(NOT DEF_CONTENTS MATCHES "LIBRARY") + file(WRITE "${CURRENT_BUILDTREES_DIR}/${DEF_FILE_NAME}" "LIBRARY ${DEF_BASE_NAME}\n${DEF_CONTENTS}") + set(DEF_FILE "${CURRENT_BUILDTREES_DIR}/${DEF_FILE_NAME}") + endif() + endif() file(TO_NATIVE_PATH "${DEF_FILE}" DEF_FILE_NATIVE) file(TO_NATIVE_PATH "${DEF_FILE_DIR}/${OUT_FILE_NAME}" OUT_FILE_NATIVE) message(STATUS "Generating ${OUT_FILE_NATIVE}") vcpkg_execute_required_process( - COMMAND lib.exe "/def:${DEF_FILE_NATIVE}" "/out:${OUT_FILE_NATIVE}" ${LIB_MACHINE_ARG} + COMMAND "${LIB_TOOL}" "/def:${DEF_FILE_NATIVE}" "/out:${OUT_FILE_NATIVE}" ${LIB_MACHINE_ARG} WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}" LOGNAME "libconvert-${TARGET_TRIPLET}" ) diff --git a/ports/ffmpeg/vcpkg.json b/ports/ffmpeg/vcpkg.json index 8c365829e3..c880e29092 100644 --- a/ports/ffmpeg/vcpkg.json +++ b/ports/ffmpeg/vcpkg.json @@ -1,7 +1,7 @@ { "name": "ffmpeg", "version": "8.1.2", - "port-version": 2, + "port-version": 3, "description": [ "A library to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created.", "FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations." diff --git a/versions/baseline.json b/versions/baseline.json index 02c6d77cb2..35d588a93d 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -3042,7 +3042,7 @@ }, "ffmpeg": { "baseline": "8.1.2", - "port-version": 2 + "port-version": 3 }, "ffmpeg-bin2c": { "baseline": "8.1.1", diff --git a/versions/f-/ffmpeg.json b/versions/f-/ffmpeg.json index 1abbf274e9..c7d9456769 100644 --- a/versions/f-/ffmpeg.json +++ b/versions/f-/ffmpeg.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "c40aaa40e075d25ef1e812daa7333778890b6b0d", + "version": "8.1.2", + "port-version": 3 + }, { "git-tree": "62cece738a9900d0574d426a81228e47e4a4f664", "version": "8.1.2",