From 5ff68a62040fabf4fc9f01a97119fb1d9352e1ed Mon Sep 17 00:00:00 2001 From: star9029 Date: Tue, 31 Dec 2024 23:15:15 +0800 Subject: [PATCH 1/6] ffmpeg: Fix build on msys2 --- packages/f/ffmpeg/xmake.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index 0e5b8781e60..4116ee9d887 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -117,11 +117,20 @@ package("ffmpeg") package:add("syslinks", "Bcrypt", "Mfplat", "mfuuid", "Ole32", "Secur32", "Strmiids", "User32", "ws2_32") end if is_subhost("windows") and os.arch() == "x64" then - if package:is_plat("windows", "mingw") then - package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}}) - else - package:add("deps", "msys2", {configs = {msystem = "MINGW64", mingw64_gcc = true, base_devel = true}}) + local configs = { + msystem = "MINGW64", + base_devel = true, + } + -- @see https://stackoverflow.com/questions/65438878/ffmpeg-build-on-windows-using-msvc-make-fails + configs.make = true + if not package:is_plat("windows", "mingw") then + configs.mingw64_gcc = true end + package:add("deps", "msys2", {configs = configs}) + end + + if not package:is_cross() then + package:addenv("PATH", "bin") end end) @@ -158,6 +167,7 @@ package("ffmpeg") table.insert(configs, "--enable-dxva2") table.insert(configs, "--enable-mediafoundation") table.insert(configs, "--toolchain=msvc") + table.insert(configs, "--extra-cflags=-" .. package:config("runtimes")) elseif package:is_plat("mingw") then if package:is_arch("x86", "i386", "i686") then table.insert(configs, "--target-os=mingw32") @@ -336,9 +346,18 @@ package("ffmpeg") end import("package.tools.autoconf").install(package, configs, opt) end - package:addenv("PATH", "bin") end) on_test(function (package) - assert(package:has_cfuncs("avformat_open_input", {includes = "libavformat/avformat.h"})) + if not package:is_cross() then + for _, tool in ipairs({"ffprobe", "ffmpeg", "ffplay"}) do + if package:config(tool) then + os.vrunv(tool, {"-version"}) + end + end + end + + if package:is_library() then + assert(package:has_cfuncs("avformat_open_input", {includes = "libavformat/avformat.h"})) + end end) From b82c713c2c0ed9e9dbf1e4495c5bc4b5adf7e1fe Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 1 Jan 2025 00:41:19 +0800 Subject: [PATCH 2/6] Fix cross-compilation with windows plat --- packages/f/ffmpeg/xmake.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index 4116ee9d887..8218ceb66a8 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -216,6 +216,11 @@ package("ffmpeg") if path.cygwin then -- xmake 2.8.9 import("package.tools.autoconf") local envs = autoconf.buildenvs(package, {packagedeps = "libiconv"}) + if not envs.PATH then -- Fix in xmake 2.9.8 + local msvc = package:toolchain("msvc") or toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) + envs.PATH = os.getenv("PATH") -- we need to reserve PATH on msys2 + envs = os.joinenvs(envs, msvc:runenvs()) + end -- add gas-preprocessor to PATH if package:is_arch("arm", "arm64") then envs.PATH = path.join(os.programdir(), "scripts") .. path.envsep() .. envs.PATH From 9e59a2e26cae5e181786e4a2ae94aca7ac410bf1 Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 1 Jan 2025 12:56:44 +0800 Subject: [PATCH 3/6] remove clang flag for android r27 --- packages/f/ffmpeg/xmake.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index 8218ceb66a8..0d3df9efff0 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -314,9 +314,14 @@ package("ffmpeg") local cflags = table.join(table.wrap(package:config("cxflags")), table.wrap(package:config("cflags")), table.wrap(get_config("cxflags")), get_config("cflags")) local cxxflags = table.join(table.wrap(package:config("cxflags")), table.wrap(package:config("cxxflags")), table.wrap(get_config("cxflags")), get_config("cxxflags")) assert(os.isdir(sysroot), "we do not support old version ndk!") + + local ndkver = tonumber(ndk:config("ndkver")) if package:is_arch("arm64-v8a") then - table.insert(cflags, "-mfpu=neon") - table.insert(cflags, "-mfloat-abi=hard") + -- https://github.com/llvm/llvm-project/issues/74361 + if ndkver < 27 then + table.insert(cflags, "-mfpu=neon") + table.insert(cflags, "-mfloat-abi=hard") + end else table.insert(cflags, "-mfpu=neon") table.insert(cflags, "-mfloat-abi=soft") From c2ff310ff74593bfbea019b684fb3495a0f585fd Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 1 Jan 2025 21:47:18 +0800 Subject: [PATCH 4/6] Fix windows cross-compilation --- packages/f/ffmpeg/xmake.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index 0d3df9efff0..91944229576 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -225,6 +225,11 @@ package("ffmpeg") if package:is_arch("arm", "arm64") then envs.PATH = path.join(os.programdir(), "scripts") .. path.envsep() .. envs.PATH end + if package:is_cross() then + -- The makedef script always assumes that the AR environment variable is gnu ar + -- @see https://github.com/microsoft/vcpkg/issues/42365 + envs.AR = nil + end autoconf.install(package, configs, {envs = envs}) else import("core.base.option") From d2ca1a30029dc595e6bb4988ec8b6e8ae531e835 Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 1 Jan 2025 22:44:41 +0800 Subject: [PATCH 5/6] Improve AR --- packages/f/ffmpeg/xmake.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index 91944229576..a18dccc9387 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -221,15 +221,15 @@ package("ffmpeg") envs.PATH = os.getenv("PATH") -- we need to reserve PATH on msys2 envs = os.joinenvs(envs, msvc:runenvs()) end + if package:config("shared") and package:is_cross() then + -- The makedef script always assumes that the AR environment variable is gnu ar + -- @see https://github.com/microsoft/vcpkg/issues/42365#issuecomment-2567009409 + envs.AR = nil + end -- add gas-preprocessor to PATH if package:is_arch("arm", "arm64") then envs.PATH = path.join(os.programdir(), "scripts") .. path.envsep() .. envs.PATH end - if package:is_cross() then - -- The makedef script always assumes that the AR environment variable is gnu ar - -- @see https://github.com/microsoft/vcpkg/issues/42365 - envs.AR = nil - end autoconf.install(package, configs, {envs = envs}) else import("core.base.option") From 303797de077d29926f4b2caafc8649181dd6e42b Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 3 Jan 2025 00:54:43 +0800 Subject: [PATCH 6/6] Improve runtimes --- packages/f/ffmpeg/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/f/ffmpeg/xmake.lua b/packages/f/ffmpeg/xmake.lua index a18dccc9387..28de1cb6ef0 100644 --- a/packages/f/ffmpeg/xmake.lua +++ b/packages/f/ffmpeg/xmake.lua @@ -167,7 +167,7 @@ package("ffmpeg") table.insert(configs, "--enable-dxva2") table.insert(configs, "--enable-mediafoundation") table.insert(configs, "--toolchain=msvc") - table.insert(configs, "--extra-cflags=-" .. package:config("runtimes")) + table.insert(configs, "--extra-cflags=-" .. package:runtimes()) elseif package:is_plat("mingw") then if package:is_arch("x86", "i386", "i686") then table.insert(configs, "--target-os=mingw32")