Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions docs/dev/architecture/dependency-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ The controller checks the latest operation before continuing runtime work and
computes each plan from a fresh observation. Shared records avoid conversion
between separate store, API, and client operation models.

`just boundary` (`cargo xtask boundary`) checks that `piqueld-core` depends on no
server, Docker, database, or browser framework (`axum`, `bollard`, `sqlx`,
`leptos`), including through build and development dependencies. It also
checks that the daemon's crates don't depend on those they build alongside:
`piqueld-config` depends on no Docker, database, or browser framework, nor on
the daemon or its store; `piqueld-store` on no server, Docker, or browser
framework, nor on the daemon or its configuration, even in its tests; and
`piqueld-docker` on no server, database, or browser framework, nor on the
daemon, its configuration, or its store.
`just boundary` (`cargo xtask boundary`) checks each crate's dependencies on
every target, wasm32 included. `piqueld-core` depends on no server, Docker,
database, or browser framework (`axum`, `bollard`, `sqlx`, `leptos`), including
through build and development dependencies. `piqueld-client` depends on no
workspace crate but `piqueld-core` and `piqueld-probe`, so neither on the
daemon's crates nor on the CLI, dashboard or tooling, and on no Docker,
database, or browser framework, again including through build and development
dependencies. Only its native tests may use a server framework: they serve
their requests with `axum`. It also checks that the daemon's crates don't
depend on those they build alongside: `piqueld-config` depends on no Docker,
database, or browser framework, nor on the daemon or its store;
`piqueld-store` on no server, Docker, or browser framework, nor on the daemon
or its configuration, even in its tests; and `piqueld-docker` on no server,
database, or browser framework, nor on the daemon, its configuration, or its
store.
8 changes: 5 additions & 3 deletions docs/dev/rust-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ logic instead of copying it.

[Module boundaries](architecture/dependency-flow.md) describes each crate and
what it may depend on, and `just boundary` checks it. Shared contracts live in
`piqueld-core`, which knows no server, database, Docker or browser framework;
the daemon's crates (`piqueld-config`, `piqueld-store`, `piqueld-docker`)
don't depend on the ones they build alongside. A new dependency between
`piqueld-core`, which knows no server, database, Docker or browser framework.
`piqueld-client` depends on no workspace crate but `piqueld-core` and
`piqueld-probe`, and on none of those frameworks, except the server framework
its tests use. The daemon's crates (`piqueld-config`, `piqueld-store`,
`piqueld-docker`) don't depend on the ones they build alongside. A new dependency between
crates updates both that page and `tools/xtask/src/boundary.rs`.

A feature reaches every surface it applies to, from the checklist in
Expand Down
57 changes: 51 additions & 6 deletions tools/xtask/src/boundary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! `just boundary`: checks the workspace's dependency boundaries.
//! `piqueld-core` holds the shared contracts, so it must not depend on the
//! server, Docker, database, or browser frameworks. The daemon's own crates
//! build in parallel only while they don't depend on each other.
//! server, Docker, database, or browser frameworks. `piqueld-client` builds
//! for wasm32 too, so it must not depend on any other workspace crate but
//! `piqueld-core` and `piqueld-probe`, nor on those frameworks, except for the
//! server framework its native tests use.
//! The daemon's own crates build in parallel only while they don't depend on
//! each other.

use std::process::ExitCode;

Expand All @@ -11,7 +15,7 @@ use crate::Workspace;
use crate::process::checked_stdout;

/// A package that must not depend on any of `forbidden`, through the
/// dependency kinds of `edges`.
/// dependency kinds of `edges`, on any target.
struct Boundary {
package: &'static str,
/// `cargo tree --edges` kinds.
Expand All @@ -21,7 +25,7 @@ struct Boundary {
reason: &'static str,
}

const BOUNDARIES: [Boundary; 4] = [
const BOUNDARIES: [Boundary; 6] = [
Boundary {
package: "piqueld-core",
// The client and dashboard build it, so its build and development
Expand All @@ -38,6 +42,37 @@ const BOUNDARIES: [Boundary; 4] = [
],
reason: "holds the shared contracts, without server, Docker, database, or browser frameworks",
},
Boundary {
package: "piqueld-client",
// It builds for wasm32 and is published, so its build and development
// dependencies count too; its server framework is checked below.
edges: "all",
forbidden: &[
"bollard",
"bollard-stubs",
"leptos",
"sqlx",
"sqlx-core",
// Every workspace crate but `piqueld-core` and `piqueld-probe`.
"piquelctl",
"piqueld",
"piqueld-build",
"piqueld-config",
"piqueld-docker",
"piqueld-generated",
"piqueld-store",
"piqueld-ui",
"xtask",
],
reason: "is the published client the CLI and dashboard share, without the other workspace crates or Docker, database, or browser frameworks",
},
Boundary {
package: "piqueld-client",
// Its native tests serve their requests with axum.
edges: "normal,build",
forbidden: &["axum", "axum-core"],
reason: "is the published client, which builds for wasm32, so only its tests may use a server framework",
},
Boundary {
package: "piqueld-config",
edges: "normal,build",
Expand Down Expand Up @@ -73,7 +108,14 @@ pub fn check(workspace: &Workspace) -> Result<ExitCode> {
let output = workspace
.cargo()
.args(["tree", "--locked", "--package", boundary.package])
.args(["--edges", boundary.edges, "--prefix", "none"])
.args([
"--edges",
boundary.edges,
"--target",
"all",
"--prefix",
"none",
])
.output()
.context("run cargo tree")?;
let tree = checked_stdout("cargo tree", output)?;
Expand All @@ -86,7 +128,10 @@ pub fn check(workspace: &Workspace) -> Result<ExitCode> {
})
.collect();
if forbidden.is_empty() {
println!("{} dependency boundary is intact", boundary.package);
println!(
"{} dependency boundary is intact ({} dependencies)",
boundary.package, boundary.edges
);
} else {
eprintln!(
"{} {}, but depends on:\n{}",
Expand Down