lang::features
lang/src/features.mo
Optional-dependency and feature resolution.
Pure: the caller supplies one FeaturePackage per reachable mote
(its [features] table and its dependency policies), plus the root's
selection. No filesystem read happens here, which is what makes the
resolver unit-testable and identical in both compilers.
Rules (Cargo's model):
- features are additive and unioned; a dependency is enabled if any dependent enables it;
- a non-optional dependency is always enabled with the parent's
default-featureschoice; - an optional dependency is enabled only by
dep:name,name/for a plain item naming an optional dep; name?/fis weak: it enablesfonly ifnameis already enabled;defaultis a feature like any other; the root's is on unlessno_default, a dependency's follows its policy.
This module is the feature half of implementations/ attributes-deprecated-and-cfg.md's CfgSet; it does not do the #[cfg]
filtering itself.
pub struct DepPolicy {
optional : Bool,
features : List String,
default_features : Bool
}pub def DepPolicy.default : DepPolicypub struct FeaturePackage {
name : String,
features : List (Pair String (List String)),
deps : List (Pair String DepPolicy)
}One package's feature declarations and dependency policies.
pub struct FeatureSelection {
features : List (Pair String (List String)),
enabled_deps : List (Pair String (List String))
}The resolved answer: each package's enabled feature set, and each package's enabled dependency names (non-optional plus activated optional ones).
pub def Features.resolve (pkgs : List FeaturePackage) (root : String)
(requested : List String) (no_default : Bool) : Result String FeatureSelectionResolve a root's features. requested are the CLI/target features;
no_default drops only the root's default.