Skip to content
Merged
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
28 changes: 11 additions & 17 deletions .agents/skills/build-cadmus-native/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ it when documentation sources change.

## One-time setup

### 1. Native dependencies (MuPDF + C wrapper)

```bash
cargo xtask setup-native
```

This downloads MuPDF sources, applies Cadmus-specific patches, and compiles the
C wrapper library. It is **required** before any compilation or test run.

### 2. (Optional) Download runtime assets
### Download runtime assets (optional)

```bash
cargo xtask download-assets
Expand All @@ -47,6 +38,10 @@ cargo xtask download-assets
Pulls static assets (fonts, icons, etc.) from the latest GitHub release. Not
strictly required for compilation, but the emulator and some tests expect them.

Native dependencies (MuPDF, libwebp, and the C wrapper) are now built
automatically by `build.rs` when you run any Cargo command that compiles
`cadmus-core`.

## Daily workflow commands

| Goal | Command |
Expand Down Expand Up @@ -84,21 +79,20 @@ need to verify a specific one.

- **`fmt`** — runs `cargo fmt --check` (or `--apply` in CI) across the workspace
- **`clippy`** — iterates the full feature matrix; use `--features` to narrow it
- **`test`** — iterates the test feature matrix; native deps are assumed built
- **`run-emulator`** — ensures `setup-native` has run, then `cargo run -p emulator`
- **`install-importer`** — ensures `setup-native` has run, then `cargo install --path crates/importer`
- **`test`** — iterates the test feature matrix
- **`run-emulator`** — runs `cargo run -p emulator`
- **`install-importer`** — runs `cargo install --path crates/importer`

## Common mistakes

| Mistake | Result | Fix |
| ------------------------------------------------------------- | ------------------------------------------------------------- | -------------------------------------------------------- |
| Running `cargo check` before `cargo xtask docs --mdbook-only` | `RustEmbed` folder-not-found error | Generate the EPUB first |
| Running `cargo test` before `cargo xtask setup-native` | Linker errors for missing MuPDF / wrapper | Run `setup-native` first |
| Running bare `cargo clippy` / `cargo test` directly | May miss feature-gated code or use wrong feature combinations | Prefer `cargo xtask clippy` and `cargo xtask test` |
| Running `cargo xtask test` without `--features` | Runs the full (slow) CI matrix locally | Pass `--features default` or the specific combo you need |

## Platform notes

- **Linux**: `setup-native` builds MuPDF from source; ensure `gcc`, `make`, `cmake`, and standard build tools are installed.
- **macOS**: `setup-native` builds MuPDF from source; Xcode Command Line Tools must be installed.
- The `build-kobo` command is **Linux-only** (cross-compiles for ARM); it is not covered here because it runs inside a containerised CI action.
- **Linux**: Native dependencies are built from source automatically via `build.rs`; ensure `gcc`, `make`, `cmake`, and standard build tools are installed.
- **macOS**: Native dependencies are built from source automatically via `build.rs`; Xcode Command Line Tools must be installed. Full support including Kobo cross-compilation.
- The `build-kobo` command cross-compiles for ARM and is available on both Linux and macOS; it runs inside a containerised CI action in the main workflow.
34 changes: 7 additions & 27 deletions .agents/skills/build-kobo/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,24 @@ description: Cross-compile Cadmus for Kobo e-reader devices (ARM Linux). Use thi
---

Use `cargo xtask build-kobo` to cross-compile Cadmus for Kobo devices.
This task is **Linux only** — the Linaro ARM toolchain consists of x86_64 Linux
ELF binaries that cannot run on macOS. Use Docker or a Linux VM on macOS.
The Linaro ARM toolchain is supported on both Linux and macOS hosts.

## Basic usage

```sh
# Fast mode — downloads pre-built .so files (default)
# Cross-compile for Kobo
cargo xtask build-kobo

# Slow mode — builds all thirdparty libraries from source (required for CI)
cargo xtask build-kobo --slow

# Skip library download entirely (when libs/ already exists)
cargo xtask build-kobo --skip

