#!/bin/sh
# Selective rustc wrapper for the Rust omc CI build. Cargo invokes a
# RUSTC_WRAPPER as: <wrapper> <rustc> <args...>.
#
# sccache wraps rustc and only releases rustc's output when the process exits,
# which hides rustc's mid-compile "metadata ready" message from cargo. That
# disables cargo pipelining (a dependent crate can no longer start during this
# crate's codegen) and zeroes the codegen column in `cargo --timings`. That
# trade-off only pays off for crates that actually hit the cache.
#
# The crates.io / git dependencies (wasmtime, wasmer, curl, winnow, ...) are
# stable across builds, so they are cache hits worth wrapping. Our own workspace
# crates are regenerated by mmtorust every build, so they never hit the cache --
# wrapping them buys nothing and costs the pipelining overlap on the near-linear
# generated-crate chain that dominates the build. So: sccache for registry/git
# deps, bare rustc for everything else (which restores pipelining and the
# --timings codegen split for the generated crates).
case "$*" in
  *registry/src/*|*/git/checkouts/*) exec sccache "$@" ;;
  *)                                 exec "$@" ;;
esac
