From aed30502bd69ac6c030222ecb32a1f6c0425a594 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 14:00:36 -0500 Subject: [PATCH 01/81] Added snap packaging --- snap/snapcraft.yaml | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 000000000..59c7edc99 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,77 @@ +name: ghostty +base: core24 +version: git +summary: A terminal emulator +description: | + Ghostty is a fast, feature-rich, and cross-platform terminal emulator that + uses platform-native UI and GPU acceleration. +grade: stable +confinement: classic +contact: https://github.com/ghostty-org/ghostty/discussions +issues: https://github.com/ghostty-org/ghostty/issues +website: https://ghostty.org +license: MIT +icon: images/icons/icon_512.png + +platforms: + amd64: + arm64: + +apps: + ghostty: + command: bin/ghostty + command-chain: [ bin/launcher ] + desktop: share/applications/com.mitchellh.ghostty.desktop + environment: + PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH + LC_ALL: C.UTF-8 + +parts: + launcher: + plugin: dump + source: snap/local/ + organize: + launcher: bin/ + + zig: + plugin: nil + build-packages: + - curl + override-pull: | + set -ex + case "$CRAFT_TARGET_ARCH" in + amd64) arch=x86_64 ;; + arm64) arch=aarch64 ;; + *) arch="" ;; + esac + + rm -rf $CRAFT_PART_SRC/* + + if [[ -n $arch ]]; then + curl -LO --retry-connrefused --retry 10 https://ziglang.org/download/0.13.0/zig-linux-$arch-0.13.0.tar.xz + fi + + tar xf zig-lin*xz + rm -f *xz + mv zig-linux*/* . + prime: + - -* + + ghostty: + source: . + after: [ zig ] + plugin: nil + build-packages: + - libgtk-4-dev + - libadwaita-1-dev + - git + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 + - bash + - zsh + - fish + override-build: | + $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast + cp -rp zig-out/* $CRAFT_PART_INSTALL/ + sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From a7d1029e5c35eccaca5613d52958f691693f9e94 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 15:57:33 -0500 Subject: [PATCH 02/81] Added snap build workflow --- .github/workflows/snap.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/snap.yaml diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml new file mode 100644 index 000000000..5aa4c382d --- /dev/null +++ b/.github/workflows/snap.yaml @@ -0,0 +1,14 @@ +name: Snap + +on: + push: {} + pull_request: {} + workflow_dispatch: {} + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: snapcore/action-build@v1 + id: snapcraft From 97b104cf9d747ba575f7e023216afd7c69be42b3 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:05:52 -0500 Subject: [PATCH 03/81] Set source-type for launcher dir --- snap/local/launcher | 6 ++++++ snap/snapcraft.yaml | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100755 snap/local/launcher diff --git a/snap/local/launcher b/snap/local/launcher new file mode 100755 index 000000000..29c0f5c8f --- /dev/null +++ b/snap/local/launcher @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" +export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" + +exec "$@" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 59c7edc99..15601c240 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,7 +29,8 @@ apps: parts: launcher: plugin: dump - source: snap/local/ + source: snap/local + source-type: local organize: launcher: bin/ From f51789b17a8bc89c371d610d9a960cd8d3412210 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:15:34 -0500 Subject: [PATCH 04/81] Exit with error if building for unsupported arch --- snap/snapcraft.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 15601c240..846863fc5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -50,6 +50,9 @@ parts: if [[ -n $arch ]]; then curl -LO --retry-connrefused --retry 10 https://ziglang.org/download/0.13.0/zig-linux-$arch-0.13.0.tar.xz + else + echo "Unsupported arch" + exit 1 fi tar xf zig-lin*xz From 30fa18390fa1f88042fb07c34d9acb6f045014cd Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:45:23 -0500 Subject: [PATCH 05/81] Install bash-completion --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 846863fc5..e997dca47 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -21,6 +21,7 @@ apps: ghostty: command: bin/ghostty command-chain: [ bin/launcher ] + completer: share/bash-completion/completions/ghostty.bash desktop: share/applications/com.mitchellh.ghostty.desktop environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH From eb0816c2c4449b6d6ad7862970ef994289af2797 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:11:37 -0500 Subject: [PATCH 06/81] Set GHOSTTY_RESOURCES_DIR --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e997dca47..95fb671ac 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -26,6 +26,7 @@ apps: environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 + GHOSTTY_RESOURCES_DIR: /snap/ghostty/current/share/ghostty parts: launcher: From b6a3b98828136487c995d24c012c46683b4a180b Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:22:26 -0500 Subject: [PATCH 07/81] enable-patchelf is more repliable for classic snaps --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 95fb671ac..a1311e3dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,6 +67,7 @@ parts: source: . after: [ zig ] plugin: nil + build-attributes: [ enable-patchelf ] build-packages: - libgtk-4-dev - libadwaita-1-dev From bf49784b7d296a800af9b0af1a7755987d2fa284 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:03:19 -0500 Subject: [PATCH 08/81] Don't stage shells --- snap/snapcraft.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a1311e3dc..a3edeb327 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -75,9 +75,6 @@ parts: stage-packages: - libadwaita-1-0 - libgtk-4-1 - - bash - - zsh - - fish override-build: | $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ From eae420a2410b16ff1141d7bf6acfc54d4aeab6b2 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:06:57 -0500 Subject: [PATCH 09/81] Only run snap workflow on push and PR --- .github/workflows/snap.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 5aa4c382d..66e3a5254 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -1,8 +1,10 @@ name: Snap on: - push: {} - pull_request: {} + push: + branches: [main] + pull_request: + branches: [main] workflow_dispatch: {} jobs: @@ -11,4 +13,3 @@ jobs: steps: - uses: actions/checkout@v4 - uses: snapcore/action-build@v1 - id: snapcraft From 53f1b4bc1577c44a8987b12237c4db3239528277 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:19:42 -0500 Subject: [PATCH 10/81] Changed shebang in launcher script --- snap/local/launcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/local/launcher b/snap/local/launcher index 29c0f5c8f..36e87fd0c 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" From 2e0e8af1ada3300d7fdb298775f139e9b23d12a0 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 15:28:25 -0500 Subject: [PATCH 11/81] Set a more meaningful version for the snap --- snap/snapcraft.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a3edeb327..e3b61537a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,5 @@ name: ghostty base: core24 -version: git summary: A terminal emulator description: | Ghostty is a fast, feature-rich, and cross-platform terminal emulator that @@ -12,6 +11,7 @@ issues: https://github.com/ghostty-org/ghostty/issues website: https://ghostty.org license: MIT icon: images/icons/icon_512.png +adopt-info: ghostty platforms: amd64: @@ -76,6 +76,7 @@ parts: - libadwaita-1-0 - libgtk-4-1 override-build: | + craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From f1f23e1c7d8632de2f4194e7c0cbcb82ef7e1f1f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 Jan 2025 10:22:17 -0800 Subject: [PATCH 12/81] Add snap to nix, add arm64 builders --- .github/workflows/snap.yaml | 26 ++++++++++++++++++++++---- nix/devShell.nix | 2 ++ snap/snapcraft.yaml | 8 ++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 66e3a5254..05f509f13 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -8,8 +8,26 @@ on: workflow_dispatch: {} jobs: - build: - runs-on: ubuntu-24.04 + build-amd64: + runs-on: namespace-profile-ghostty-snap steps: - - uses: actions/checkout@v4 - - uses: snapcore/action-build@v1 + - uses: actions/checkout@v4 + - name: Setup Cache + uses: namespacelabs/nscloud-cache-action@v1.2.0 + with: + path: | + /nix + /zig + - uses: snapcore/action-build@v1 + + build-arm64: + runs-on: namespace-profile-ghostty-snap-arm64 + steps: + - uses: actions/checkout@v4 + - name: Setup Cache + uses: namespacelabs/nscloud-cache-action@v1.2.0 + with: + path: | + /nix + /zig + - uses: snapcore/action-build@v1 diff --git a/nix/devShell.nix b/nix/devShell.nix index 7cfef64c2..6470423a0 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -14,6 +14,7 @@ python3, qemu, scdoc, + snapcraft, valgrind, #, vulkan-loader # unused vttest, @@ -105,6 +106,7 @@ in pandoc pkg-config scdoc + snapcraft zig zip zig2nix.packages.${system}.zon2nix diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e3b61537a..d190e345d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -20,9 +20,9 @@ platforms: apps: ghostty: command: bin/ghostty - command-chain: [ bin/launcher ] + command-chain: [bin/launcher] completer: share/bash-completion/completions/ghostty.bash - desktop: share/applications/com.mitchellh.ghostty.desktop + desktop: share/applications/com.mitchellh.ghostty.desktop environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 @@ -65,9 +65,9 @@ parts: ghostty: source: . - after: [ zig ] + after: [zig] plugin: nil - build-attributes: [ enable-patchelf ] + build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev From ec8e7d9d869ea6f5c26cd55ae802d0f0c5dea5ee Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 10:16:54 -0500 Subject: [PATCH 13/81] Ensure LD_LIBRARY_PATH is set appropriately --- snap/local/launcher | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/snap/local/launcher b/snap/local/launcher index 36e87fd0c..3a70a0de0 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -2,5 +2,16 @@ export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +export HOME="$SNAP_REAL_HOME" + +if [ "$SNAP_ARCH" = "amd64" ]; then + ARCH="x86_64-linux-gnu" +elif [ "$SNAP_ARCH" = "arm64" ]; then + ARCH="aarch64-linux-gnu" +else + ARCH="$SNAP_ARCH-linux-gnu" +fi + +export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} exec "$@" From aa4d9809c363089363c52cccba1fc9114603c631 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 10:23:25 -0500 Subject: [PATCH 14/81] CRAFT_TARGET_ARCH is deprecated, use CRAFT_ARCH_BUILD_FOR --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d190e345d..d013f5bd5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -42,7 +42,7 @@ parts: - curl override-pull: | set -ex - case "$CRAFT_TARGET_ARCH" in + case "$CRAFT_ARCH_BUILD_FOR" in amd64) arch=x86_64 ;; arm64) arch=aarch64 ;; *) arch="" ;; From 6d8b3973e499b3fde515e450f10e45bc1bc3e465 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 14:26:29 -0500 Subject: [PATCH 15/81] EGL fixes, ensure necessary env variables are set to isolate dependencies from the host --- snap/local/launcher | 61 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 3a70a0de0..c65935127 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +set -euo pipefail export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" @@ -12,6 +13,62 @@ else ARCH="$SNAP_ARCH-linux-gnu" fi -export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} +# VDPAU_DRIVER_PATH only supports a single path, rely on LD_LIBRARY_PATH instead +LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau +LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ + +__EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d +__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d +DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d +VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ +XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share +XLOCALEDIR="${SNAP}/usr/share/X11/locale" + +# These are in the default LD_LIBRARY_PATH, but in case the snap dropped it inadvertently +if [ -d "/var/lib/snapd/lib/gl" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl(:|$) ]]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl +fi + +if [ -d "/var/lib/snapd/lib/gl32" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl32(:|$) ]]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32 +fi + +if [ -d "/var/lib/snapd/lib/glvnd/egl_vendor.d" ]; then + # This needs to be prepended, as glvnd goes depth-first on these + # TODO maybe collect the JSONs into a separate location so their ordering matters, + # and not the dir order + __EGL_VENDOR_LIBRARY_DIRS=/var/lib/snapd/lib/glvnd/egl_vendor.d:${__EGL_VENDOR_LIBRARY_DIRS} +fi + +if [ -d "/var/lib/snapd/lib/vulkan/icd.d" ]; then + XDG_DATA_DIRS=${XDG_DATA_DIRS}:/var/lib/snapd/lib +fi + +if [ -d "/var/lib/snapd/lib/gl/vdpau" ]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl/vdpau +fi + +if [ -d "/var/lib/snapd/lib/gl32/vdpau" ]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32/vdpau +fi + +if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then + export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm +fi + +export LD_LIBRARY_PATH +export LIBGL_DRIVERS_PATH +if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then + # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU + # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications + export LIBVA_DRIVERS_PATH +fi +export __EGL_VENDOR_LIBRARY_DIRS +export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS +export DRIRC_CONFIGDIR +export VK_LAYER_PATH +export XDG_DATA_DIRS +export XLOCALEDIR exec "$@" From 3a9d61d6e464471c3f511a75c8da4c33f9af2352 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 14:26:59 -0500 Subject: [PATCH 16/81] Stage more depends to ensure we aren't getting leaks from the host --- snap/snapcraft.yaml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d013f5bd5..a666c73dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,11 +72,31 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git - stage-packages: - - libadwaita-1-0 - - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop + + libs: + plugin: nil + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 + - libgtk-4-media-gstreamer + - ibus-gtk4 + - libegl1 + - libegl-mesa0 + - libgl1-mesa-dri + - libglapi-mesa + - libglu1-mesa + - libglx-mesa0 + - mesa-va-drivers + - mesa-vulkan-drivers + - libpciaccess0 + - libtinfo6 + - libedit2 + - libelf1t64 + - libsensors5 + - libllvm17 + - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] From 2b6b7c19d284f2c4e7e1d9fb5a9b230ba2e425c0 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:03:53 -0500 Subject: [PATCH 17/81] Enable patch-elf for libs part --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a666c73dc..1640c01d4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -80,6 +80,7 @@ parts: libs: plugin: nil + build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 From f3829072f34efdd356a2d30d9075e742d1700838 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:29:52 -0500 Subject: [PATCH 18/81] Drop patchelf --- snap/snapcraft.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1640c01d4..eaccb78bf 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,7 +67,6 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev @@ -80,7 +79,6 @@ parts: libs: plugin: nil - build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 From 0272ad9edb005e830a47f0f6fa3003957eead171 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:43:45 -0500 Subject: [PATCH 19/81] Stage gnome-text-editor to open configuration, this makes it more reliable across more distros as a classic snap. --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index eaccb78bf..bb1d46557 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -98,4 +98,5 @@ parts: - libelf1t64 - libsensors5 - libllvm17 + - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] From 9d62c31f44d51e20c64343cd6f2fe1e454193d4a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 10 Jan 2025 08:57:01 -0500 Subject: [PATCH 20/81] no-patchelf for DRI and tidy up the mesa bits --- snap/snapcraft.yaml | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index bb1d46557..597ff3713 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -79,24 +79,44 @@ parts: libs: plugin: nil + build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 - libgtk-4-media-gstreamer - ibus-gtk4 - - libegl1 - - libegl-mesa0 - - libgl1-mesa-dri - - libglapi-mesa - - libglu1-mesa - - libglx-mesa0 - - mesa-va-drivers - - mesa-vulkan-drivers - libpciaccess0 - libtinfo6 - libedit2 - libelf1t64 - libsensors5 - libllvm17 + - libunistring5 - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] + stage: + # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - -usr/lib/*/dri + + mesa: + plugin: nil + build-attributes: [enable-patchelf] + stage-packages: + - libglu1-mesa + - libgl1-mesa-dri + - libegl-mesa0 + - libegl1 + - libglx-mesa0 + stage: + # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - -usr/lib/*/dri + + mesa-gl1-dri: + plugin: nil + stage-packages: + - libgl1-mesa-dri + build-attributes: [no-patchelf] + stage: + # Only the libraries in dri need to not be patched, the rest come from the mesa part + # Otherwise snapcraft may strip the build ID and cause the driver to crash + - usr/lib/*/dri From 1dcea3b11f957837be4c261ce832435024ee1fa5 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:15:34 -0500 Subject: [PATCH 21/81] Exit with error if building for unsupported arch From e09d8455a10834e35c244117fea555315ec4cd96 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:11:37 -0500 Subject: [PATCH 22/81] Set GHOSTTY_RESOURCES_DIR From 78446008c473cee7edf111f047676eab0a88c70a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:22:26 -0500 Subject: [PATCH 23/81] enable-patchelf is more repliable for classic snaps --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 597ff3713..33d1f7864 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,6 +67,7 @@ parts: source: . after: [zig] plugin: nil + build-attributes: [ enable-patchelf ] build-packages: - libgtk-4-dev - libadwaita-1-dev From 9c81cd323dd9506622ce509780878e177c5227c3 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:03:19 -0500 Subject: [PATCH 24/81] Don't stage shells --- snap/snapcraft.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 33d1f7864..00209f4c0 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,6 +72,9 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast From 5e77a973b211630101ec3cefc38733f3ad2e3c0d Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 12 Jan 2025 16:23:21 -0500 Subject: [PATCH 25/81] Removed duplicated stage-packages --- snap/snapcraft.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 00209f4c0..33d1f7864 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,9 +72,6 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git - stage-packages: - - libadwaita-1-0 - - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast From 55c5b8b72f948e069f7388f2ec30fbe7e05ff64d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 Jan 2025 11:03:40 -0800 Subject: [PATCH 26/81] ci: temporary apt installs required for namespace --- .github/workflows/snap.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 05f509f13..c5b7f5208 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -18,6 +18,8 @@ jobs: path: | /nix /zig + - run: sudo apt install -y udev + - run: sudo systemctl start systemd-udevd - uses: snapcore/action-build@v1 build-arm64: @@ -30,4 +32,6 @@ jobs: path: | /nix /zig + - run: sudo apt install -y udev + - run: sudo systemctl start systemd-udevd - uses: snapcore/action-build@v1 From 1a5b69181f51989652a24396547bbbe39531f724 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 21 Jan 2025 08:48:48 +0200 Subject: [PATCH 27/81] Use patch-rpath which improves our cross distro support --- snap/snapcraft.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 33d1f7864..c616e67c5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,14 +67,15 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [ enable-patchelf ] + build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev - git + - patchelf override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) - $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast + $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=/snap/ghostty/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From 3e669fc4bb6de8d564fc6d9814122edcf1915d91 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 21 Jan 2025 08:49:37 +0200 Subject: [PATCH 28/81] Improved environment handling to ensure the snap will work across distros and unset all SNAP environment variables that could leak at runtime --- snap/local/launcher | 69 +++++++++++---------------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index c65935127..7a77d8afc 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,5 +1,5 @@ -#!/bin/bash -set -euo pipefail +#!/bin/sh +set -e export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" @@ -13,62 +13,27 @@ else ARCH="$SNAP_ARCH-linux-gnu" fi -# VDPAU_DRIVER_PATH only supports a single path, rely on LD_LIBRARY_PATH instead -LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau -LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ -LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau +export LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export __EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d +export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d +export DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d +export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ +export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share +export XLOCALEDIR="${SNAP}/usr/share/X11/locale" -__EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d -__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d -DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d -VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ -XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share -XLOCALEDIR="${SNAP}/usr/share/X11/locale" - -# These are in the default LD_LIBRARY_PATH, but in case the snap dropped it inadvertently -if [ -d "/var/lib/snapd/lib/gl" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl(:|$) ]]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl -fi - -if [ -d "/var/lib/snapd/lib/gl32" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl32(:|$) ]]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32 -fi - -if [ -d "/var/lib/snapd/lib/glvnd/egl_vendor.d" ]; then - # This needs to be prepended, as glvnd goes depth-first on these - # TODO maybe collect the JSONs into a separate location so their ordering matters, - # and not the dir order - __EGL_VENDOR_LIBRARY_DIRS=/var/lib/snapd/lib/glvnd/egl_vendor.d:${__EGL_VENDOR_LIBRARY_DIRS} -fi - -if [ -d "/var/lib/snapd/lib/vulkan/icd.d" ]; then - XDG_DATA_DIRS=${XDG_DATA_DIRS}:/var/lib/snapd/lib -fi - -if [ -d "/var/lib/snapd/lib/gl/vdpau" ]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl/vdpau -fi - -if [ -d "/var/lib/snapd/lib/gl32/vdpau" ]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32/vdpau -fi - -if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then - export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm -fi - -export LD_LIBRARY_PATH export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications export LIBVA_DRIVERS_PATH fi -export __EGL_VENDOR_LIBRARY_DIRS -export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS -export DRIRC_CONFIGDIR -export VK_LAYER_PATH -export XDG_DATA_DIRS -export XLOCALEDIR + +# Unset all SNAP specific environment variables to keep them from leaking +# into other snaps that might get executed from within the shell +for var in $(printenv | grep SNAP | cut -d= -f1); do + unset $var +done exec "$@" From d2f82b2e4013f7684c59fcfdaf15f1d5b4d90028 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 22 Jan 2025 07:25:01 +0200 Subject: [PATCH 29/81] Stage libglib2.0-0t64 to insure we don't mix in the host's lib --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index c616e67c5..2b4f4a825 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -84,6 +84,7 @@ parts: build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 + - libglib2.0-0t64 - libgtk-4-1 - libgtk-4-media-gstreamer - ibus-gtk4 From cee189de11e5b9ecb34f309de6ff5148d0879702 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 22 Jan 2025 07:38:41 +0200 Subject: [PATCH 30/81] Only export XDG_CONFIG_HOME and XDG_DATA_HOME if they aren't already set --- snap/local/launcher | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 7a77d8afc..6b5b69fa6 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,8 +1,15 @@ #!/bin/sh set -e -export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" -export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +# Set these to reasonable defaults if not already set +if [ -z "$XDG_CONFIG_HOME" ]; then + export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" +fi + +if [ -z "$XDG_DATA_HOME" ]; then + export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +fi + export HOME="$SNAP_REAL_HOME" if [ "$SNAP_ARCH" = "amd64" ]; then From c036eb2444bbbcab47dfafc0c1293a2b684a7bd0 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 24 Jan 2025 13:57:14 +0200 Subject: [PATCH 31/81] Unset environment varies set by the snap --- src/termio/Exec.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 864f2e21c..a728e7a37 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -732,6 +732,19 @@ const Subprocess = struct { try env.put("GHOSTTY_RESOURCES_DIR", dir); } + // Unset environment varies set by the snap + if (env.get("SNAP") != null) { + env.remove("SNAP"); + env.remove("DRIRC_CONFIGDIR"); + env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); + env.remove("__EGL_VENDOR_LIBRARY_DIRS"); + env.remove("LD_LIBRARY_PATH"); + env.remove("LIBGL_DRIVERS_PATH"); + env.remove("LIBVA_DRIVERS_PATH"); + env.remove("VK_LAYER_PATH"); + env.remove("XLOCALEDIR"); + } + // Set our TERM var. This is a bit complicated because we want to use // the ghostty TERM value but we want to only do that if we have // ghostty in the TERMINFO database. From f239df59caca2034eb98b3f90f6878e6384d1d0c Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 24 Jan 2025 13:57:30 +0200 Subject: [PATCH 32/81] Clean up environment variable while launching the shell --- snap/local/launcher | 3 +-- snap/snapcraft.yaml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 6b5b69fa6..c0f204060 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -30,7 +30,6 @@ export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/i export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share export XLOCALEDIR="${SNAP}/usr/share/X11/locale" -export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications @@ -39,7 +38,7 @@ fi # Unset all SNAP specific environment variables to keep them from leaking # into other snaps that might get executed from within the shell -for var in $(printenv | grep SNAP | cut -d= -f1); do +for var in $(printenv | grep SNAP_ | cut -d= -f1); do unset $var done diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 2b4f4a825..a27f35e45 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -95,7 +95,6 @@ parts: - libsensors5 - libllvm17 - libunistring5 - - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part From a111b3f96fc7b2151f001b835e50588aeaca107b Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sat, 25 Jan 2025 07:44:32 -0500 Subject: [PATCH 33/81] Per PR review feedback, this is the more "ziggy" way of doing the check for environment variable. --- src/termio/Exec.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index a728e7a37..8dfeb1aeb 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -733,7 +733,7 @@ const Subprocess = struct { } // Unset environment varies set by the snap - if (env.get("SNAP") != null) { + if (env.get("SNAP")) |_| { env.remove("SNAP"); env.remove("DRIRC_CONFIGDIR"); env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); From b0edda4b696d15e5fae1e5422d4b1f07402e266a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 7 Feb 2025 14:39:48 -0500 Subject: [PATCH 34/81] Updated stage packages --- snap/snapcraft.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a27f35e45..732700272 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,7 +67,7 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [enable-patchelf] + build-attributes: [no-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev @@ -95,6 +95,7 @@ parts: - libsensors5 - libllvm17 - libunistring5 + - librsvg2-2 - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part @@ -109,8 +110,12 @@ parts: - libegl-mesa0 - libegl1 - libglx-mesa0 + - mesa-libgallium stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - usr/lib/*/*.so* + - usr/lib/*/dri/libdril_dri.so + - -usr/lib/*/libgallium*so - -usr/lib/*/dri mesa-gl1-dri: @@ -121,4 +126,6 @@ parts: stage: # Only the libraries in dri need to not be patched, the rest come from the mesa part # Otherwise snapcraft may strip the build ID and cause the driver to crash + - usr/lib/*/libgallium*so + - -usr/lib/*/dri/libdril_dri.so - usr/lib/*/dri From 90ce5b75f1a7145bd4715a629b6fed6575cc7f06 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 13 Feb 2025 21:42:49 -0500 Subject: [PATCH 35/81] Simplified setting snap version --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 732700272..37020a2d6 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -74,7 +74,7 @@ parts: - git - patchelf override-build: | - craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) + craftctl set version=$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=/snap/ghostty/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From 4e8e2d97965347f9afd3d179d81bce0aa02e6972 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Feb 2025 14:52:29 -0800 Subject: [PATCH 36/81] nix: snapcraft should only be installed on Linux --- nix/devShell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/devShell.nix b/nix/devShell.nix index 6470423a0..66f259656 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -106,7 +106,6 @@ in pandoc pkg-config scdoc - snapcraft zig zip zig2nix.packages.${system}.zon2nix @@ -139,6 +138,7 @@ in qemu gdb + snapcraft valgrind wraptest From 8c4b0f815d0b988c8a41a6fd9cc1cf92d342b20f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Feb 2025 14:54:53 -0800 Subject: [PATCH 37/81] prettier --- snap/snapcraft.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 37020a2d6..847327d4c 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -96,7 +96,14 @@ parts: - libllvm17 - libunistring5 - librsvg2-2 - - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] + - on amd64: + [ + i965-va-driver, + libdrm-intel1, + libdrm-nouveau2, + libdrm-amdgpu1, + libdrm-radeon1, + ] stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part - -usr/lib/*/dri From f0842c559998c1f39235e0d89bd758e4bf285b23 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 14:00:36 -0500 Subject: [PATCH 38/81] Added snap packaging --- snap/snapcraft.yaml | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 000000000..59c7edc99 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,77 @@ +name: ghostty +base: core24 +version: git +summary: A terminal emulator +description: | + Ghostty is a fast, feature-rich, and cross-platform terminal emulator that + uses platform-native UI and GPU acceleration. +grade: stable +confinement: classic +contact: https://github.com/ghostty-org/ghostty/discussions +issues: https://github.com/ghostty-org/ghostty/issues +website: https://ghostty.org +license: MIT +icon: images/icons/icon_512.png + +platforms: + amd64: + arm64: + +apps: + ghostty: + command: bin/ghostty + command-chain: [ bin/launcher ] + desktop: share/applications/com.mitchellh.ghostty.desktop + environment: + PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH + LC_ALL: C.UTF-8 + +parts: + launcher: + plugin: dump + source: snap/local/ + organize: + launcher: bin/ + + zig: + plugin: nil + build-packages: + - curl + override-pull: | + set -ex + case "$CRAFT_TARGET_ARCH" in + amd64) arch=x86_64 ;; + arm64) arch=aarch64 ;; + *) arch="" ;; + esac + + rm -rf $CRAFT_PART_SRC/* + + if [[ -n $arch ]]; then + curl -LO --retry-connrefused --retry 10 https://ziglang.org/download/0.13.0/zig-linux-$arch-0.13.0.tar.xz + fi + + tar xf zig-lin*xz + rm -f *xz + mv zig-linux*/* . + prime: + - -* + + ghostty: + source: . + after: [ zig ] + plugin: nil + build-packages: + - libgtk-4-dev + - libadwaita-1-dev + - git + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 + - bash + - zsh + - fish + override-build: | + $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast + cp -rp zig-out/* $CRAFT_PART_INSTALL/ + sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From 818c81282bb88cd860d17b042279ac90ab91ce9a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 15:57:33 -0500 Subject: [PATCH 39/81] Added snap build workflow --- .github/workflows/snap.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/snap.yaml diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml new file mode 100644 index 000000000..5aa4c382d --- /dev/null +++ b/.github/workflows/snap.yaml @@ -0,0 +1,14 @@ +name: Snap + +on: + push: {} + pull_request: {} + workflow_dispatch: {} + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: snapcore/action-build@v1 + id: snapcraft From 2b2b3c5b3bc90dcd4e1008fe15499be159b3645f Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:05:52 -0500 Subject: [PATCH 40/81] Set source-type for launcher dir --- snap/local/launcher | 6 ++++++ snap/snapcraft.yaml | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100755 snap/local/launcher diff --git a/snap/local/launcher b/snap/local/launcher new file mode 100755 index 000000000..29c0f5c8f --- /dev/null +++ b/snap/local/launcher @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" +export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" + +exec "$@" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 59c7edc99..15601c240 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,7 +29,8 @@ apps: parts: launcher: plugin: dump - source: snap/local/ + source: snap/local + source-type: local organize: launcher: bin/ From b7bd8444c7636438404057ee7ec95d920315ae83 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:15:34 -0500 Subject: [PATCH 41/81] Exit with error if building for unsupported arch --- snap/snapcraft.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 15601c240..846863fc5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -50,6 +50,9 @@ parts: if [[ -n $arch ]]; then curl -LO --retry-connrefused --retry 10 https://ziglang.org/download/0.13.0/zig-linux-$arch-0.13.0.tar.xz + else + echo "Unsupported arch" + exit 1 fi tar xf zig-lin*xz From fcde494440a29c9f2882f2701d5445f89761b1d2 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:45:23 -0500 Subject: [PATCH 42/81] Install bash-completion --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 846863fc5..e997dca47 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -21,6 +21,7 @@ apps: ghostty: command: bin/ghostty command-chain: [ bin/launcher ] + completer: share/bash-completion/completions/ghostty.bash desktop: share/applications/com.mitchellh.ghostty.desktop environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH From 71297870cfd72cb5011e2be3bda61803373117cd Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:11:37 -0500 Subject: [PATCH 43/81] Set GHOSTTY_RESOURCES_DIR --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e997dca47..95fb671ac 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -26,6 +26,7 @@ apps: environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 + GHOSTTY_RESOURCES_DIR: /snap/ghostty/current/share/ghostty parts: launcher: From d0108416d04ffc1f035db52940355c8e8ab9945e Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:22:26 -0500 Subject: [PATCH 44/81] enable-patchelf is more repliable for classic snaps --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 95fb671ac..a1311e3dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,6 +67,7 @@ parts: source: . after: [ zig ] plugin: nil + build-attributes: [ enable-patchelf ] build-packages: - libgtk-4-dev - libadwaita-1-dev From 5d0dde57f94bc37bed18ccd50c3a5c39ffa2f981 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:03:19 -0500 Subject: [PATCH 45/81] Don't stage shells --- snap/snapcraft.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a1311e3dc..a3edeb327 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -75,9 +75,6 @@ parts: stage-packages: - libadwaita-1-0 - libgtk-4-1 - - bash - - zsh - - fish override-build: | $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ From e6c9dc7040873abe629d8fb98bd0510852ab31bb Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:06:57 -0500 Subject: [PATCH 46/81] Only run snap workflow on push and PR --- .github/workflows/snap.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 5aa4c382d..66e3a5254 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -1,8 +1,10 @@ name: Snap on: - push: {} - pull_request: {} + push: + branches: [main] + pull_request: + branches: [main] workflow_dispatch: {} jobs: @@ -11,4 +13,3 @@ jobs: steps: - uses: actions/checkout@v4 - uses: snapcore/action-build@v1 - id: snapcraft From d06d6796c5e93afdb191d744305bb61ac1c0f45a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:19:42 -0500 Subject: [PATCH 47/81] Changed shebang in launcher script --- snap/local/launcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/local/launcher b/snap/local/launcher index 29c0f5c8f..36e87fd0c 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" From c35ca1e87f09986b549a470b6d4d220441178c0c Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 15:28:25 -0500 Subject: [PATCH 48/81] Set a more meaningful version for the snap --- snap/snapcraft.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a3edeb327..e3b61537a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,5 @@ name: ghostty base: core24 -version: git summary: A terminal emulator description: | Ghostty is a fast, feature-rich, and cross-platform terminal emulator that @@ -12,6 +11,7 @@ issues: https://github.com/ghostty-org/ghostty/issues website: https://ghostty.org license: MIT icon: images/icons/icon_512.png +adopt-info: ghostty platforms: amd64: @@ -76,6 +76,7 @@ parts: - libadwaita-1-0 - libgtk-4-1 override-build: | + craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From c7635201ab49035a53f55a364b292d558aab6360 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 Jan 2025 10:22:17 -0800 Subject: [PATCH 49/81] Add snap to nix, add arm64 builders --- .github/workflows/snap.yaml | 26 ++++++++++++++++++++++---- nix/devShell.nix | 2 ++ snap/snapcraft.yaml | 8 ++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 66e3a5254..05f509f13 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -8,8 +8,26 @@ on: workflow_dispatch: {} jobs: - build: - runs-on: ubuntu-24.04 + build-amd64: + runs-on: namespace-profile-ghostty-snap steps: - - uses: actions/checkout@v4 - - uses: snapcore/action-build@v1 + - uses: actions/checkout@v4 + - name: Setup Cache + uses: namespacelabs/nscloud-cache-action@v1.2.0 + with: + path: | + /nix + /zig + - uses: snapcore/action-build@v1 + + build-arm64: + runs-on: namespace-profile-ghostty-snap-arm64 + steps: + - uses: actions/checkout@v4 + - name: Setup Cache + uses: namespacelabs/nscloud-cache-action@v1.2.0 + with: + path: | + /nix + /zig + - uses: snapcore/action-build@v1 diff --git a/nix/devShell.nix b/nix/devShell.nix index 7cfef64c2..6470423a0 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -14,6 +14,7 @@ python3, qemu, scdoc, + snapcraft, valgrind, #, vulkan-loader # unused vttest, @@ -105,6 +106,7 @@ in pandoc pkg-config scdoc + snapcraft zig zip zig2nix.packages.${system}.zon2nix diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e3b61537a..d190e345d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -20,9 +20,9 @@ platforms: apps: ghostty: command: bin/ghostty - command-chain: [ bin/launcher ] + command-chain: [bin/launcher] completer: share/bash-completion/completions/ghostty.bash - desktop: share/applications/com.mitchellh.ghostty.desktop + desktop: share/applications/com.mitchellh.ghostty.desktop environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 @@ -65,9 +65,9 @@ parts: ghostty: source: . - after: [ zig ] + after: [zig] plugin: nil - build-attributes: [ enable-patchelf ] + build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev From ae953b5f10824e60b092cd5c1fbb58a0bcb99841 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 10:16:54 -0500 Subject: [PATCH 50/81] Ensure LD_LIBRARY_PATH is set appropriately --- snap/local/launcher | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/snap/local/launcher b/snap/local/launcher index 36e87fd0c..3a70a0de0 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -2,5 +2,16 @@ export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +export HOME="$SNAP_REAL_HOME" + +if [ "$SNAP_ARCH" = "amd64" ]; then + ARCH="x86_64-linux-gnu" +elif [ "$SNAP_ARCH" = "arm64" ]; then + ARCH="aarch64-linux-gnu" +else + ARCH="$SNAP_ARCH-linux-gnu" +fi + +export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} exec "$@" From 8dffe3450c01a400c96e67f327f69d7a4ef1d894 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 10:23:25 -0500 Subject: [PATCH 51/81] CRAFT_TARGET_ARCH is deprecated, use CRAFT_ARCH_BUILD_FOR --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d190e345d..d013f5bd5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -42,7 +42,7 @@ parts: - curl override-pull: | set -ex - case "$CRAFT_TARGET_ARCH" in + case "$CRAFT_ARCH_BUILD_FOR" in amd64) arch=x86_64 ;; arm64) arch=aarch64 ;; *) arch="" ;; From 43b2e43a119030a835428ef7e092c77f85bcfdcb Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 14:26:29 -0500 Subject: [PATCH 52/81] EGL fixes, ensure necessary env variables are set to isolate dependencies from the host --- snap/local/launcher | 61 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 3a70a0de0..c65935127 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +set -euo pipefail export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" @@ -12,6 +13,62 @@ else ARCH="$SNAP_ARCH-linux-gnu" fi -export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} +# VDPAU_DRIVER_PATH only supports a single path, rely on LD_LIBRARY_PATH instead +LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau +LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ + +__EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d +__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d +DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d +VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ +XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share +XLOCALEDIR="${SNAP}/usr/share/X11/locale" + +# These are in the default LD_LIBRARY_PATH, but in case the snap dropped it inadvertently +if [ -d "/var/lib/snapd/lib/gl" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl(:|$) ]]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl +fi + +if [ -d "/var/lib/snapd/lib/gl32" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl32(:|$) ]]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32 +fi + +if [ -d "/var/lib/snapd/lib/glvnd/egl_vendor.d" ]; then + # This needs to be prepended, as glvnd goes depth-first on these + # TODO maybe collect the JSONs into a separate location so their ordering matters, + # and not the dir order + __EGL_VENDOR_LIBRARY_DIRS=/var/lib/snapd/lib/glvnd/egl_vendor.d:${__EGL_VENDOR_LIBRARY_DIRS} +fi + +if [ -d "/var/lib/snapd/lib/vulkan/icd.d" ]; then + XDG_DATA_DIRS=${XDG_DATA_DIRS}:/var/lib/snapd/lib +fi + +if [ -d "/var/lib/snapd/lib/gl/vdpau" ]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl/vdpau +fi + +if [ -d "/var/lib/snapd/lib/gl32/vdpau" ]; then + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32/vdpau +fi + +if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then + export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm +fi + +export LD_LIBRARY_PATH +export LIBGL_DRIVERS_PATH +if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then + # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU + # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications + export LIBVA_DRIVERS_PATH +fi +export __EGL_VENDOR_LIBRARY_DIRS +export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS +export DRIRC_CONFIGDIR +export VK_LAYER_PATH +export XDG_DATA_DIRS +export XLOCALEDIR exec "$@" From 48f94e6fcc3b0b278b80fd3bacbf8bdffed50dbc Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 14:26:59 -0500 Subject: [PATCH 53/81] Stage more depends to ensure we aren't getting leaks from the host --- snap/snapcraft.yaml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index d013f5bd5..a666c73dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,11 +72,31 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git - stage-packages: - - libadwaita-1-0 - - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop + + libs: + plugin: nil + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 + - libgtk-4-media-gstreamer + - ibus-gtk4 + - libegl1 + - libegl-mesa0 + - libgl1-mesa-dri + - libglapi-mesa + - libglu1-mesa + - libglx-mesa0 + - mesa-va-drivers + - mesa-vulkan-drivers + - libpciaccess0 + - libtinfo6 + - libedit2 + - libelf1t64 + - libsensors5 + - libllvm17 + - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] From c9cafd3051b376ad314cb9ccaa08cc24918f648c Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:03:53 -0500 Subject: [PATCH 54/81] Enable patch-elf for libs part --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a666c73dc..1640c01d4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -80,6 +80,7 @@ parts: libs: plugin: nil + build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 From bdafc2227cfe793cc28b5f73fcf0fc6d97579a58 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:29:52 -0500 Subject: [PATCH 55/81] Drop patchelf --- snap/snapcraft.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1640c01d4..eaccb78bf 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,7 +67,6 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev @@ -80,7 +79,6 @@ parts: libs: plugin: nil - build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 From 403eab2cf0fa69798ea7b9868ec5bb20234e4441 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 9 Jan 2025 15:43:45 -0500 Subject: [PATCH 56/81] Stage gnome-text-editor to open configuration, this makes it more reliable across more distros as a classic snap. --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index eaccb78bf..bb1d46557 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -98,4 +98,5 @@ parts: - libelf1t64 - libsensors5 - libllvm17 + - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] From e174fb2748ef86f7c7f36e020b5954b24866f5ce Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 10 Jan 2025 08:57:01 -0500 Subject: [PATCH 57/81] no-patchelf for DRI and tidy up the mesa bits --- snap/snapcraft.yaml | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index bb1d46557..597ff3713 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -79,24 +79,44 @@ parts: libs: plugin: nil + build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 - libgtk-4-1 - libgtk-4-media-gstreamer - ibus-gtk4 - - libegl1 - - libegl-mesa0 - - libgl1-mesa-dri - - libglapi-mesa - - libglu1-mesa - - libglx-mesa0 - - mesa-va-drivers - - mesa-vulkan-drivers - libpciaccess0 - libtinfo6 - libedit2 - libelf1t64 - libsensors5 - libllvm17 + - libunistring5 - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] + stage: + # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - -usr/lib/*/dri + + mesa: + plugin: nil + build-attributes: [enable-patchelf] + stage-packages: + - libglu1-mesa + - libgl1-mesa-dri + - libegl-mesa0 + - libegl1 + - libglx-mesa0 + stage: + # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - -usr/lib/*/dri + + mesa-gl1-dri: + plugin: nil + stage-packages: + - libgl1-mesa-dri + build-attributes: [no-patchelf] + stage: + # Only the libraries in dri need to not be patched, the rest come from the mesa part + # Otherwise snapcraft may strip the build ID and cause the driver to crash + - usr/lib/*/dri From a85de40710b277c7dbe56e5e9eb7b8e57d284366 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 16:15:34 -0500 Subject: [PATCH 58/81] Exit with error if building for unsupported arch From 99c7abb43a565f04fcca3641cecfcd18848af0b1 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:11:37 -0500 Subject: [PATCH 59/81] Set GHOSTTY_RESOURCES_DIR From 301fdff58f9b982307bcf823e28a51b9be2a3788 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 29 Dec 2024 17:22:26 -0500 Subject: [PATCH 60/81] enable-patchelf is more repliable for classic snaps --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 597ff3713..33d1f7864 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,6 +67,7 @@ parts: source: . after: [zig] plugin: nil + build-attributes: [ enable-patchelf ] build-packages: - libgtk-4-dev - libadwaita-1-dev From 5de0e775cb8690571d952f1254c86066c4bb1202 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Mon, 30 Dec 2024 14:03:19 -0500 Subject: [PATCH 61/81] Don't stage shells --- snap/snapcraft.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 33d1f7864..00209f4c0 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,6 +72,9 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git + stage-packages: + - libadwaita-1-0 + - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast From e7d4daa7c10689ae826f2e9f46e43b477af4db1f Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sun, 12 Jan 2025 16:23:21 -0500 Subject: [PATCH 62/81] Removed duplicated stage-packages --- snap/snapcraft.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 00209f4c0..33d1f7864 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,9 +72,6 @@ parts: - libgtk-4-dev - libadwaita-1-dev - git - stage-packages: - - libadwaita-1-0 - - libgtk-4-1 override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast From 9944fd5958b23c19b1aeed09c39f948ffe773ce2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 Jan 2025 11:03:40 -0800 Subject: [PATCH 63/81] ci: temporary apt installs required for namespace --- .github/workflows/snap.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index 05f509f13..c5b7f5208 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -18,6 +18,8 @@ jobs: path: | /nix /zig + - run: sudo apt install -y udev + - run: sudo systemctl start systemd-udevd - uses: snapcore/action-build@v1 build-arm64: @@ -30,4 +32,6 @@ jobs: path: | /nix /zig + - run: sudo apt install -y udev + - run: sudo systemctl start systemd-udevd - uses: snapcore/action-build@v1 From 0acf82bb9c07a0289d164df872a3b9c3498d2e45 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 21 Jan 2025 08:48:48 +0200 Subject: [PATCH 64/81] Use patch-rpath which improves our cross distro support --- snap/snapcraft.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 33d1f7864..c616e67c5 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,14 +67,15 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [ enable-patchelf ] + build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev - git + - patchelf override-build: | craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) - $CRAFT_PART_SRC/../../zig/src/zig build -Doptimize=ReleaseFast + $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=/snap/ghostty/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From 725488e1a2b2a3851ea12d02ac25472cb971af76 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 21 Jan 2025 08:49:37 +0200 Subject: [PATCH 65/81] Improved environment handling to ensure the snap will work across distros and unset all SNAP environment variables that could leak at runtime --- snap/local/launcher | 69 +++++++++++---------------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index c65935127..7a77d8afc 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,5 +1,5 @@ -#!/bin/bash -set -euo pipefail +#!/bin/sh +set -e export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" @@ -13,62 +13,27 @@ else ARCH="$SNAP_ARCH-linux-gnu" fi -# VDPAU_DRIVER_PATH only supports a single path, rely on LD_LIBRARY_PATH instead -LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau -LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ -LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau +export LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ +export __EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d +export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d +export DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d +export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ +export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share +export XLOCALEDIR="${SNAP}/usr/share/X11/locale" -__EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d -__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${SNAP}/usr/share/egl/egl_external_platform.d -DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d -VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ -XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share -XLOCALEDIR="${SNAP}/usr/share/X11/locale" - -# These are in the default LD_LIBRARY_PATH, but in case the snap dropped it inadvertently -if [ -d "/var/lib/snapd/lib/gl" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl(:|$) ]]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl -fi - -if [ -d "/var/lib/snapd/lib/gl32" ] && [[ ! ${LD_LIBRARY_PATH} =~ (^|:)/var/lib/snapd/lib/gl32(:|$) ]]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32 -fi - -if [ -d "/var/lib/snapd/lib/glvnd/egl_vendor.d" ]; then - # This needs to be prepended, as glvnd goes depth-first on these - # TODO maybe collect the JSONs into a separate location so their ordering matters, - # and not the dir order - __EGL_VENDOR_LIBRARY_DIRS=/var/lib/snapd/lib/glvnd/egl_vendor.d:${__EGL_VENDOR_LIBRARY_DIRS} -fi - -if [ -d "/var/lib/snapd/lib/vulkan/icd.d" ]; then - XDG_DATA_DIRS=${XDG_DATA_DIRS}:/var/lib/snapd/lib -fi - -if [ -d "/var/lib/snapd/lib/gl/vdpau" ]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl/vdpau -fi - -if [ -d "/var/lib/snapd/lib/gl32/vdpau" ]; then - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/var/lib/snapd/lib/gl32/vdpau -fi - -if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then - export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm -fi - -export LD_LIBRARY_PATH export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications export LIBVA_DRIVERS_PATH fi -export __EGL_VENDOR_LIBRARY_DIRS -export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS -export DRIRC_CONFIGDIR -export VK_LAYER_PATH -export XDG_DATA_DIRS -export XLOCALEDIR + +# Unset all SNAP specific environment variables to keep them from leaking +# into other snaps that might get executed from within the shell +for var in $(printenv | grep SNAP | cut -d= -f1); do + unset $var +done exec "$@" From 5841a4f95857c83cf383cf353e253f1b1941dacc Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 22 Jan 2025 07:25:01 +0200 Subject: [PATCH 66/81] Stage libglib2.0-0t64 to insure we don't mix in the host's lib --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index c616e67c5..2b4f4a825 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -84,6 +84,7 @@ parts: build-attributes: [enable-patchelf] stage-packages: - libadwaita-1-0 + - libglib2.0-0t64 - libgtk-4-1 - libgtk-4-media-gstreamer - ibus-gtk4 From 7e5c57a848d02be61d29e473d61f33d15d08e7da Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 22 Jan 2025 07:38:41 +0200 Subject: [PATCH 67/81] Only export XDG_CONFIG_HOME and XDG_DATA_HOME if they aren't already set --- snap/local/launcher | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 7a77d8afc..6b5b69fa6 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -1,8 +1,15 @@ #!/bin/sh set -e -export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" -export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +# Set these to reasonable defaults if not already set +if [ -z "$XDG_CONFIG_HOME" ]; then + export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" +fi + +if [ -z "$XDG_DATA_HOME" ]; then + export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" +fi + export HOME="$SNAP_REAL_HOME" if [ "$SNAP_ARCH" = "amd64" ]; then From cb5379ab1d452df758bd508f4ecd0fe03d0fe426 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 24 Jan 2025 13:57:14 +0200 Subject: [PATCH 68/81] Unset environment varies set by the snap --- src/termio/Exec.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 5a2d2a507..07f1d6226 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -733,6 +733,19 @@ const Subprocess = struct { try env.put("GHOSTTY_RESOURCES_DIR", dir); } + // Unset environment varies set by the snap + if (env.get("SNAP") != null) { + env.remove("SNAP"); + env.remove("DRIRC_CONFIGDIR"); + env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); + env.remove("__EGL_VENDOR_LIBRARY_DIRS"); + env.remove("LD_LIBRARY_PATH"); + env.remove("LIBGL_DRIVERS_PATH"); + env.remove("LIBVA_DRIVERS_PATH"); + env.remove("VK_LAYER_PATH"); + env.remove("XLOCALEDIR"); + } + // Set our TERM var. This is a bit complicated because we want to use // the ghostty TERM value but we want to only do that if we have // ghostty in the TERMINFO database. From e4cf81c2ba8662d02937a5e087b12712d77ffe41 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 24 Jan 2025 13:57:30 +0200 Subject: [PATCH 69/81] Clean up environment variable while launching the shell --- snap/local/launcher | 3 +-- snap/snapcraft.yaml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/snap/local/launcher b/snap/local/launcher index 6b5b69fa6..c0f204060 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -30,7 +30,6 @@ export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/i export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share export XLOCALEDIR="${SNAP}/usr/share/X11/locale" -export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU # https://download.nvidia.com/XFree86/Linux-x86_64/510.54/README/primerenderoffload.html#configureapplications @@ -39,7 +38,7 @@ fi # Unset all SNAP specific environment variables to keep them from leaking # into other snaps that might get executed from within the shell -for var in $(printenv | grep SNAP | cut -d= -f1); do +for var in $(printenv | grep SNAP_ | cut -d= -f1); do unset $var done diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 2b4f4a825..a27f35e45 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -95,7 +95,6 @@ parts: - libsensors5 - libllvm17 - libunistring5 - - gnome-text-editor # Needed for config editor - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part From ff5c1001c64aaa4bc8eb9c6023d85aa9b921d04d Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Sat, 25 Jan 2025 07:44:32 -0500 Subject: [PATCH 70/81] Per PR review feedback, this is the more "ziggy" way of doing the check for environment variable. --- src/termio/Exec.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 07f1d6226..39e5569ea 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -734,7 +734,7 @@ const Subprocess = struct { } // Unset environment varies set by the snap - if (env.get("SNAP") != null) { + if (env.get("SNAP")) |_| { env.remove("SNAP"); env.remove("DRIRC_CONFIGDIR"); env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); From bd6a133e95cf9fc5c30fd25d42f11049deac9a5c Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 7 Feb 2025 14:39:48 -0500 Subject: [PATCH 71/81] Updated stage packages --- snap/snapcraft.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a27f35e45..732700272 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -67,7 +67,7 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [enable-patchelf] + build-attributes: [no-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev @@ -95,6 +95,7 @@ parts: - libsensors5 - libllvm17 - libunistring5 + - librsvg2-2 - on amd64: [i965-va-driver,libdrm-intel1,libdrm-nouveau2,libdrm-amdgpu1,libdrm-radeon1] stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part @@ -109,8 +110,12 @@ parts: - libegl-mesa0 - libegl1 - libglx-mesa0 + - mesa-libgallium stage: # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part + - usr/lib/*/*.so* + - usr/lib/*/dri/libdril_dri.so + - -usr/lib/*/libgallium*so - -usr/lib/*/dri mesa-gl1-dri: @@ -121,4 +126,6 @@ parts: stage: # Only the libraries in dri need to not be patched, the rest come from the mesa part # Otherwise snapcraft may strip the build ID and cause the driver to crash + - usr/lib/*/libgallium*so + - -usr/lib/*/dri/libdril_dri.so - usr/lib/*/dri From 238b0faf5cdef6928b799aff83c8ed0663d286de Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 13 Feb 2025 21:42:49 -0500 Subject: [PATCH 72/81] Simplified setting snap version --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 732700272..37020a2d6 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -74,7 +74,7 @@ parts: - git - patchelf override-build: | - craftctl set version=$(grep version build.zig.zon |awk -F '"' '{print $2}')-$(git describe --abbrev=8) + craftctl set version=$(git describe --abbrev=8) $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=/snap/ghostty/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From 94e2982d4b26f6cb8c335f65594cbe8cf0592fe6 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 14 Feb 2025 17:16:36 -0500 Subject: [PATCH 73/81] Allow snap to refresh while running --- snap/snapcraft.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 37020a2d6..af2ee8f3c 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -23,6 +23,7 @@ apps: command-chain: [bin/launcher] completer: share/bash-completion/completions/ghostty.bash desktop: share/applications/com.mitchellh.ghostty.desktop + refresh-mode: ignore-running environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 From 2adee4290a2c57fe9cc7a9a60e6bc82ced908b39 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 14 Feb 2025 18:07:39 -0500 Subject: [PATCH 74/81] Improved rpath handling for ghostty --- snap/snapcraft.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index af2ee8f3c..b19472935 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -68,7 +68,7 @@ parts: source: . after: [zig] plugin: nil - build-attributes: [no-patchelf] + build-attributes: [enable-patchelf] build-packages: - libgtk-4-dev - libadwaita-1-dev @@ -76,7 +76,7 @@ parts: - patchelf override-build: | craftctl set version=$(git describe --abbrev=8) - $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=/snap/ghostty/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast + $CRAFT_PART_SRC/../../zig/src/zig build -Dpatch-rpath=\$ORIGIN/../usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:/snap/core24/current/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR -Doptimize=ReleaseFast cp -rp zig-out/* $CRAFT_PART_INSTALL/ sed -i 's|Icon=com.mitchellh.ghostty|Icon=/snap/ghostty/current/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png|g' $CRAFT_PART_INSTALL/share/applications/com.mitchellh.ghostty.desktop From d3623393a68e2e7f240cccbd7fbac9d75a2bbb44 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 14 Feb 2025 18:14:06 -0500 Subject: [PATCH 75/81] More environment handling to ensure reliability across distros --- snap/local/launcher | 9 ++++++++- src/termio/Exec.zig | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/snap/local/launcher b/snap/local/launcher index c0f204060..11597f238 100755 --- a/snap/local/launcher +++ b/snap/local/launcher @@ -6,6 +6,10 @@ if [ -z "$XDG_CONFIG_HOME" ]; then export XDG_CONFIG_HOME="$SNAP_REAL_HOME/.config" fi +if [ -z "$XDG_CACHE_HOME" ]; then + export XDG_CACHE_HOME="$SNAP_REAL_HOME/.cache" +fi + if [ -z "$XDG_DATA_HOME" ]; then export XDG_DATA_HOME="$SNAP_REAL_HOME/.local/share" fi @@ -20,7 +24,7 @@ else ARCH="$SNAP_ARCH-linux-gnu" fi -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau +export LD_LIBRARY_PATH=${SNAP}/usr/lib/${ARCH}:${SNAP}/usr/lib/${ARCH}/vdpau:${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:} export LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ export LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH:+$LIBVA_DRIVERS_PATH:}${SNAP}/usr/lib/${ARCH}/dri/ export __EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${SNAP}/usr/share/glvnd/egl_vendor.d @@ -29,6 +33,9 @@ export DRIRC_CONFIGDIR=${SNAP}/usr/share/drirc.d export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${SNAP}/usr/share/vulkan/implicit_layer.d/:${SNAP}/usr/share/vulkan/explicit_layer.d/ export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${SNAP}/usr/share export XLOCALEDIR="${SNAP}/usr/share/X11/locale" +export GDK_PIXBUF_MODULE_FILE="$XDG_CACHE_HOME/gdk-pixbuf-loaders.cache" +export GDK_PIXBUF_MODULEDIR="$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/2.10.0/loaders" +export GTK_PATH="$SNAP/usr/lib/$ARCH/gtk-4.0" if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then # Prevent picking VA-API (Intel/AMD) over NVIDIA VDPAU diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 39e5569ea..026b48f7f 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -744,6 +744,9 @@ const Subprocess = struct { env.remove("LIBVA_DRIVERS_PATH"); env.remove("VK_LAYER_PATH"); env.remove("XLOCALEDIR"); + env.remove("GDK_PIXBUF_MODULEDIR"); + env.remove("GDK_PIXBUF_MODULE_FILE"); + env.remove("GTK_PATH"); } // Set our TERM var. This is a bit complicated because we want to use From b551e106a83f82bfff02595732609a1ee16dcbe6 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 14 Feb 2025 18:27:19 -0500 Subject: [PATCH 76/81] Comment out refresh-mode, the store rejects this. Needs fixing in review-tools --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a41e5192b..9ef2f5cc4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -23,7 +23,7 @@ apps: command-chain: [bin/launcher] completer: share/bash-completion/completions/ghostty.bash desktop: share/applications/com.mitchellh.ghostty.desktop - refresh-mode: ignore-running + #refresh-mode: ignore-running # Store rejects this, needs fix in review-tools environment: PATH: /snap/ghostty/current/bin:/snap/ghostty/current/usr/bin:$PATH LC_ALL: C.UTF-8 From 03d1240999ad63e4b4bd9676ffe465ea99db3a9d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 Feb 2025 07:07:08 -0800 Subject: [PATCH 77/81] nix: use snapcraft only on Linux --- nix/devShell.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/devShell.nix b/nix/devShell.nix index 374dfe669..66f259656 100644 --- a/nix/devShell.nix +++ b/nix/devShell.nix @@ -106,7 +106,6 @@ in pandoc pkg-config scdoc - snapcraft zig zip zig2nix.packages.${system}.zon2nix From 494273cf085973d67c3e25dd2006160529710193 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 Feb 2025 07:10:25 -0800 Subject: [PATCH 78/81] ci: snap workflow requires git history --- .github/workflows/snap.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml index c5b7f5208..81f012d3e 100644 --- a/.github/workflows/snap.yaml +++ b/.github/workflows/snap.yaml @@ -12,6 +12,9 @@ jobs: runs-on: namespace-profile-ghostty-snap steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Setup Cache uses: namespacelabs/nscloud-cache-action@v1.2.0 with: @@ -26,6 +29,9 @@ jobs: runs-on: namespace-profile-ghostty-snap-arm64 steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Setup Cache uses: namespacelabs/nscloud-cache-action@v1.2.0 with: From 88a6b542b3f83c6475d4c5f5898b62a68cbd62f4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 Feb 2025 07:20:46 -0800 Subject: [PATCH 79/81] ci: move snap testing into our big test workflow --- .github/workflows/snap.yaml | 43 ------------------------------------- .github/workflows/test.yml | 26 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/snap.yaml diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml deleted file mode 100644 index 81f012d3e..000000000 --- a/.github/workflows/snap.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Snap - -on: - push: - branches: [main] - pull_request: - branches: [main] - workflow_dispatch: {} - -jobs: - build-amd64: - runs-on: namespace-profile-ghostty-snap - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - name: Setup Cache - uses: namespacelabs/nscloud-cache-action@v1.2.0 - with: - path: | - /nix - /zig - - run: sudo apt install -y udev - - run: sudo systemctl start systemd-udevd - - uses: snapcore/action-build@v1 - - build-arm64: - runs-on: namespace-profile-ghostty-snap-arm64 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - name: Setup Cache - uses: namespacelabs/nscloud-cache-action@v1.2.0 - with: - path: | - /nix - /zig - - run: sudo apt install -y udev - - run: sudo systemctl start systemd-udevd - - uses: snapcore/action-build@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41a54fde3..ebecdf21e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -276,6 +276,32 @@ jobs: nix develop -c zig build --system ${{ steps.deps.outputs.deps }} -Dapp-runtime=glfw -Drenderer=metal -Dfont-backend=coretext_harfbuzz nix develop -c zig build --system ${{ steps.deps.outputs.deps }} -Dapp-runtime=glfw -Drenderer=metal -Dfont-backend=coretext_noshape + build-snap: + strategy: + fail-fast: false + matrix: + os: + [namespace-profile-ghostty-snap, namespace-profile-ghostty-snap-arm64] + runs-on: ${{ matrix.os }} + needs: test + env: + ZIG_LOCAL_CACHE_DIR: /zig/local-cache + ZIG_GLOBAL_CACHE_DIR: /zig/global-cache + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + - name: Setup Cache + uses: namespacelabs/nscloud-cache-action@v1.2.0 + with: + path: | + /nix + /zig + - run: sudo apt install -y udev + - run: sudo systemctl start systemd-udevd + - uses: snapcore/action-build@v1 + build-windows: runs-on: windows-2022 # this will not stop other jobs from running From 818bc779b38c6d8b0ca7aef9ce509739700242ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 Feb 2025 07:22:10 -0800 Subject: [PATCH 80/81] apprt/gtk: unset snap env vars --- src/apprt/gtk/Surface.zig | 17 +++++++++++++++++ src/termio/Exec.zig | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 6c39677d5..42c8278a2 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -2264,6 +2264,23 @@ pub fn defaultTermioEnv(self: *Surface) !std.process.EnvMap { env.remove("GDK_DISABLE"); env.remove("GSK_RENDERER"); + // Unset environment varies set by snaps if we're running in a snap. + // This allows Ghostty to further launch additional snaps. + if (env.get("SNAP")) |_| { + env.remove("SNAP"); + env.remove("DRIRC_CONFIGDIR"); + env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); + env.remove("__EGL_VENDOR_LIBRARY_DIRS"); + env.remove("LD_LIBRARY_PATH"); + env.remove("LIBGL_DRIVERS_PATH"); + env.remove("LIBVA_DRIVERS_PATH"); + env.remove("VK_LAYER_PATH"); + env.remove("XLOCALEDIR"); + env.remove("GDK_PIXBUF_MODULEDIR"); + env.remove("GDK_PIXBUF_MODULE_FILE"); + env.remove("GTK_PATH"); + } + if (self.container.window()) |window| { // On some window protocols we might want to add specific // environment variables to subprocesses, such as WINDOWID on X11. diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 026b48f7f..5a2d2a507 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -733,22 +733,6 @@ const Subprocess = struct { try env.put("GHOSTTY_RESOURCES_DIR", dir); } - // Unset environment varies set by the snap - if (env.get("SNAP")) |_| { - env.remove("SNAP"); - env.remove("DRIRC_CONFIGDIR"); - env.remove("__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS"); - env.remove("__EGL_VENDOR_LIBRARY_DIRS"); - env.remove("LD_LIBRARY_PATH"); - env.remove("LIBGL_DRIVERS_PATH"); - env.remove("LIBVA_DRIVERS_PATH"); - env.remove("VK_LAYER_PATH"); - env.remove("XLOCALEDIR"); - env.remove("GDK_PIXBUF_MODULEDIR"); - env.remove("GDK_PIXBUF_MODULE_FILE"); - env.remove("GTK_PATH"); - } - // Set our TERM var. This is a bit complicated because we want to use // the ghostty TERM value but we want to only do that if we have // ghostty in the TERMINFO database. From baa47ff24ed80cfd87773aa1091dc58fb2a7c392 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 Feb 2025 07:24:18 -0800 Subject: [PATCH 81/81] ci: test requires build-snap --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ebecdf21e..20ca3f419 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,7 @@ jobs: - build-bench - build-linux-libghostty - build-nix + - build-snap - build-macos - build-macos-matrix - build-windows