007: Architecture¶
- Type: Architecture
- Status: Accepted
- Date: 2026-12-02
- Author(s) / Deciders: João V. Farias
- Question: How is
winesmithstructured across Rust modules, external system boundaries, configuration layers, and diagrams?
Context¶
Replacing per-project Wine shell scripts with a compiled Linux binary requires clean module boundaries around volatile OS and network operations. Isolating HTTP transfers, Wine subprocess execution, filesystem mounts, /proc scans, and Nushell completion generation behind focused Rust modules lets unit and integration tests verify core logic without running Wine.
System diagrams¶
Two Mermaid diagrams summarize external actors and internal data movement.
Use-case overview¶
This diagram shows the core workflows available to Linux developers, headless CI pipelines, and Nushell users:
flowchart LR
Dev(["Linux Developer"])
CI(["Headless CI Pipeline"])
NuShell(["Nushell 0.117+ User"])
subgraph System["winesmith CLI System"]
UC1(("Initialize project manifest"))
UC2(("Provision runner, prefix & toolchains"))
UC3(("Execute hybrid Wine/Host build task"))
UC4(("Run ad-hoc Windows command"))
UC5(("Open interactive Wine shell"))
UC6(("Audit environment with doctor"))
UC7(("Manage prefixes & runners"))
UC8(("Install Nushell completions & query tables"))
end
Dev --> UC1
Dev --> UC2
Dev --> UC3
Dev --> UC4
Dev --> UC5
Dev --> UC6
Dev --> UC7
CI --> UC2
CI --> UC3
CI --> UC4
CI --> UC6
NuShell --> UC3
NuShell --> UC4
NuShell --> UC7
NuShell --> UC8
Data-flow pipeline¶
This data-flow diagram traces manifests and lockfiles through runner resolution, prefix storage, recipe installation, and process execution:
flowchart LR
Manifest["winesmith.toml + local + env + CLI"] --> P1["1. Config & Template Engine"]
LockIn["winesmith.lock"] --> P1
P1 --> P2["2. Runner Resolver"]
P2 <--> Cache[("XDG Download Cache")]
P2 --> Runners[("XDG Runners Store")]
P2 --> P3["3. Prefix Provisioner"]
P1 --> P3
P3 <--> Prefixes[("Wine / Proton Prefixes + state.json")]
P3 --> P4["4. Toolchain Recipe Engine"]
Cache --> P4
P4 --> Prefixes
P4 --> LockOut["Updated winesmith.lock"]
P1 --> P5["5. Hybrid Task & Exec Engine"]
Runners --> P5
Prefixes --> P5
P5 --> WineProc["Windows Binary via Per-Call .cmd Wrapper"]
P5 --> HostProc["Linux Host Command / Process Guard"]
WineProc --> Output["Compiled Artifacts, Logs & Exit Code"]
HostProc --> Output
P1 --> P6["6. Query & Nushell Completer"]
Prefixes --> P6
Runners --> P6
P6 --> NuOut["JSON Tables / Dynamic Completions"]
Requirements and restrictions¶
Implementation choices obey three structural boundaries across the Rust crate and host filesystem:
- The binary builds with synchronous Rust (Edition 2024, MSRV 1.85) using
clap,serde,toml,minijinja,thiserror,miette,ureqoverrustls,sha2,fs4, and pure-Rust archive crates (tar,flate2,lzma-rust2,zip,sevenz-rust2) for staticmuslcompilation. - User settings, download archives, runners, prefixes, and shell completions follow standard XDG paths (
$XDG_CONFIG_HOME/winesmith/config.toml,$XDG_CACHE_HOME/winesmith/downloads/,$XDG_DATA_HOME/winesmith/runners/,$XDG_DATA_HOME/winesmith/prefixes/, and$XDG_CONFIG_HOME/nushell/autoload/winesmith.nu). - External process boundaries are limited to Wine or Proton binaries, optional
xvfb-runandwinetricks,/bin/shfor host steps, and HTTPS endpoints for upstream SDKs and runners.
Alternatives¶
Rewriting neorune.nu into a shared Nushell script package would force every Linux developer and CI container to install Nushell before compiling a Windows project. A Go binary avoids a shell runtime dependency, yet Rust provides stronger algebraic enums over manifest and state schemas, source-span TOML errors via miette, and direct POSIX file-lock and signal libraries. Organizing the tool inside a single monolithic source file speeds up initial experiments, while making unit tests hard to isolate.
Decision¶
Organize winesmith as a modular Rust library crate (src/lib.rs) paired with a thin CLI binary entrypoint (src/main.rs):
winesmith/
├── Cargo.toml
├── LICENSE # GNU AGPL v3.0
├── COPYING.EXCEPTION # Compilation Output Exception (Section 7)
├── src/
│ ├── main.rs # CLI entrypoint and exit code mapping
│ ├── lib.rs # Library exports for binary and test crates
│ ├── error.rs # WinesmithError variants, miette spans, exit codes
│ ├── cli.rs # Long-only clap command definitions and __complete
│ ├── config/
│ │ ├── mod.rs # Six-layer manifest merger
│ │ ├── schema.rs # Serde schema structs and validation
│ │ ├── lockfile.rs # winesmith.lock reader, writer, SHA-256 checks
│ │ └── template.rs # MiniJinja renderer and winpath(...) helper
│ ├── runner/
│ │ ├── mod.rs # Runner paths, RunnerLayout, and resolver
│ │ ├── kron4ek.rs # Portable Kron4ek Wine 10 resolver
│ │ ├── system.rs # Host system Wine and explicit path resolver
│ │ ├── proton.rs # Steam Proton VDF discovery and GE-Proton downloads
│ │ └── download.rs # Streaming HTTPS/file fetcher and pure-Rust unpacker
│ ├── prefix/
│ │ ├── mod.rs # Shared/isolated prefix scoping and fs4 locks
│ │ ├── init.rs # Prefix boot, OS version, dialog suppression, registry
│ │ ├── mounts.rs # dosdevices/ drive mounts and drive_c symlinks
│ │ └── state.rs # winesmith-state.json persistence and drift checks
│ ├── exec/
│ │ ├── mod.rs # Per-call WrapperGuard .cmd execution and signal handling
│ │ ├── display.rs # None, xvfb-run, and host display adapters
│ │ ├── paths.rs # Batch escaping and safe exec argument path translation
│ │ └── wineserver.rs # Persistent wineserver startup
│ ├── recipe/
│ │ ├── mod.rs # Provisioning orchestrator, win7 warnings, ad-hoc specs
│ │ ├── generic.rs # Custom URL, archive, MSI/EXE, registry, winetricks hooks
│ │ ├── dotnet.rs # .NET SDK, shared NuGet cache, templates, global tools
│ │ ├── python.rs # NuGet portable Windows Python, ensurepip, pip packages
│ │ └── packagers.rs # Inno Setup and NSIS provisioning
│ ├── tasks/
│ │ ├── mod.rs # Topological DAG runner, Wine + Host steps, env/cwd
│ │ └── guards.rs # Linux /proc scanner for forbid_running regex patterns
│ ├── completions/
│ │ └── mod.rs # Nushell script template and fast local __complete logic
│ └── commands/
│ ├── mod.rs # Top-level dispatch plus config and tasks subcommands
│ ├── init.rs # Starter manifest scaffolding and .gitignore updates
│ ├── setup.rs # Matrix setup and lockfile persistence
│ ├── run.rs # Hybrid task orchestration and --all-targets runner
│ ├── exec.rs # Shared lazy runtime setup and ad-hoc exec handler
│ ├── shell.rs # Interactive cmd.exe launcher
│ ├── doctor.rs # Host, runner, lockfile, prefix, and toolchain audits
│ ├── env.rs # Prefix list, inspect, path, rm, and prune subcommands
│ ├── runner.rs # Runner list, install, rm, and detect subcommands
│ └── completions.rs # Nushell script emitter, installer, and __complete CLI
└── tests/
├── unit/ # White-box unit tests
├── integration/ # Hermetic mock-server and CLI black-box tests
└── e2e/ # Ignored live Wine end-to-end tests
Configuration layering precedence¶
Each layer overrides matching keys from earlier layers in strict order:
- Built-in defaults select
kron4ekWine 10staging-amd64-wow64,win10,win64,display = "none", andprefix.mode = "shared". - Global user settings load from
~/.config/winesmith/config.toml. - Project defaults load from
winesmith.toml. - Machine-specific overrides load from gitignored
winesmith.local.toml. - Process environment variables (
WINESMITH_*) override config file values. - CLI flags (
--target,--win,--arch,--display,--gui,--runner,--var) and positionalKEY=VALUEpairs onrunoverride all other layers.
CLI command surface¶
The table below maps every user-facing command to its Nushell integration mode:
| Command | Role | Nushell mode |
|---|---|---|
winesmith init |
Scaffold starter winesmith.toml |
extern --strict |
winesmith setup |
Provision runner, prefix, mounts, toolchains, and lockfile | extern --strict |
winesmith run <task> [key=value ...] |
Execute declared Wine and host tasks | def --wrapped |
winesmith exec [flags] -- <cmd...> |
Execute project or ad-hoc Windows command | def --wrapped |
winesmith shell |
Launch interactive Wine cmd.exe with loaded environment |
extern --strict |
winesmith doctor [--json] |
Audit host tools, runners, prefix registry, and toolchains | extern --strict + @structured |
winesmith env <subcmd> [--json] |
List, inspect, locate, remove, or prune prefixes | extern --strict + @structured |
winesmith runner <subcmd> [--json] |
List, install, remove, or detect runners | extern --strict + @structured |
winesmith config [--json] |
Print resolved configuration | extern --strict + @structured |
winesmith tasks [--json] |
List declared project tasks | extern --strict + @structured |
winesmith completions nu |
Print Nushell integration script | extern --strict |
winesmith completions install nu |
Write Nushell script to user autoload directory | extern --strict |
winesmith __complete <kind> |
Fast JSON candidate lookup for Nushell completers | Hidden |
Consequences¶
Positives¶
Isolating pure configuration, path conversion, and DAG logic from OS subprocess adapters lets unit and integration tests run offline without launching Wine. Exporting library modules from src/lib.rs supports clean separation between white-box and black-box tests.
Negatives¶
Adding new runner kinds or subcommand options requires updating src/cli.rs, the completion script in src/completions/mod.rs, and the CLI parity tests together.