# Download thirdparty sources only, without building
cargo xtask build-kobo --download-only

# Build with specific Cargo feature flags
cargo xtask build-kobo --features test
```

## Build modes

| Mode | Flag | Description |
| -------------------- | ------------------------ | ------------------------------------------------------- |
| Fast (default) | _(none)_ | Downloads pre-built `.so` files + MuPDF sources |
| Slow | `--slow` | Builds all thirdparty libraries from source |
| Slow + download only | `--slow --download-only` | Downloads all thirdparty sources without building |
| Skip | `--skip` | Assumes `libs/` already exists; skips download entirely |

## What it does

1. Verifies the Linaro ARM toolchain is available on `PATH`
2. Downloads or builds thirdparty `.so` libraries into `libs/`
3. Builds the `mupdf_wrapper` C library for the ARM target
4. Runs `cargo build --release --target arm-unknown-linux-gnueabihf -p cadmus`
2. Runs `cargo build --release --target arm-unknown-linux-gnueabihf -p cadmus`

Thirdparty dependencies (zlib, bzip2, libpng, libjpeg, openjpeg, jbig2dec, libwebp, freetype2, harfbuzz, gumbo, djvulibre, mupdf) are tracked as git submodules and built automatically by the `build-deps` crate's build.rs when needed. On a warm cache, no submodule initialisation or C/C++ compilation happens.

## Output

Expand All @@ -49,7 +30,6 @@ The compiled binary is written to:

## Prerequisites

- **Linux only** — exits with a clear error on macOS
- **Linux or macOS** — cross-compilation is supported on both platforms
- Linaro ARM toolchain on `PATH`: `arm-linux-gnueabihf-gcc`, `arm-linux-gnueabihf-ar`
(provided by the devenv shell on Linux)
- Run `cargo xtask setup-native` first if MuPDF sources are not yet present
(provided by the devenv shell)
4 changes: 2 additions & 2 deletions build-scripts/mupdf/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# MuPDF Patches for Cadmus

This directory contains the upstream MuPDF source tree (currently 1.27.0) plus
Cadmus-specific patches. The patches are applied by `cargo xtask setup-native`
and by the Kobo build scripts.
Cadmus-specific patches. The patches are applied automatically by the
`build-deps` crate's `build.rs` during compilation.

## Patch overview

Expand Down
16 changes: 2 additions & 14 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,9 @@ in
];
};

# Build mupdf and wrapper for native development
"deps:native" = {
exec = "cargo xtask setup-native";
};

# Build for Kobo with cross-compilation
"build:kobo" = {
exec = "cargo xtask build-kobo --slow";
exec = "cargo xtask build-kobo";
after = [ "docs:build" ];
};

Expand All @@ -704,14 +699,9 @@ in
zola serve --base-url http://localhost
'';

# Build mupdf for native development
cadmus-setup-native.exec = ''
cargo xtask setup-native
'';

# Build for Kobo device
cadmus-build-kobo.exec = ''
cargo xtask build-kobo --slow
cargo xtask build-kobo
cargo xtask dist
'';

Expand Down Expand Up @@ -766,7 +756,6 @@ in
echo "Cadmus development environment"
echo ""
echo "Available commands:"
echo " cadmus-setup-native - Build mupdf for native development (run once)"
echo " cadmus-docs-build - Build complete documentation portal"
echo " cadmus-docs-serve - Serve documentation locally (http://localhost:1111)"
echo " cargo test - Run tests (after setup)"
Expand All @@ -783,7 +772,6 @@ in
echo " cadmus-clippy - Lint lines changed vs master (reviewdog)"
echo " cargo xtask clippy - Lint across feature matrix"
echo " cargo xtask test - Test across feature matrix"
echo " cargo xtask setup-native - Build MuPDF for native development"
echo " cargo xtask docs - Build documentation portal"
echo " cargo xtask dist - Assemble Kobo distribution"
echo " cargo xtask bundle - Package KoboRoot.tgz"
Expand Down
Loading
Loading