ADR-393: A Package Becomes a Rust Library — artifact = "rust-library" and [features] Chosen by Roots

Status: 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)

1. Question

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?

2. Options

For the crate:

For the parts:

3. Decision

A and C.

D1 - 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.

D2 - [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.

D3 - What a root reaches comes with it, and the compiler derives everything else.

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):

The source holds no condition. The manifest names only the roots.

D4 - Features only add, and a grammar’s streaming form is a feature’s.

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.

D5 - Features act on a rust-library build and on 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.

D6 - The compiler checks every feature alone and all of them together.

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):

D7 - [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.

4. Consequences

5. What this does not decide

This site is open source. Improve this page.