# Bundle layouts

> What each bundle format holds, how a bundled app finds its Chromium and how that runtime is verified.

This page describes what [`kurogane bundle`](https://kurogane-rs.org/docs/shipping/bundling.md) produces. You don't need it to bundle an app. Read it to debug a bundle, write an installer around one or check what ships.

## What every bundle carries

* Your app's binary
* The Chromium runtime, laid out as the platform loads it
* CEF's notices, `LICENSE.txt` and `CREDITS.html`
* Your built frontend in `content/`, when the project has one
* The extra files `[[bundle.resources]]` declares

The runtime leaves out CEF's development material (`include/`, `cmake/`, `libcef_dll/`, `CMakeLists.txt`, `libcef.lib`), its download records (`archive.json`, the original archive) and CEF's sandbox bootstraps. A sandboxed Windows bundle ships one bootstrap under your app's name.

## Linux directory

`--format dir` on Linux:

```text
dist/
├── myapp                      # launcher script
├── runtime/
│   ├── myapp                  # your binary
│   ├── kurogane-bundle        # marker: run only the runtime below
│   └── cef/                   # the Chromium runtime
│       ├── libcef.so
│       ├── locales/
│       ├── icudtl.dat
│       ├── chrome-sandbox
│       └── ...
├── content/                   # your frontend
│   └── index.html
└── assets/                    # extra resources
```

Users start the launcher, `./dist/myapp`. It execs the binary in `runtime/` and leaves the working directory alone:

```sh
#!/usr/bin/env sh
set -eu

ROOT="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"

# Opt-in library path for libraries the system's loader does not find
if [ -n "${KUROGANE_LD_LIBRARY_PATH:-}" ]; then
    export LD_LIBRARY_PATH="$KUROGANE_LD_LIBRARY_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi

exec "$ROOT"/'runtime/myapp' "$@"
```

The binary's path is one single-quoted word. No character of a name expands in the script.

### Library loading

The marker tells your app it runs from a bundle. The app loads `libcef.so` by its full path in `runtime/cef`. Nothing is baked in at link time and Kurogane sets no `LD_LIBRARY_PATH`.

Some systems, NixOS among them, have a loader that doesn't find libcef's own system libraries. `KUROGANE_LD_LIBRARY_PATH` adds them for one run. It's never set for you:

```bash
KUROGANE_LD_LIBRARY_PATH=/nix/store/...-lib ./dist/myapp
```

### chrome-sandbox

`chrome-sandbox` ships without setuid bits. It stays unused unless your app runs under [`SandboxMode::Chromium`](https://kurogane-rs.org/docs/concepts/sandbox.md) on a system without user namespaces. An installer that wants that route makes the bundled `cef/chrome-sandbox` owned by root and setuid (`chown root:root`, `chmod 4755`).

## Windows directory

`--format dir` on Windows:

```text
dist/
├── myapp.exe                  # your binary
├── myapp.exe.manifest         # CEF's application manifest
├── kurogane-bundle            # marker: run only the runtime here
├── libcef.dll
├── chrome_elf.dll
├── locales/
├── icudtl.dat
├── v8_context_snapshot.bin
├── content/                   # your frontend
│   └── index.html
└── assets/                    # extra resources
```

Chromium sits beside the executable, where CEF's sandbox bootstrap needs it. Your app loads `libcef.dll` by its full path. Chromium's DLLs load from `libcef.dll`'s own directory and never from `PATH`. Keep them together.

`myapp.exe.manifest` is the manifest CEF's own executables carry. Windows reads it when the executable embeds none. An app whose `build.rs` calls `kurogane_build::build()` embeds the same one.

### Sandboxed

With `sandbox = true` under `[app]` CEF's windowed bootstrap takes your app's name and your app becomes a library beside it:

```text
dist/
├── myapp.exe                  # CEF's bootstrap, under your app's name
├── myapp.dll                  # your app
├── myapp.exe.manifest
├── kurogane-bundle
├── libcef.dll
└── ...
```

CEF finds the library by the bootstrap's name in the bootstrap's directory. The bundler keeps the two names in step.

Sign both binaries or neither. The bootstrap refuses to load a library unless both are unsigned or both carry the same valid certificate. `kurogane bundle --sign` signs every binary in the bundle.

## Linux AppImage

`--format appimage` wraps the Linux directory bundle as it is:

```text
squashfs-root/                       # ./myapp.AppImage --appimage-extract
├── AppRun                           # execs the bundle's launcher
├── myapp.desktop
├── myapp.png
├── .DirIcon -> myapp.png
└── usr/
    ├── lib/myapp/                   # the directory bundle, unchanged
    ├── share/applications/myapp.desktop
    └── share/icons/hicolor/256x256/apps/myapp.png
```

* `usr/lib/<name>/` is exactly what `--format dir` produces and passes the same checks.
* linuxdeploy adds the desktop integration and the system libraries Chromium links against, such as nss, glib and atk. Kurogane keeps it from copying, stripping or relinking the bundle and from duplicating the Chromium runtime.
* The desktop entry names the window class (`StartupWMClass`) from `[app].identifier`, or the executable's name without one. Give [`App::window_class`](https://kurogane-rs.org/docs/api/app/app.md#method.window_class) the same value.
* The desktop entry's `Version=` is the specification's version, `1.0`. Your app's version goes in `X-AppImage-Version=`.

An AppImage mounts `nosuid`. Under the sandbox it relies on user namespaces.

## Windows installer

`--format nsis` installs the verified directory bundle whole:

```text
dist/
├── myapp_1.0.0_x64-setup.exe       # the installer
├── bundle/                          # the staged bundle
└── installer.nsi                    # the generated script
```

The installer:

* installs per user, into `%LOCALAPPDATA%` by default
* creates Start Menu and Desktop shortcuts as `[windows]` asks
* registers in **Add or remove programs** under the current user
* ships an uninstaller that removes the installation, the shortcuts and the registry keys

## macOS app

`--format app` keeps the CEF framework whole inside the `.app`:

```text
dist/
├── MyApp.dmg                                # the app beside a link to /Applications
└── MyApp.app/
    └── Contents/
        ├── Info.plist
        ├── MacOS/
        │   └── myapp                        # your binary
        ├── Frameworks/
        │   ├── Chromium Embedded Framework.framework/
        │   ├── MyApp Helper.app/
        │   ├── MyApp Helper (GPU).app/
        │   ├── MyApp Helper (Plugin).app/
        │   ├── MyApp Helper (Renderer).app/
        │   └── MyApp Helper (Alerts).app/
        └── Resources/
            ├── AppIcon.icns                 # from [app].icon
            ├── Chromium Embedded Framework/ # CEF's notices
            └── content/                     # your frontend
```

Both are named after `[app].name`, or the crate's name without one. There is no macOS `--format dir`. A flat directory couldn't be signed or double-clicked.

### What the app declares

Every `Info.plist` in the bundle declares:

* `LSMinimumSystemVersion`, from `[macos] minimum-system-version` or else `12.0`, the oldest macOS CEF runs on
* `NSCameraUsageDescription` and `NSMicrophoneUsageDescription`, from `[macos.privacy]` or Kurogane's generic wording

The app's own plist also carries `LSApplicationCategoryType` from `[macos] category`, `public.app-category.utilities` by default. Kurogane checks these values before anything is built on macOS.

### Helpers

Each helper is your binary again under its own bundle identifier. See [Process model](https://kurogane-rs.org/docs/concepts/process-model.md#helpers-on-macos). The app finds the `<name> Helper.app` bundle whatever the `.app` is called. A `.app` without exactly one refuses to start and says to reinstall.

### The framework

The app links the framework at `@executable_path/../Frameworks`. The helpers reach the same folder from inside their bundles. There is no RPATH. Each executable reaches only the framework of its own bundle wherever the bundle moves.

A bundled app uses its own framework even when `CEF_PATH` is set. A binary from `cargo build` or `kurogane run` links no framework and opens the installed one by path.

## How a bundled app finds its runtime

The `kurogane-bundle` marker, or the `.app` itself on macOS, makes your app run only the Chromium inside its bundle. It never reads `CEF_PATH` or the installation then. A bundle whose runtime is gone reports itself incomplete.

Relative paths such as `App::new("content")` resolve against the bundle's resource root:

| Platform | Executable | Resource root |
|---|---|---|
| Linux | `<root>/runtime/<exe>` | `<root>` |
| Windows | `<root>/<exe>.exe` | `<root>` |
| macOS | `<name>.app/Contents/MacOS/<exe>` | `<name>.app/Contents/Resources` |

An unbundled run, `cargo run` among them, loads the first runtime it finds:

1. A runtime beside its executable
2. The runtime `CEF_PATH` names
3. tanso's installation of the CEF version it was built against

A `CEF_PATH` that names no directory is an error and never skipped. Loading refuses a libcef from another CEF build than the app was built against.

## How the runtime is verified

`kurogane install` writes an `archive.json` into every installation:

```json
{
  "type": "minimal",
  "name": "cef_binary_154.0.33+ga03e714+chromium-154.0.8037.94_linux64_minimal.tar.bz2",
  "sha1": "..."
}
```

`export-cef-dir` writes one too. A distribution passes when:

* the runtime is complete and carries CEF's notices
* the CEF version in the archive's name equals your project's exactly; `154.0.33+ga03e714` matches `154.0.33` and `154.0.34` doesn't
* the platform matches the target

After copying, every format checks the runtime holds what Chromium needs to run:

| Linux | Windows | macOS |
|---|---|---|
| `libcef.so` | `libcef.dll` | the framework and its binary |
| `chrome-sandbox` | `chrome_elf.dll` | |
| `icudtl.dat` | `icudtl.dat` | `icudtl.dat` |
| `locales/` | `locales/` | a `*.lproj` locale |
| a V8 snapshot | a V8 snapshot | a V8 snapshot |

A bundle on disk has passed this check.

### Resolution errors

| Error | Meaning | Fix |
|---|---|---|
| `NotInstalled` | the CEF version isn't installed and `CEF_PATH` isn't set | `kurogane install` |
| `CefPathMissing` | `CEF_PATH` names no directory | correct it |
| `InvalidRuntime` | the runtime `CEF_PATH` names is incomplete | point it at a distribution `export-cef-dir` wrote or unset it |
| `MissingNotice` | it has no `LICENSE.txt` or `CREDITS.html` | as above |
| `Unverified` | it fails verification: `NoArchiveJson`, `UnknownArchive`, `VersionMismatch` or `PlatformMismatch` | as above |
| `NoInstallDir` | the user has no local data directory | run as a user with a home directory |
| `UnsupportedHost` | CEF publishes no build for this host | bundle on a supported platform |
