Skip to main content

link_driver_language

Function link_driver_language 

Source
pub fn link_driver_language(languages: &[SourceLanguage]) -> SourceLanguage
Expand description

Pick the link-driver language for a target whose objects span the supplied set of source languages.

Rule: if any object came from a C++ source (or any transitively linked library declares any C++ object), the link driver is the C++ compiler. Otherwise the C compiler drives the link. The C++ driver pulls in the C++ runtime (libstdc++ / libc++), which is required for any translation unit that uses C++; the C driver omits that runtime, which is correct for pure-C link lines.

Returns SourceLanguage::C for an empty input — that is the conservative choice for an empty link line, but in practice the planner rejects executables with no objects before this is consulted.

The slice form (rather than a generic IntoIterator) keeps the predicate cheap to call on the per-target language manifests the planner already collects, and lets callers reason about the input by reading the call site directly.