moonutil::toolchain owns executable resolution for MoonBit toolchain
programs and executable environment overrides.
MoonBit tool executables are selected in this order:
- an executable specified by its override environment variable
- the executable under the resolved toolchain root
- an executable found through
PATH
Override values use the same platform executable lookup as other tool names.
They may be bare names, explicit relative paths, or absolute paths. Successful
resolution always produces an absolute path, including when PATH itself
contains relative entries. An override that cannot be resolved is left intact
so its command keeps the existing error-reporting behavior.
Whenever Moon delegates to a child before applying -C to its own process,
executable lookup and the child's working directory use the same effective
command directory. This applies to early moon cram and moon help ide
delegation. Relative moon-cram overrides and relative PATH entries are
resolved from that directory.
The cached entry point is moonutil::toolchain::BINARIES. Build engines should
use it instead of duplicating tool lookup rules.
Registry Git synchronization uses the same cache, selecting MOON_GIT_OVERRIDE
before searching PATH.
Linux profiling resolves perf through an optional entry in this cache,
using MOON_PERF_OVERRIDE before searching PATH. Availability checks,
recording, export, and dry-run output use the same resolved executable.
macOS profiling invokes xcrun xctrace. The xcrun launcher uses the same
cache, selecting MOON_XCRUN_OVERRIDE before searching PATH; Xcode selects
xctrace when the launcher runs.
Each cache entry uses LazyLock: its initializer runs on first access and
the result, including an unavailable optional tool, is reused for the rest of
the process. Repeated availability checks do not repeat executable discovery.
Binary resolution is demand-driven. The cache must not expose an aggregate inventory API: code for display, diagnostics, or tests must never enumerate all entries or otherwise force resolution of the complete executable inventory. An unavailable unused executable must not make an operation fail.
Version output uses the selected executable paths. For display, paths under
the user's home directory are abbreviated with ~ by comparing whole path
components. Ordinary and verbatim Windows drive/UNC prefixes match, including
when a long executable path retains its prefix beneath a short home directory.
Paths outside home are simplified only when that preserves their meaning. This
formatting applies to both text and JSON output and does not change the paths
used to execute tools.