Skip to content

fix: the import libraries are conditioned on the object ABI, not the C library - #6

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/cfg-predicate-is-the-abi
Aug 24, 2026
Merged

fix: the import libraries are conditioned on the object ABI, not the C library#6
Sunrisepeak merged 1 commit into
mainfrom
fix/cfg-predicate-is-the-abi

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Summary

-[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 库改由依赖图供给的那一刻不再重合。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

两份 build.ninjaldflags 逐 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!

兼容性

⚠️ x86_64-windows-gnu 的求值结果不变(gnu != msvc);新增覆盖的是 msvc 之外的其它 env 拼法。

Test plan

  • x86_64-windows-gnu:行为不变
  • x86_64-windows-musl:PE32+ 产出,导入表干净,wine 下运行
  • CI

related: mcpp-community/mcpp#494

@Sunrisepeak Sunrisepeak changed the title fix: 导入库的条件是对象 ABI,不是 C 库 fix: the import libraries are conditioned on the object ABI, not the C library Aug 24, 2026
…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
Sunrisepeak force-pushed the fix/cfg-predicate-is-the-abi branch from 3047ca8 to a66d3ab Compare August 24, 2026 11:48
@Sunrisepeak
Sunrisepeak merged commit a394eb5 into main Aug 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant