docs/rationale/mpi-wrappers-as-compilers.md
MPI wrapper commands (mpicc, mpicxx, mpifort, ... from Open MPI
and MPICH; mpiicc, mpiifort, ... from Intel MPI) wrap the real
compiler, but they are a different kind of wrapper than ccache/distcc/
sccache: the real compiler is not an argument of the invocation. The
underlying compiler and the extra -I/-L flags are baked into the
wrapper at MPI-installation time and are discoverable only by running
the wrapper itself (mpicc -show on MPICH, mpicc -showme on Open
MPI). Bear's wrapper-unwrapping mechanism therefore cannot apply.
Two options were on the table:
mpicc -show (or
-showme) and recording the underlying compiler command with the
baked-in flags inlined.Option (b) executes tools during semantic analysis, which is slow (one
fork+exec per invocation or at least per wrapper path), couples Bear to
the presence and health of the MPI installation at analysis time, and
differs per MPI vendor (-show vs -showme vs -compile_info). The
expanded command is also not necessarily what clang tooling needs:
clangd already solves exactly this problem on its side with
--query-driver, which asks the wrapper for its implicit include paths.
Option (a): record the wrapper invocation verbatim. Flag parsing uses
the GCC flag table (via table inheritance), because the wrappers pass
their arguments through to a gcc-compatible driver. Intel MPI wrappers
are the exception: they are recognized as the Intel compilers
themselves (extra basenames on the existing Intel families), because
mpiicc is icc/icx with MPI paths baked in and Intel's flag table
has arity entries (e.g. -debug takes an argument) that the GCC table
would mis-parse.
bear semantic.--query-driver (clangd) or an
equivalent mechanism to learn the wrapper's baked-in include paths.
Revisit expansion only if users ask for it.-showme, -show, -compile_info,
-link_info) classify as info-and-exit, so probing the wrapper does
not pollute the database.recognition-compiler-namesmpicc(1), -show/-compile_info/-link_info