# Build scripts

Local release builds for Windows and Linux.

## Toolchain

You need a Rust toolchain (**1.88+**; CI uses 1.96). Install once:

```bash
# Recommended (any distro)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# then restart the shell, or: source "$HOME/.cargo/env"

# Or on Arch Linux
sudo pacman -S --needed rust
```

Also install the platform build libraries under **Linux build dependencies** below before `cargo test` / `cargo build`.

**Interactive shells:** the build scripts detect missing requirements (Rust, apt/pacman packages, `cargo-deb`, `base-devel`) and ask whether to install them automatically. Non-interactive runs (CI/pipes) never prompt; they print install instructions and exit.

## Windows

```powershell
.\scripts\build-windows.ps1
```

Output: `target\release\posprint.exe`

If `cargo`/`rustc` are missing and the shell is interactive, the script offers to install Rust via **winget** (`Rustlang.Rustup`) or **rustup-init**.

Options:

```powershell
.\scripts\build-windows.ps1 -SkipTests
```

## Linux

```bash
chmod +x scripts/build-linux.sh
./scripts/build-linux.sh                # release binary
./scripts/build-linux.sh --deb          # binary + .deb (prompts to install if interactive)
./scripts/build-linux.sh --deb --install  # build .deb and install with apt
```

On a TTY, missing **apt** build packages and (with `--deb`) **cargo-deb** are offered for install before building.

On **Arch Linux**:

```bash
chmod +x scripts/build-arch.sh
./scripts/build-arch.sh                 # .pkg.tar.zst (prompts to install if interactive)
./scripts/build-arch.sh --install      # build and install with pacman
```

On a TTY, missing **base-devel**, Rust, and common pacman build libs are offered for install before building.

`build-arch.sh` accepts a **rustup** toolchain on `PATH`. If the pacman `rust`/`cargo` packages are not installed, it runs `makepkg --nodeps` after verifying `rustc`/`cargo` work (the PKGBUILD still lists those packages for AUR/CI).

After a successful package build, both scripts ask whether to install (TTY only). Pass `--install` to skip the prompt and install automatically. Non-interactive runs (CI/pipes) never prompt.

Outputs:

| Artifact | Path |
|----------|------|
| Binary | `target/release/posprint` |
| Debian package | `target/debian/*.deb` |
| Arch package | `packaging/arch/posprint-*-x86_64.pkg.tar.zst` |

### Linux targets we support

| Format | Distros | Notes |
|--------|---------|-------|
| **`.deb`** | Debian, Ubuntu, Mint, Pop!_OS, etc. | **Recommended** for apt-based systems; produced by `cargo-deb` |
| **`.pkg.tar.zst`** | Arch Linux, Manjaro, EndeavourOS, etc. | **Recommended** for pacman; `sudo pacman -U posprint-*.pkg.tar.zst` |
| **Raw binary** | Any x86_64 Linux | Copy `target/release/posprint`; needs X11/Wayland libs at runtime |
| **`.rpm`** | Fedora, RHEL, openSUSE | Not automated yet; build binary and wrap with `fpm` if needed |
| **AppImage** | Universal | Not automated yet; good for portable distribution |

**Architecture:** `x86_64` (amd64) only in CI and build scripts today.

### Linux build dependencies (Debian/Ubuntu)

```bash
sudo apt-get install -y build-essential pkg-config \
  libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev \
  libssl-dev libudev-dev
```

For `.deb`:

```bash
cargo install cargo-deb --locked
```

### Arch Linux build dependencies

```bash
sudo pacman -S --needed base-devel rust pkgconf openssl libxkbcommon libxcb dbus \
  wayland libx11 fontconfig freetype2 libglvnd git rsync
```

### AUR publishing

Normal local Arch packaging uses `packaging/arch/PKGBUILD`.

Automated AUR publishing uses:

- `packaging/aur/PKGBUILD`
- `packaging/aur/.SRCINFO`
- `scripts/publish-aur.sh`

That AUR package builds from the GitLab tag tarball, not from a prebuilt binary.

Setup and required GitLab secrets are documented in [AUR.md](AUR.md).

### File association (`.pos` → posprint)

The package installs:

- `/usr/share/mime/packages/posprint.xml` → MIME type `application/x-posprint` for `*.pos`
- `/usr/share/applications/posprint.desktop` → claims that MIME type

After `pacman -U`, pacman hooks refresh the MIME and desktop databases. To make posprint the **default** opener (double-click):

```bash
xdg-mime default posprint.desktop application/x-posprint
xdg-mime query filetype some.pos          # expect: application/x-posprint
xdg-mime query default application/x-posprint  # expect: posprint.desktop
```

If `query filetype` still says `text/plain`, the MIME package was not installed or the cache is stale:

```bash
sudo update-mime-database /usr/share/mime
sudo update-desktop-database /usr/share/applications
```

## Tests before release

```bash
cargo test --release
```
