Skip to main content

Module condition

Module condition 

Source
Expand description

Typed model for cfg(...) target-condition expressions.

Cabin manifests can declare target-specific dependency tables, e.g.

[target.'cfg(os = "linux")'.dependencies]
epoll = "^1"

The condition string between the parentheses is parsed into a Condition AST and evaluated against a TargetPlatform describing the current evaluation context (the host build platform in this step). Parsing and evaluation are pure, deterministic, and side-effect-free.

Supported keys are intentionally narrow. The platform keys — os, arch, family, env, abi, target — are listed by the ConditionKey enum. feature = "..." evaluates against the owning package’s enabled-feature set, and the compiler keys — cc, cxx, cc_version, cxx_version — evaluate against the detected toolchain; both are accepted on profile flag tables only (the manifest layer rejects them elsewhere). Any other key is rejected at parse time so manifests do not silently rely on a future detection layer.

Public syntax is preserved as the canonical inner-expression string when round-tripped (see the Display impl on Condition); the manifest layer wraps it in cfg(...) and the metadata layer emits the bare inner form so JSON / on-disk shapes stay compact.

Structs§

ConditionContext
Evaluation context for Condition::evaluate. Bundles the host platform, the owning package’s enabled-feature set, and the detected compiler identities so each leaf kind reads the input it is defined over. Platform-only call sites (dependency gating, toolchain / wrapper selection) use ConditionContext::platform_only; compiler identities are attached only on the flag-resolution path, the only place compiler-referencing leaves are reachable (the manifest layer rejects them elsewhere).
TargetPlatform
Evaluation context for Condition::evaluate. Each field is a stable, normalized lowercase string. Unknown values flow through as the literal unknown, which is matchable in cfg(...) expressions.

Enums§

CompilerSlot
Compiler slot a compiler condition tests: the detected C compiler (cc / cc_version keys) or the detected C++ compiler (cxx / cxx_version). Deliberately not crate::toolchain::ToolKind, which includes the archiver — conditions support compiler slots only.
Condition
Typed AST for a cfg(...) target condition.
ConditionKey
Recognized target-condition keys. Anything else is rejected at parse time.
ConditionParseError
Errors produced while parsing a cfg(...) expression.