From c21847efd87b6a17d818a9d963482eb0485df734 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Fri, 20 Nov 2026 15:40:46 +0900 Subject: [PATCH 1/2] compat.c-ares: CARES_STATICLIB reaches the consumer (Windows: a dllimport slot lld-link discards under /OPT:REF) --- pkgs/c/compat.c-ares.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkgs/c/compat.c-ares.lua b/pkgs/c/compat.c-ares.lua index 1505603f..e6e77968 100644 --- a/pkgs/c/compat.c-ares.lua +++ b/pkgs/c/compat.c-ares.lua @@ -76,6 +76,23 @@ package = { -- fail with implicit-declaration errors. cflags = { "-DCARES_STATICLIB", "-DHAVE_CONFIG_H", "-D_GNU_SOURCE", "-D_HAS_EXCEPTIONS=0" }, + -- CARES_STATICLIB IS THE CONSUMER'S TOO. Without it declares + -- every entry point __declspec(dllimport) on Windows, and a consumer + -- calls this static library through an `__imp_` slot that lld-link + -- fills locally (LNK4217). Under /OPT:REF, lld's default without + -- /DEBUG, that slot does not keep its definition alive: when the + -- object was pulled in only by code that is later discarded, the + -- definition goes and the slot holds the image base. gRPC's + -- `ares_library_init` was exactly that, and grpc_init jumped to the + -- PE header (0xC0000005). Upstream propagates the define to + -- dependents (cares.BUILD `defines`, CMake's INTERFACE definition); + -- here a feature's `defines` reach the consumer and `default` + -- implies it unconditionally, as compat.curl does for CURL_STATICLIB. + features = { + ["default"] = { implies = { "staticlib" } }, + ["staticlib"] = { defines = { "CARES_STATICLIB" } }, + }, + -- ONE SNAPSHOT PER C ENVIRONMENT, AND THE PREPROCESSOR PICKS. -- -- These are gRPC 1.83.0's three frozen `ares_config.h` files, verbatim, From 3b6b6024dc1a5bc3a5caf3fe1f69626dc9936e9f Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Fri, 20 Nov 2026 17:25:59 +0900 Subject: [PATCH 2/2] CHANGELOG: compat.c-ares passes CARES_STATICLIB to its consumers --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c052d5c4..6c2e1bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,7 @@ ### Fixed +- **compat.c-ares:`CARES_STATICLIB` 传给使用方(Windows 上 gRPC 启动即崩溃的根因)。** 此前只有包自身以该宏编译,使用方看到的 `` 把每个入口声明为 `__declspec(dllimport)`,经 lld-link 本地补全的 `__imp_` 槽调用静态库(LNK4217)。lld-link 在不带 `/DEBUG` 时默认 `/OPT:REF`,该槽不保住它的定义:定义所在目标文件只因随后被丢弃的代码而载入时,定义被丢弃、槽内为映像基址。gRPC 的 `ares_library_init` 正是如此,`grpc_init` 跳到 PE 头(0xC0000005,mcpp 报 exit 133);四行 C 即可复现(llvm 23.1.3)。上游的 Bazel(`defines`)与 CMake(INTERFACE 定义)都把该宏传给依赖方;此处按 compat.curl 的写法以 `default` 隐含的 feature `defines` 传递。在装有旧 compat.c-ares 的 home 上实测生效,无需 packaging revision;gRPC 的模块测试在 Windows 默认链接参数下通过(grpc-m#10)。 - **mcpp.plugins 0.23.1。** `dist-apk` 把构建程序在输出目录(`mcpp::out_dir()`、`target/`)中生成的 Java 或 Kotlin 根只作为 `javac` 动作的输入,不再为其声明永远无法命中的重跑 glob,消除每次构建的警告。`latest` 指向 0.23.1 (mcpp-community/mcpp-plugins#57)。