From ea40c1d9b3ddef7f9f3966a7e01b4cca50deb7e2 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Wed, 19 Feb 2025 10:28:23 -0700 Subject: [PATCH] Add scripts and configuration for building snap package (#25064) Release Notes: - N/A --------- Co-authored-by: Soumyadeep Ghosh --- .gitignore | 1 + crates/zed/resources/snap/snapcraft.yaml.in | 58 +++++++++++++++++++++ script/snap-build | 27 ++++++++++ script/snap-try | 25 +++++++++ 4 files changed, 111 insertions(+) create mode 100644 crates/zed/resources/snap/snapcraft.yaml.in create mode 100755 script/snap-build create mode 100755 script/snap-try diff --git a/.gitignore b/.gitignore index 99a6184f56..45f74d34c1 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ /dev.zed.Zed*.json /plugins/bin /script/node_modules +/snap /zed.xcworkspace DerivedData/ Packages diff --git a/crates/zed/resources/snap/snapcraft.yaml.in b/crates/zed/resources/snap/snapcraft.yaml.in new file mode 100644 index 0000000000..832237497c --- /dev/null +++ b/crates/zed/resources/snap/snapcraft.yaml.in @@ -0,0 +1,58 @@ +name: zed +title: Zed +base: core24 +version: "$RELEASE_VERSION" +summary: The editor for what's next +description: | + Zed is a modern open-source code editor, built from the ground up in Rust with + a GPU-accelerated renderer. We help you build software faster than ever before. +grade: stable +confinement: classic +compression: lzo +icon: crates/zed/resources/app-icon.png +website: https://zed.dev/ +source-code: https://github.com/zed-industries/zed +issues: https://github.com/zed-industries/zed/issues +contact: https://zed.dev/community-links#support-and-feedback + +parts: + zed: + plugin: dump + source: "https://github.com/zed-industries/zed/releases/download/v$RELEASE_VERSION/zed-linux-x86_64.tar.gz" + + organize: + # These renames seem to not be necessary, but it's tidier. + bin: usr/bin + libexec: usr/libexec + + stage-packages: + - libasound2t64 + # snapcraft has a lint that this is unused, but without it Zed exits with + # "Missing Vulkan entry points: LibraryLoadFailure" in blade_graphics. + - libvulkan1 + # snapcraft has a lint that this is unused, but without it Zed exits with + # "NoWaylandLib" when run with Wayland. + - libwayland-client0 + - libxcb1 + - libxkbcommon-x11-0 + - libxkbcommon0 + + build-attributes: + - enable-patchelf + + prime: + # Omit unneeded files from the tarball + - -lib + - -licenses.md + - -share + + # Omit unneeded files from stage-packages + - -etc + - -usr/share/doc + - -usr/share/lintian + - -usr/share/man + +apps: + zed: + command: usr/bin/zed + common-id: dev.zed.Zed diff --git a/script/snap-build b/script/snap-build new file mode 100755 index 0000000000..62eae6f9de --- /dev/null +++ b/script/snap-build @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +mkdir -p snap/gui + +export DO_STARTUP_NOTIFY="true" +export APP_NAME="Zed" +export APP_CLI="zed" +export APP_ICON="\${SNAP}/meta/gui/zed.png" +export APP_ARGS="%U" +envsubst < "crates/zed/resources/zed.desktop.in" > "snap/gui/zed.desktop" +cp "crates/zed/resources/app-icon.png" "snap/gui/zed.png" + +RELEASE_VERSION="$1" envsubst < crates/zed/resources/snap/snapcraft.yaml.in > snap/snapcraft.yaml + +# Clean seems to be needed to actually check that the snapcraft.yaml +# works. For example, when a `stage-package` is removed, it will +# still remain on rebuild. +snapcraft clean + +snapcraft diff --git a/script/snap-try b/script/snap-try new file mode 100755 index 0000000000..a262c0139a --- /dev/null +++ b/script/snap-try @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# This script is intended to be run after `snap-build`. +# +# It expects a version to be passed as the first argument, and expects +# the built `.snap` for that version to be in the current directory. +# +# This will uninstall the current `zed` snap, replacing it with a snap +# that directly uses the `snap/unpacked` directory. + +set -euxo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Rerun as root +[ "$UID" -eq 0 ] || exec sudo bash -e "$0" "$@" + +snap remove zed || true +mkdir -p snap +rm -rf snap/unpacked +unsquashfs -dest snap/unpacked "zed_$1_amd64.snap" +snap try --classic snap/unpacked