Skip to content

Commit b3cf05f

Browse files
committed
run/test: look the runner up by the canonical triple — the driver's spelling matched on Linux and never on macOS (measured on CI)
1 parent 4a48111 commit b3cf05f

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

.agents/docs/2026-09-02-runner-beyond-baremetal-design.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,18 @@ For the resolved target, in order:
298298
299299
The per-triple key is already the scoping mechanism for "this runner belongs to
300300
that cross target": a runner written under `[target.aarch64-linux-musl]` is not
301-
found when the host target is resolved, because the lookup is
302-
`targetOverrides.find(ctx.tc.targetTriple)` and the key is stored canonicalised
303-
(`toml.cppm:1825-1830, :1960`). No new key is needed to express applicability
304-
along the target axis.
301+
found when the host target is resolved, because the key is stored canonicalised
302+
(`toml.cppm:1825-1830, :1960`) and looked up by the resolved target. No new key
303+
is needed to express applicability along the target axis.
304+
305+
The lookup key is the canonical spelling, `triple::parse(tc.targetTriple)->str()`,
306+
which is the output directory's name and the key every other
307+
`[target.<triple>]` reader in `prepare.cppm` resolves. The draft looked up
308+
`tc.targetTriple` as the driver reported it; on a Linux host that is the
309+
canonical spelling and on macOS it is `arm64-apple-darwin24.6.0`, so
310+
`[target.aarch64-macos].runner` matched on Linux hosts and never on macOS
311+
(measured on PR #545's macOS e2e shard, 2026-09-02). The raw spelling stays as
312+
a fallback for a triple the parser does not know.
305313
306314
What the key cannot express is the host axis, and this is the limit D3 and D4
307315
respond to: the same triple is foreign on one host and native on another, and

src/build/execute.cppm

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,25 @@ RunnerChoice choose_runner(const BuildContext& ctx, bool noRunner = false) {
472472
// for `-bios none -semihosting` while debugging, and — on a hosted cross
473473
// triple — for naming the user-mode emulator at all.
474474
c.tmpl = ctx.manifest.buildConfig.runner;
475-
if (auto it = ctx.manifest.targetOverrides.find(ctx.tc.targetTriple);
476-
it != ctx.manifest.targetOverrides.end() && !it->second.runner.empty()) {
477-
c.tmpl = it->second.runner;
475+
// The manifest key is the CANONICAL spelling — `aarch64-macos`, the name
476+
// of the output directory and the key every other `[target.<triple>]`
477+
// reader uses (prepare.cppm resolves overrides by `t.str()`). The
478+
// toolchain's own `targetTriple` is what the driver reported, which on a
479+
// Linux host happens to be the canonical spelling and on macOS is
480+
// `arm64-apple-darwin24.6.0`. Looking up the raw spelling alone matched on
481+
// Linux and never on macOS (measured on CI, 2026-09-02); the raw form is
482+
// kept as a fallback for a triple the parser does not know.
483+
auto lookup = [&](std::string_view key) {
484+
auto it = ctx.manifest.targetOverrides.find(std::string(key));
485+
return it != ctx.manifest.targetOverrides.end() && !it->second.runner.empty()
486+
? &it->second : nullptr;
487+
};
488+
const mcpp::manifest::TargetEntry* entry = nullptr;
489+
if (auto ft = mcpp::toolchain::triple::parse(ctx.tc.targetTriple))
490+
entry = lookup(ft->str());
491+
if (!entry) entry = lookup(ctx.tc.targetTriple);
492+
if (entry) {
493+
c.tmpl = entry->runner;
478494
c.fromManifest = !ctx.manifest.buildConfig.runner.empty();
479495
}
480496
// `--no-runner` is the operator on THIS host stating a host fact the

tests/e2e/330_runner_hosted_targets.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ cat > tests/one.cpp <<'EOF'
4242
int main() { return 0; }
4343
EOF
4444

45-
# The host triple as the manifest spells it. Read from the engine rather than
46-
# guessed: `[target.<triple>]` is matched against the resolved target.
45+
# The host triple as the manifest spells it: the CANONICAL form, which is the
46+
# name of the output directory (`target/<triple>/…`) and the key every
47+
# `[target.<triple>]` reader resolves. Read from the engine rather than
48+
# guessed. Not the "Target … → …" status line: on macOS that prints the
49+
# driver's own spelling (`arm64-apple-darwin24.6.0`), which is not the key —
50+
# and the first version of this test used it and failed only on macOS.
4751
out=$("$MCPP" build 2>&1) || fail "initial build: $out"
48-
HOST=$(sed -n 's/.*Target \([^ ]*\) → .*/\1/p' <<<"$out" | head -1)
49-
[[ -n "$HOST" ]] || HOST=$(ls target | head -1)
50-
[[ -n "$HOST" ]] || fail "could not determine the host triple from: $out"
52+
HOST=$(ls target | head -1)
53+
[[ -n "$HOST" ]] || fail "could not determine the host triple from target/: $out"
5154

5255
cat > "$TMP/runner.sh" <<'EOF'
5356
#!/bin/sh

0 commit comments

Comments
 (0)