@@ -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