Skip to content

Commit 553466c

Browse files
committed
fix(dist): 产物格式的判据匹配不到 mcpp 自己用的三元组拼法
if (t.find("apple")) return MachO; apple / darwin 是 LLVM 的词。mcpp 的规范形式是 aarch64-macos,两个都不含 —— 于是 这个判断在**每一种宿主上**都落到了「问宿主」,而它产生的两种失败方向相反: Linux 宿主 + macOS 目标 → 给 Mach-O 用了 Elf 的契约 macOS 宿主 + Linux 目标 → 给 ELF 用了 MachO 的契约 ⚠️ 实测第二种(macOS runner 交叉到 x86_64-linux-gnu): ld.lld: error: unable to find library -load_hidden …/xim-x-llvm/22.1.8/lib/libc++.a: archive member 'system_error.cpp.o' is neither ET_REL nor LLVM bitcode -load_hidden 是 Mach-O 链接器的词,那个归档是**宿主的** —— 两个都是因为「格式」 这个问题被用「哪台机器在构建」回答了。 ⇒ 先用已解析的 triple 回答(is_pe / os == macos / linux / none);字符串判断保留 在后面,作为词表解析不了的三元组([target.X] 逃生口)的兜底,那里只有拼法可依。
1 parent 1ccf979 commit 553466c

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/build/flags.cppm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,37 @@ CompileFlags compute_flags(const BuildPlan& plan) {
914914
// Only ADDS answers: a triple that says neither falls through to
915915
// exactly the previous derivation, so no existing build changes.
916916
const auto& t = plan.toolchain.targetTriple;
917+
// ⭐⭐ THE PARSED TRIPLE FIRST, BECAUSE THE SUBSTRINGS BELOW DO NOT
918+
// MATCH THE SPELLING mcpp ITSELF USES.
919+
//
920+
// `apple` and `darwin` are LLVM's words. mcpp's canonical form for
921+
// that target is `aarch64-macos`, which contains neither — so the
922+
// test fell through to the host on every host, and the two failures
923+
// that produces are opposite:
924+
//
925+
// Linux host, macOS target → Elf contract for a Mach-O
926+
// macOS host, Linux target → MachO contract for an ELF
927+
//
928+
// ⚠️ Measured 2026-08-23, the second one, on a macOS runner
929+
// cross-building for `x86_64-linux-gnu` over openkal:
930+
//
931+
// ld.lld: error: unable to find library -load_hidden
932+
// …/xim-x-llvm/22.1.8/lib/libc++.a: archive member
933+
// 'system_error.cpp.o' is neither ET_REL nor LLVM bitcode
934+
//
935+
// `-load_hidden` is a Mach-O linker's word and that archive is the
936+
// HOST's — both chosen because the format question was answered by
937+
// asking which machine was doing the building.
938+
//
939+
// The substring tests are kept below as a fallback for a triple the
940+
// vocabulary cannot parse (the `[target.X]` escape hatch), where a
941+
// spelling is all there is.
942+
if (auto parsed = mcpp::toolchain::triple::parse(t)) {
943+
if (parsed->is_pe()) return dist::Format::Pe;
944+
if (parsed->os == "macos") return dist::Format::MachO;
945+
if (parsed->os == "linux"
946+
|| parsed->os == "none") return dist::Format::Elf;
947+
}
917948
if (t.find("windows") != std::string::npos
918949
|| t.find("mingw") != std::string::npos)
919950
return dist::Format::Pe;

0 commit comments

Comments
 (0)