artifact = "rust-library" and [features] Chosen by RootsStatus: Accepted
Date: October 29, 2026 (owner’s decision), written November 8, 2026
Answers: #978
Related: Part III 13.3 (the manifest), 13.2 (nikaia bind), 15.1 (a C
library), 15.2 (Rust integration); ADR-286 D23-D24 (a published
package is the crate nikaia_<name>); ADR-336 D2 and
ADR-338 D2 (the prefix of what the project publishes);
ADR-yaml-1 D10 (the facade crate and stream wait on this)
A package builds into a program or a C library. A Rust program that wants a Nikaia package, the YAML package’s serde_yaml facade first among them, has no way to depend on it: the lowered Rust exists only inside a Nikaia build. And a library with several independent parts (a tree, an event stream, a serde bridge) has no way to let its user take only the part they need, which Rust users expect from Cargo features.
Two questions follow. What does a package built for Rust look like? And how
does its author name the parts a Rust user can choose, without writing
#[cfg] into Nikaia code?
For the crate:
"rust-library". The lowered package is written as
an ordinary Cargo lib crate.bindgen. That costs a second boundary, loses every Rust type at it, and
turns a borrow into a pointer.For the parts:
[features] in the manifest, each naming roots. The compiler works
out what each root reaches and writes the #[cfg].#[cfg(feature = …)] written in the source, as Rust does. Each item
carries its own condition, and the author keeps those conditions true by
hand. Every forgotten condition is a build that fails for one combination
of features only.A and C.
artifact = "rust-library" writes the package as an ordinary Rust lib crate.nikaia build writes Cargo.toml and src/ of a lib crate named
nikaia_<name> (ADR-286 D23). Its public API is the package’s pub items,
lowered as they are for a Nikaia program that depends on the package. It
depends on nikaia-std and on the package’s own dependencies. A Rust crate
uses it as a path dependency now. It is published to crates.io once
nikaia-std is (ADR-336 D2). The build writes the crate to
target/rust-library/nikaia_<name>/ and prints that path. Nothing in it is
written by hand: the next build overwrites it.
[features] names features, and each feature names roots.[features]
default = ["serde"]
tree = ["yaml::tree"]
stream = ["yaml::stream"]
serde = ["yaml::serde"]
A root is a module, which stands for all its pub items, or one pub item
written by its path. default lists features; it is the set a Rust user gets
without asking. A pub item that no feature’s root names or reaches is always
present: it is the core. Without [features], everything pub is core.
Every item a root reaches through calls, types, trait implementations and constants is in that feature. The compiler derives the following and records it in the ledger (13.5):
#[cfg(any(feature = "a", feature = "b"))].Cargo.toml lists the implication (serde = ["tree"]).optional = true, and each feature that reaches it lists dep:<name>.The source holds no condition. The manifest names only the roots.
A feature adds items and never changes or removes one, so any set of features
builds the same code for the items they share. The lowering writes a
grammar’s reader form (parse_<rule>_reader, #[stream]) only where a
feature reaches it with a reader. Without such a feature the crate holds only
the forms over a whole input.
Amended November 8, 2026 (supervisor, on #1442 step 3): a root names a
grammar entry by its path, <package>::<Grammar>::<rule> (yaml::Yaml::events);
<package>::<Grammar> stands for all its pub entries, as a module does
(D2). The feature gates only the public reader G::<rule>_reader
(ADR-grammar-typed-read-v2 D7). The engine’s #[stream] form that an in-crate walk over
String or Bytes needs is part of the core and is written without a
feature.
nikaia bind.A program has no user who chooses parts, so [features] in a package built as
a program is refused. A C library is built whole. nikaia bind <language>
--features a,b writes a binding for those features and the core only. The
binding’s default is default.
A rust-library build compiles the crate with the core only, with each feature
alone, and with all features. A combination rustc refuses is reported on the
.nika root of the feature that fails, as a Nikaia diagnostic. It is not an
internal compiler error (NK1343). This catches what the derivation of D3
missed.
The new codes (Part III C.3):
NK1344: a root that names nothing, or an item that is not pub.NK1345: a feature that does not build alone or together with the others.NK1346: [features], or --features, where the build is a program.NK1347: a feature list that names an undeclared feature, or a feature
name Cargo does not accept.[rust-library] may splice hand-written Rust into the crate: root becomes the crate root, and the lowered items move under native.Moved to ADR-rust-boundary-1 D23 (November 19, 2026), unchanged, with NK1348.
nikaia_yaml::native.nikaia bind (D5).nikaia-std’s version. That
is decided when nikaia-std is published.