fix: the import libraries are conditioned on the object ABI, not the C library - #6
Merged
Merged
Conversation
…C library
-[target.'cfg(all(windows, env = "gnu"))'.build]
+[target.'cfg(all(windows, not(env = "msvc")))'.build]
ldflags = ["-lntdll", "-lsynchronization", "-lshell32", "-lkernel32"]
这四个是 Win32 导入库 —— 本包所实现的**平台接口**的性质,不是 C 库的性质。
`env = "gnu"` 一直在代表「GNU/PE 的 ABI 而不是 MSVC 的」,而在传统栈上两者重合。
它们在 C 库改由依赖图供给的那一刻不再重合:一次 `x86_64-windows-gnu` 的
openkal 构建解析出的 C 库是 musl —— mcpp 自己的报告就这么打印:
kernel-abi openkal (openkal-windows@0.1.3, graph)
c-abi musl (openkal-musl@0.3.3, graph)
而拼作 `x86_64-windows-musl` 的是同一次构建的诚实名字。旧谓词下第二个拼法
不带这四个库中的任何一个,实测:
ld.lld: error: undefined symbol: __declspec(dllimport) GetStdHandle
ld.lld: error: undefined symbol: __declspec(dllimport) WriteFile
…
两份 build.ninja 的 ldflags 逐 token 对比,差别只有这四个 token;
连 `--target=x86_64-w64-windows-gnu` 都完全相同 —— 两个 mcpp 三元组翻译成
同一个 LLVM 三元组。
实测(改动后):
Finished dev in 2.75s
test3.exe: PE32+ executable (console) x86-64, 14 sections
imports: ntdll.dll / api-ms-win-core-synch-l1-2-0.dll / SHELL32.dll / KERNEL32.dll
wine test3.exe → Hello from test3!
`cxxflags = ["-fno-exceptions", "-fno-rtti"]` 在同一张表里,因此一并生效于
两种拼法 —— 那也是对的:它们的理由同样是 ABI 而非 C 库。
⚠️ 兼容性:`x86_64-windows-gnu` 的求值结果不变(`gnu != msvc`),
新增覆盖的是 `msvc` 之外的其它 env 拼法。
related: mcpp-community/mcpp#494
Sunrisepeak
force-pushed
the
fix/cfg-predicate-is-the-abi
branch
from
August 24, 2026 11:48
3047ca8 to
a66d3ab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
这四个是 Win32 导入库 —— 本包所实现的平台接口的性质,不是 C 库的性质。
env = "gnu"一直在代表「GNU/PE 的 ABI 而不是 MSVC 的」,而在传统栈上两者重合。它们在 C 库改由依赖图供给的那一刻不再重合。mcpp 自己的报告就这么打印:
拼作
x86_64-windows-musl的是同一次构建的诚实名字。旧谓词下它不带这四个库中的任何一个:两份
build.ninja的ldflags逐 token 对比,差别只有这四个 token —— 连--target=x86_64-w64-windows-gnu都完全相同,两个 mcpp 三元组翻译成同一个 LLVM 三元组。实测(改动后)
兼容性
x86_64-windows-gnu的求值结果不变(gnu != msvc);新增覆盖的是msvc之外的其它 env 拼法。Test plan
x86_64-windows-gnu:行为不变x86_64-windows-musl:PE32+ 产出,导入表干净,wine 下运行related: mcpp-community/mcpp#494