From a2acfa9a6fea3797e910e7db1e6ecdbd03bf764a Mon Sep 17 00:00:00 2001 From: Linghong Date: Sun, 20 Sep 2026 19:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Godot=20=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=9A=84=20MSVC=20=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 ABI 存储改为 C11 显式 16 字节对齐并保留 128 字节容量 补充 Windows 编译环境要求与 MSVC 对齐问题排障说明 --- docs/project-memory/shared-memory/pitfalls.md | 5 +++++ .../【技术方案】AGC Godot编辑器插件接入-2026-09-20.md | 2 ++ plugins/agc-godot-editor/native/gdextension/src/native.c | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/project-memory/shared-memory/pitfalls.md b/docs/project-memory/shared-memory/pitfalls.md index 8a2942429..34bd0dcc7 100644 --- a/docs/project-memory/shared-memory/pitfalls.md +++ b/docs/project-memory/shared-memory/pitfalls.md @@ -1,5 +1,10 @@ # 踩坑与排障记录 +## Godot 原生插件在 MSVC C 模式下的对齐声明 + +- `native.c` 若首先报 `max_align_t` 语法错误,后面的 `Storage`、`retained_script` 等未声明通常是连带错误。MSVC C 模式不提供该类型;ABI 存储使用 C11 `_Alignas(16)` 显式对齐并保持 128 字节容量,通过实际 MSVC DLL 构建验证,不逐条修补连带错误。 +- `No C compiler found` 则属于开发环境问题:先初始化 Visual Studio x64 开发环境,同时设置 PATH、INCLUDE 与 LIB,再运行构建。只把 `cl.exe` 所在目录加到 PATH 不足以提供头文件和链接库。 + ## Rust 同步回调的测试记录按线程隔离 - `shared-contracts` 的资源 kind reporter 是进程级回调。仅给注册和断言加锁,无法阻止其他并行 manifest 测试触发该回调,导致日志数量和内容断言偶发混入其他测试记录。 diff --git a/docs/technical/【技术方案】AGC Godot编辑器插件接入-2026-09-20.md b/docs/technical/【技术方案】AGC Godot编辑器插件接入-2026-09-20.md index be5e4d5eb..12c399c5e 100644 --- a/docs/technical/【技术方案】AGC Godot编辑器插件接入-2026-09-20.md +++ b/docs/technical/【技术方案】AGC Godot编辑器插件接入-2026-09-20.md @@ -33,6 +33,8 @@ DLL 原件随 AGC 安装包放在插件资源目录中;Godot Windows 加载器 ## 分发与描述文件 +- Windows 原生构建使用 x64 C11 编译器;MSVC 需先初始化 Visual Studio 的 x64 开发环境,以同时提供 PATH、INCLUDE 与 LIB。ABI 临时存储使用 128 字节、C11 `_Alignas(16)` 显式对齐,不依赖 MSVC C 模式未提供的 `max_align_t`;定向验证运行 `plugins/agc-godot-editor/native/gdextension/build.ps1 -Compiler cl.exe`。 + - 安装资源布局为 `plugins/agc-godot-editor/native/gdextension/bin/win-x64/agc_godot_editor.dll`,邻接元数据记录协议、构建身份和 DLL SHA256。开发模式允许宿主提供仓库插件目录中的同结构产物;RPC 不接受自定义 DLL 候选。 - 缓存根仅由宿主提供,为其私有配置目录下的 `godot-editor-runtime`;按 `PID + startedFileTime + buildId` 隔离,所有路径分量受控且拒绝链接/reparse point。复制前验证安装原件及元数据,缓存已有文件必须匹配来源、归属及 SHA,不能加载被替换的同名文件。受管描述同时保留原件与加载副本身份,重启恢复不得把工程给出的任意 DLL 路径当作受信任来源。 - 实际模块核验同时覆盖加载副本及 Godot 在同目录生成的精确 `~agc_godot_editor.dll`,要求规范化路径和 DLL 字节身份一致。确认原生卸载后,只清理本实例、本构建、内容未变的缓存文件;不能跨编辑器删除或复用影子副本。安装位置更新和实例 PID 重用都必须重新验证。 diff --git a/plugins/agc-godot-editor/native/gdextension/src/native.c b/plugins/agc-godot-editor/native/gdextension/src/native.c index 54e9ae5d7..c29455473 100644 --- a/plugins/agc-godot-editor/native/gdextension/src/native.c +++ b/plugins/agc-godot-editor/native/gdextension/src/native.c @@ -9,9 +9,10 @@ #include "gdextension_interface.h" #include "embedded_bridge.h" -/* Windows x64 ABI storage is deliberately oversized and naturally aligned. +/* Windows x64 ABI storage is deliberately oversized and 16-byte aligned. + * Explicit C11 alignment also works with MSVC C, which lacks max_align_t. * Objects are constructed/destructed solely through the official interface. */ -typedef union { max_align_t alignment; unsigned char bytes[128]; } Storage; +typedef struct { _Alignas(16) unsigned char bytes[128]; } Storage; static GDExtensionInterfacePrintWarning api_warning; static GDExtensionInterfaceVariantCall api_call; static GDExtensionInterfaceVariantDestroy api_destroy;