This document provides an overview of the cpclib workspace architecture and how the various crates interact.
cpclib is a large Cargo workspace containing 40+ crates organized into several functional layers:
┌─────────────────────────────────────────────────────────┐
│ User-Facing Tools │
│ cpclib-basm, cpclib-bndbuild, cpclib-xfertool, etc. │
└─────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────┐
│ High-Level Libraries │
│ cpclib, cpclib-runner, cpclib-asm, cpclib-disc │
└─────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────────┐
│ Core Libraries │
│ cpclib-common, cpclib-tokens, cpclib-macros │
└─────────────────────────────────────────────────────────┘
-
cpclib-common(v0.11.0)- Shared types, utilities, and event system
- Used by almost all other crates
- Provides: logging, paths, itertools re-exports
-
cpclib-macros(v0.11.0)- Procedural macros for code generation
- Derive macros for common patterns
-
cpclib-tokens(v0.11.0)- Symbol table and token management
- Expression evaluation
- Used by assembler and parser
-
cpclib-sna(v0.11.0)- Snapshot (.SNA) file reading/writing
- Chunk-based format support
- Memory state serialization
-
cpclib-disc(v0.11.0)- DSK file manipulation
- Format, read, write operations
- Compatible with iDSK/dskmanager
-
cpclib-cpr(v0.11.0)- Cartridge (.CPR) file handling
- GX4000 cartridge format
-
cpclib-cprcli(v0.11.0)- Command-line tool for CPR manipulation
- Create and inspect cartridge files
-
cpclib-basic(v0.11.0)- BASIC tokenization and parsing
- Source to token conversion
- Round-trip encode/decode support
-
cpclib-locomotive(v0.11.0)- Locomotive BASIC manipulation tool
- ASCII ↔ binary BASIC conversion
- Integrated into bndbuild
-
cpclib-files(v0.11.0)- Generic file utilities
-
cpclib-asm(v0.11.0)- Core assembler engine
- Z80 instruction set support
- Expression parser and evaluator
-
cpclib-basm(v0.11.0)- Command-line assembler binary
- Multiple pass assembly
- Macro system
- Primary assembler for the toolchain
-
cpclib-bdasm(v0.11.0)- Disassembler binary
- Z80 code to assembly conversion
-
cpclib-basmdoc(v0.11.0)- Documentation generator for assembly source
-
cpclib-z80emu(v0.11.0)- Basic Z80 emulator
- Used for instruction validation
-
cpclib-orgams-ascii(v0.11.0)- Orgams ASCII format support
- On-CPC assembler compatibility
-
cpclib-borgams(v0.11.0)- Borgams tool for Orgams integration
- Converts between Orgams formats
-
cpclib-image(v0.11.0)- CPC image format representation
- Mode 0, 1, 2 support
- Palette management
-
cpclib-imgconverter(v0.11.0)- Image conversion to CPC formats
- Multiple dithering algorithms
- Command-line tool
-
cpclib-sprite-compiler(v0.11.0)- Sprite data compilation
- Optimized sprite generation
-
cpclib-crunch(v0.11.0)- Compression interface
- Z80-targeted crunchers
-
cpclib-crunchers(v0.11.0)- Multiple compression algorithms
- Exomizer, ZX0, LZSA support
- Includes native C implementations
-
cpclib-bndbuild(v0.11.0)- Build automation tool (Make alternative)
- YAML-based project files
- Task orchestration
- Central build system for demo projects
-
cpclib-bndbuild-ratatui(v0.11.0)- Terminal UI (TUI) frontend for bndbuild
- Interactive build monitoring
- Built with ratatui library
-
cpclib-runner(v0.11.0)- External tool management
- Emulator control
- Download and cache external tools
- Supports: Rasm, Winape, ACE, AT3, etc.
-
cpclib-xfer(v0.11.0)- Library for cpcwifi/M4 communication
- File transfer protocols
-
cpclib-xfertool(v0.11.0)- Command-line tool for hardware transfers
- Interactive REPL mode
-
cpclib-emucontrol(v0.11.0)- Emulator remote control
- Script automation
-
cpclib-csl(v0.11.0)- CSL (CPC Script Language) parser
- Emulator scripting language types
- AST and evaluation
-
cpclib-cslcli(v0.11.0)- CSL command-line tool
- Execute CSL scripts
-
cpclib-visual-basm(v0.11.0)- GUI frontend for assembler
- Syntax highlighting
- Build integration
-
cpclib-visual-bndbuild(v0.11.0)- GUI frontend for build system
- Project visualization
-
cpclib-bndbuild-tauri(v0.1.0)- Tauri-based GUI alternative
- Cross-platform desktop app
-
cpclib-wasm(v0.11.0)- WebAssembly bindings
- Browser-based tooling
- Website at https://cpcsdk.github.io/rust.cpclib/
-
cpclib-python(v0.11.0)- Python bindings via PyO3
- Python API for toolchain
-
cpclib-catart(v0.11.0)- Catart-related functionality
- Demo catalog generation
- Amstrad CPC demo scene tools
-
cpclib-catalog(v0.11.0)- Amsdos catalog manipulation
- Directory listing utilities
- DSK catalog operations
cpclib(v0.11.0)- Umbrella crate combining most functionality
- Re-exports from other crates
- Unified API surface
- Start here for library usage
cpclib (facade)
├── cpclib-asm
│ ├── cpclib-tokens
│ └── cpclib-common
├── cpclib-disc
│ └── cpclib-common
├── cpclib-sna
│ └── cpclib-common
├── cpclib-image
│ └── cpclib-common
└── cpclib-basic
└── cpclib-common
cpclib-basm (CLI tool)
└── cpclib-asm
└── ...
cpclib-bndbuild (build tool)
├── cpclib-runner
│ └── cpclib-common
└── cpclib
└── ...
- Most crates use
Result<T, String>or custom error types thiserrorfor error derivation- Moving toward proper
Resultpropagation (reducing.unwrap())
cpclib-commonprovidesEventObservertrait- Used for progress reporting and logging
- Allows GUI and CLI tools to share logic
- Workspace dependencies use
default-features = false - Optional features for GUI, hardware, etc.
- Minimizes binary size for focused builds
- Shared metadata in workspace
Cargo.toml edition = "2024"across all crates- MIT license throughout
- Current version:
v0.11.0for all workspace crates
User writes:
- .asm files (assembly source)
- .bas files (BASIC source)
- build.yml (bndbuild config)
- .png images
↓
bndbuild orchestrates:
1. Image conversion (cpclib-imgconverter)
2. BASIC conversion (cpclib-locomotive)
3. Assembly (cpclib-basm)
4. Compression (cpclib-crunchers)
5. DSK creation (cpclib-disc)
6. Catalog operations (cpclib-catalog)
7. Emulator launch (cpclib-runner)
8. Hardware transfer (cpclib-xfer)
↓
Output:
- .sna snapshots
- .dsk disk images
- .bin binaries
- .cpr cartridges
- Create crate directory under workspace root
- Add to
membersin workspaceCargo.toml - Add workspace dependency entry
- Add
[patch.crates-io]entry if needed - Use workspace inheritance:
[package] edition.workspace = true license.workspace = true authors.workspace = true
- Document in this file
The cpclib-runner crate manages external tools:
- Assemblers: Rasm, Orgams, Sjasmplus, Vasm, uz80
- Emulators: WinAPE, ACE, CPCEC, Sugarbox, AmSpirit, Caprice
- Trackers: ArkosTracker 3, ChipNSFX
- Compression: Exomizer, LZSA, DZ80
- Graphics: Martine, Grafx2, img2cpc
- Disk Utils: ImpDSK, Disark
- Others: Various converters and utilities
Tools are downloaded, cached, and versioned automatically.
- Unit tests: In each crate's
tests/directory - Integration tests: In workspace-level
tests/ - Cross-assembler tests:
cpclib-rasm-basm-testsvalidates compatibility - Examples: In crate
examples/directories
Typical demo project structure:
my-demo/
├── build.yml # bndbuild configuration
├── src/
│ ├── main.asm # Main assembly source
│ └── data.asm # Data includes
├── gfx/ # Source images
└── music/ # AT3 tracker files
Run: bndbuild in project directory
- Main docs: https://cpcsdk.github.io/rust.cpclib/
- Generated via
mkdocsfromdocs/directory - API docs:
cargo doc --open
-
BASIC Support: Added
cpclib-locomotivefor BASIC ↔ binary conversion- Fixed round-trip encoding/decoding bugs in
cpclib-basic - Properly handles string literals with closing quotes
- Integrated into bndbuild workflow
- Fixed round-trip encoding/decoding bugs in
-
Terminal UI: Added
cpclib-bndbuild-ratatuifor interactive builds -
Emulator Scripting: Added
cpclib-cslandcpclib-cslclifor CSL support -
Catalog Tools: Enhanced catalog manipulation with
cpclib-catalogandcpclib-catart -
Orgams Support: Better on-CPC assembler compatibility via
cpclib-borgams
- Reduce
.unwrap()panics throughout codebase - Stabilize APIs for v1.0 release
- Better error messages with source spans
- Incremental compilation support
- Plugin system for custom tasks
- Improved IDE integration and LSP support