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
ffmpeg: fix build failure with gbk encoding
  • Loading branch information
choyy committed Dec 10, 2025
commit a8369834d72d0dd09eebad02e04eb65766aefff4
8 changes: 8 additions & 0 deletions packages/f/ffmpeg/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ package("ffmpeg")
local configs = {
msystem = "MINGW64",
base_devel = true,
uchardet = true,
}
-- @see https://stackoverflow.com/questions/65438878/ffmpeg-build-on-windows-using-msvc-make-fails
configs.make = true
Expand Down Expand Up @@ -271,6 +272,13 @@ package("ffmpeg")
if package:is_arch("arm", "arm64") then
envs.PATH = path.join(os.programdir(), "scripts") .. path.envsep() .. envs.PATH
end
-- fix build failure with gbk encoding
io.replace("configure", "cp_if_changed $TMPH config.h", [[
config_encodings=$(uchardet $TMPH)
case "$config_encodings" in GB18030|GBK|GB2312)
{ printf '\xEF\xBB\xBF'; iconv -f "$config_encodings" -t UTF-8 -c $TMPH; } > config.h;;
*) cp_if_changed $TMPH config.h;;
Comment on lines +277 to +280
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For robustness, it's a good practice to quote the $TMPH variable in shell scripts to handle potential spaces or special characters in the file path.

                    config_encodings=$(uchardet "$TMPH")
                    case "$config_encodings" in GB18030|GBK|GB2312)
                        { printf '\xEF\xBB\xBF'; iconv -f "$config_encodings" -t UTF-8 -c "$TMPH"; } > config.h;; 
                    *) cp_if_changed "$TMPH" config.h;;

esac]], {plain = true})
Comment on lines +276 to +281
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This is a great fix for the encoding issue. However, this io.replace call is inside an if path.cygwin then block. There is another code path for Windows builds in the else block (starting on line 283) which also invokes the ./configure script. This fix should also be applied there to ensure consistent behavior for all Windows builds. You could move this block of code to before the if path.cygwin then check (e.g., after line 274) to apply it to both paths.

autoconf.install(package, configs, {envs = envs})
else
import("core.base.option")
Expand Down
2 changes: 2 additions & 0 deletions packages/m/msys2/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package("msys2")

add_configs("make", {description = "Install gnumake.", default = false, type = "boolean"})
add_configs("gcc", {description = "Install gcc.", default = false, type = "boolean"})
add_configs("uchardet", {description = "Install uchardet.", default = false, type = "boolean"})
add_configs("diffutils", {description = "Install diffutils.", default = false, type = "boolean"})
add_configs("base_devel", {description = "Install base-devel.", default = false, type = "boolean"})
add_configs("mingw64_gcc", {description = "Install mingw64 gcc.", default = false, type = "boolean"})
Expand Down Expand Up @@ -41,6 +42,7 @@ package("msys2")
local packages = {
"gcc", "make", "diffutils",
base_devel = "base-devel",
uchardet = "mingw-w64-x86_64-uchardet",
mingw32_gcc = "mingw-w64-i686-gcc",
mingw32_toolchain = "mingw-w64-i686-toolchain",
mingw64_gcc = "mingw-w64-x86_64-gcc",
Expand Down
Loading