From 8edfe75645355bc4d59e66fff64bdf2c3a9095f0 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 4 Aug 2026 15:56:20 +0800 Subject: [PATCH] fix(godot-cpp): force-include , broken on libc++ 22 src/godot.cpp calls realloc() and free() while including neither nor -- it has been riding on a transitive include all along. libstdc++ and libc++ up to 20 still provide one; libc++ 22 does not: src/godot.cpp:252: error: use of undeclared identifier 'realloc' src/godot.cpp:270: error: use of undeclared identifier 'free' Both 4.5.0 and 10.0.0-rc1 carry it, so the fix is not version-gated. CI missed it because the only LLVM legs are macOS and Windows and both pin llvm@20.1.7, while the linux leg is gcc -- linux-with-a-newer-libc++ is a combination the matrix never builds. It surfaced in a real GDExtension project pinned to llvm@22.1.8, which had to pin gcc@16 to work around it. A force-include rather than a generated shim header: the translation unit at fault is the PACKAGE's own, and a dependency compiles with its own include path, so nothing a consumer ships -- including the header-shadow mechanism godot-cpp-m uses for its module unit -- can reach it. cxxflags rather than cflags: this package has no C sources and cflags never reaches a .cpp. Verified with mcpp 2026.8.3.3 + llvm@22.1.8 on linux: compat.godot-cpp 4.5.0 and 10.0.0-rc1 both build and run; `import godot_cpp;` through godotengine.godot-cpp-m 10.0.0-rc1 builds and runs; and the reporting project builds its player GDExtension (libplayer.so) with its gcc pin lifted. --- .../2026-08-04-add-godot-cpp-10.0.0-rc1.md | 22 +++++++++++++++++++ pkgs/c/compat.godot-cpp.lua | 15 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/.agents/docs/2026-08-04-add-godot-cpp-10.0.0-rc1.md b/.agents/docs/2026-08-04-add-godot-cpp-10.0.0-rc1.md index b398ef0..4606727 100644 --- a/.agents/docs/2026-08-04-add-godot-cpp-10.0.0-rc1.md +++ b/.agents/docs/2026-08-04-add-godot-cpp-10.0.0-rc1.md @@ -91,3 +91,25 @@ version=1 bind=1 vec2=1 vec3=1 basis=1 color=1 aabb=1 gen=1 | CN | `https://gitcode.com/mcpp-res/godot-cpp/releases/download/10.0.0-rc1/godot-cpp-10.0.0-rc1.tar.gz` | 两侧下载回来核过 sha,与本地打包一致。 + +## 8. 后记:libc++ 22 上的 ``(2026-08-04 补) + +`src/godot.cpp` 调 `realloc()`/`free()`,却既没包含 `` 也没包含 `` —— +一直靠传递包含活着。libstdc++ 和 libc++ ≤20 还给,**libc++ 22 不给了**: + +``` +src/godot.cpp:252: error: use of undeclared identifier 'realloc' +src/godot.cpp:270: error: use of undeclared identifier 'free' +``` + +**4.5.0 和 10.0.0-rc1 都有**,所以不按版本门控。CI 之所以没抓到:macOS/Windows 两条 LLVM 腿钉的是 +`llvm@20.1.7`,而 linux 腿用 gcc —— 这个组合(linux + 新 libc++)CI 完全没覆盖。是用户在自己的 +GDExtension 工程里用 `llvm@22.1.8` 撞出来的。 + +修法是 `cxxflags = { "-include", "cstdlib" }`,**不是**生成一个遮蔽头:出问题的 TU 是**本包自己的** +`src/godot.cpp`,依赖是拿自己的 include 路径编的,消费侧(哪怕是 godot-cpp-m 那套遮蔽头机制) +根本够不到它。用 `cxxflags` 而非 `cflags`:本包没有 C 源码,`cflags` 到不了 `.cpp`。 + +验证(mcpp 2026.8.3.3 + llvm@22.1.8,linux):`compat.godot-cpp` 4.5.0 与 10.0.0-rc1 各自直编通过; +`import godot_cpp;` 经 godotengine.godot-cpp-m 10.0.0-rc1 通过;用户的真实工程(gamecore + player +GDExtension)`mcpp build -p player` 产出 `libplayer.so`、`mcpp test -p gamecore` 通过。 diff --git a/pkgs/c/compat.godot-cpp.lua b/pkgs/c/compat.godot-cpp.lua index 2a3bdd6..c9d7553 100644 --- a/pkgs/c/compat.godot-cpp.lua +++ b/pkgs/c/compat.godot-cpp.lua @@ -150,6 +150,21 @@ package = { ["gdextension"] = { defines = { "GDEXTENSION", "TYPED_METHOD_BIND" } }, }, deps = { }, + -- src/godot.cpp calls realloc()/free() but includes neither + -- nor -- it has been riding on a transitive include the + -- whole time. libstdc++ and libc++ up to 20 still provide one; libc++ + -- 22 does not, and the TU stops compiling: + -- + -- src/godot.cpp:252: error: use of undeclared identifier 'realloc' + -- src/godot.cpp:270: error: use of undeclared identifier 'free' + -- + -- Both 4.5.0 and 10.0.0-rc1 carry it, so this is not version-gated. + -- It is a force-include rather than a generated shim header because + -- the TU at fault is the PACKAGE's own: a consumer-side header shadow + -- never reaches it (the dependency compiles with its own include + -- path). cxxflags, not cflags -- this package has no C sources and + -- cflags would not reach a .cpp. + cxxflags = { "-include", "cstdlib" }, -- A GDExtension IS a shared library, so this static library's objects -- are almost always linked into one. Without position-independent code -- that link fails outright ("relocation R_X86_64_32 against `.rodata`