Skip to content

arch: freeze the crate layout — criteria for adding a crate, and ask the dev first #152

Closed

Description

@zackees

Why

reld has 7 crates today and they were not designed as a set. Two recent changes were shaped by that: the #137 host-platform facade could not be a leaf crate the way soldr and zccache did it, so it went inside reld-core; and in the same change reld-testkit and reld-diff had to avoid the facade entirely, because giving them a path to it would have meant a new dependency edge.

The goal is a stable, deliberately small crate set: a default answer of "add a module, not a crate", written criteria for the rare case where a new crate is justified, and the developer is asked before any new crate is created.

Current layout

Crate Lines Purpose Depends on
reld 87 binaries reld / reld-link reld-core, (dev) reld-diff, reld-layout-schema
reld-core 60,734 the linker itself reld-layout-schema, reld-reloc, reld-trace
reld-diff 10,386 diffs and validates ELF binaries reld-layout-schema, reld-reloc, reld-trace
reld-reloc 4,758 relocation code shared by core and diff —
reld-testkit 2,252 synthetic workloads for bench/stress/difftest (publish = false) —
reld-layout-schema 166 layout data structures —
reld-trace 69 trace output data structures —

The shape is coherent: one big implementation crate, a thin binary crate, one consumer tool, and small leaf crates that exist so reld-core and reld-diff can share types without depending on each other. Nothing here needs splitting.

Proposal

1. Default: add a module, not a crate

New functionality goes into an existing crate as a module. reld-core being large is not by itself a reason to split it: it is one program, and its compile time is dominated by the linker implementation, not by crate boundaries.

2. Criteria for a new crate

Every one of these must hold, and the first two are the load-bearing ones:

  1. More than one crate must depend on it, or it must be consumed by something outside this repo. A single consumer means a module.
  2. It removes a dependency edge that would otherwise be wrong, e.g. two crates needing shared types without depending on each other (reld-reloc, reld-layout-schema, reld-trace all exist for exactly this).
  3. It has a stable, narrow public surface that can be documented in a sentence.
  4. It does not create a cycle or a diamond that forces a lockstep version bump across the workspace.
  5. It is not test-only scaffolding unless it is shared by several test targets, in which case it is publish = false like reld-testkit.

Reasons that are explicitly not sufficient: a file is long; "this feels like its own concern"; a desire for faster incremental builds without a measurement showing a crate split achieves it; or mirroring another project's layout (soldr and zccache are daemons with many consumers, reld is one linker).

3. Ask the developer first

Adding a workspace member requires developer approval before the work starts, in the issue that motivates it. This mirrors the #88 rule for third-party dependencies. The request should state which criteria above are met, which edges it removes, and what the public surface is.

Agents must not create a crate on their own initiative, and must not work around the absence of one by duplicating code across crates. If a boundary genuinely hurts, say so and ask.

4. Enforcement

  • A CI check that fails when [workspace].members changes without a matching approval reference, in the spirit of ci/check_dependencies.py. The dependency baseline already records intra-workspace edges, so a new crate shows up there as a new edge; extend that guard with a clear message pointing at this issue rather than adding a new mechanism.
  • Record the criteria in AGENTS.md next to the existing dependency and host-platform rules.

Open questions for the developer

  1. Is 7 the intended steady state? If the plan is to stay at 7 unless a new consumer appears, I will write that down as the target.
  2. Does the host-platform facade eventually want to be a leaf crate? Today it lives in reld-core/src/platforms/ (refactor: centralize host-platform cfg behind crate::platform + cfg_select!, enforced by Dylint #137), so reld-diff and reld-testkit cannot use it and instead avoid host selection entirely. That is working, but a reld-platform leaf crate is the shape soldr and zccache chose. This is the single most likely candidate for crate number 8, and it should be a deliberate decision rather than a drive-by one.
  3. Does reld-trace (69 lines) still earn its place, or should it fold into reld-layout-schema now that both are consumed by the same two crates? Merging would take the count to 6.

Acceptance

  • The criteria above are agreed and recorded in AGENTS.md.
  • The steady-state crate count and the answers to the open questions are recorded here.
  • A CI guard fails a PR that adds a workspace member without an approval reference.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions