Docs/Platforms/Linux.md
简体中文 →View on GitHub ↗

Linux

Bern compiles the Linux target (platform = "linux") to a native GTK 4 + libadwaita Rust binary linking the engine in-process, targeting distributions with GTK 4.14+ and libadwaita 1.5+ (such as Ubuntu 24.04+, Fedora 40+, Arch, and SteamOS). Linux targets must be built on Linux.

Prerequisites

  • Rust 1.99+ (rustup update).
  • pkg-config, GTK 4.14+, libadwaita 1.5+, and GStreamer (for media playback):
bash
# Debian / Ubuntu 24.04+
sudo apt install pkg-config libgtk-4-dev libadwaita-1-dev gstreamer1.0-libav

# Fedora 40+
sudo dnf install pkgconf-pkg-config gtk4-devel libadwaita-devel

If your target sets webview = true, also install the WebKitGTK 6 development package (e.g., libwebkitgtk-6.0-dev on Ubuntu/Debian or webkitgtk6.0-devel on Fedora).

Verify your toolchain with:

bash
bern doctor

Configuration in Bern.toml

toml
[app]
id = "tasks"
bundle_id = "com.example.tasks"
version = "0.1.0"
name = "Tasks"
publisher = "Example Inc"   # Used in .deb Maintainer metadata

[app.icon]
default = "assets/icon.png"
linux = "assets/icons/hicolor"   # Optional: square PNG or hicolor icon theme directory

[targets.linux]
platform = "linux"
ui = "gtk"

Build, run, and debug

bash
# Build the native binary, .desktop entry, app CLI, and Skill
bern build --target linux

# Build and start the app
bern run --target linux

Build outputs under target/bern/linux/<Product>/:

  • <app> — native GTK 4 application binary.
  • resources/ — bundled assets, translations, and optional __bern_web_ui/.
  • <bundle_id>.desktop — freedesktop launcher entry.
  • bin/<app> — generated app CLI.
  • skills/<app>/SKILL.md — generated agent Skill.

Drive the running app via its CLI:

bash
target/bern/linux/Tasks/bin/tasks --help
target/bern/linux/Tasks/bin/tasks window screenshot --output linux.png

Useful debugging environment variables:

Variable Effect
BERN_APPEARANCE=light|dark Overrides system light/dark color scheme.
BERN_MOTION=reduce Disables spring animations and forces reduced motion.
BERN_MOTION_LOG=1 Prints element motion transforms to stderr.
BERN_TRACE=<rules> Enables performance tracing (or pass --trace to bern run).
BERN_SNAPSHOT_DIR=<dir> Saves automatic window snapshots to <dir>.

Platform behavior and adaptations

  • Header bars & sidebar: Because libadwaita's sidebar header bar already displays the application title (and KDE's button layout shows the app icon), SidebarHeader(role: title) is omitted automatically on Linux.
  • System tray & autostart: StatusItem registers a StatusNotifierItem with dbusmenu (works on GNOME with AppIndicator, KDE Plasma, and wlroots/Wayland status bars) and keeps the process running after all windows close. Switch(login_item: true) manages an XDG autostart .desktop entry.
  • Custom media core: Video exposes a FrameSink and GTK frame clock when the engine installs a custom MediaKernel.
  • WebPage and Ubuntu 24.04+ AppArmor: When webview = true is enabled, WebPage uses WebKitGTK 6. On Ubuntu 24.04+, AppArmor restricts unprivileged user namespaces for binaries outside an installed AppArmor profile. The .deb package generated by bern package installs the required AppArmor profile automatically; when running an unpacked .tar.gz or local dev build on Ubuntu 24.04+, either install that profile or set WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1 for local testing only.
  • File associations & icons: [[app.opens]] writes MimeType= entries into the .desktop file. [app.icon].linux accepts a PNG or an entire hicolor theme directory.
  • Native views: Co-located GTK 4 widgets mount via NativeView(linux: "..."). See Native views.

Packaging and signing

bash
bern package --target linux

bern package --target linux builds a release binary and creates two archives in target/bern/dist/:

  • <app>_<version>_<arch>.deb — Debian/Ubuntu package installing into /opt/<bundle_id>, symlinking the CLI/binary to /usr/bin/<app>, installing .desktop, hicolor icons, and (when webview = true) the WebKitGTK AppArmor profile.
  • <app>-<version>-linux-<arch>.tar.gz — portable tarball with the app binary, resources, .desktop, CLI, and Skill.
Linux · Bern Docs