#!/bin/bash # Damson release packages. Run: tools/package.sh (see the common part below for what it makes) set -euo pipefail root=$(cd "$(dirname "$0")/.." && pwd) APP=damson NAME=Damson DESKTOP=damson.desktop URL=https://astar76.com/git/astar76/Damson ver=$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -n 1) BINS=(damson) LICENSE=MIT NIX_LICENSE=mit SUMMARY='Material You code editor with 462 languages built in' DEB_DEPENDS='libgl1, libegl1, libwayland-client0, libwayland-egl1, libxkbcommon0, libxkbcommon-x11-0, libx11-6, libxcursor1, libxi6, libxrandr2, libfontconfig1, libdbus-1-3' DEB_RECOMMENDS='git, xdg-desktop-portal' DEB_SECTION=editors NIX_ARGS='libGL, wayland, libxkbcommon, xorg, fontconfig, dbus' NIX_RUNTIME='libGL wayland libxkbcommon xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr fontconfig dbus' NIX_BUILD_INPUTS='stdenv.cc.cc.lib' WIN=0 # Damson uses Unix sockets (Discord) and sudo saves; no Windows port yet ZIG_GLIBC=2.35 build() { nice cargo zigbuild --release --locked -q -j 2 --target x86_64-unknown-linux-gnu.$ZIG_GLIBC; } # share/ as it lands under the prefix stage() { local s=$1 b=$rel/damson install -Dm644 packaging/damson.desktop "$s/applications/damson.desktop" install -Dm644 packaging/damson.metainfo.xml "$s/metainfo/damson.metainfo.xml" install -Dm644 packaging/damson.svg "$s/icons/hicolor/scalable/apps/damson.svg" for n in 16 24 32 48 64 128 256 512; do mkdir -p "$s/icons/hicolor/${n}x$n/apps"; "$b" --export-icon "$n" "$s/icons/hicolor/${n}x$n/apps/damson.png" done install -Dm644 LICENSE "$s/licenses/damson/LICENSE" install -Dm644 assets/syntax/LICENSES.md "$s/licenses/damson/syntax-definitions.md" install -Dm644 assets/syntax/KSyntaxHighlighting-MIT.txt "$s/licenses/damson/KSyntaxHighlighting-MIT.txt" } stage() { local s=$1 b=$rel/damson install -Dm644 packaging/damson.desktop "$s/applications/damson.desktop" install -Dm644 packaging/damson.metainfo.xml "$s/metainfo/damson.metainfo.xml" install -Dm644 packaging/damson.svg "$s/icons/hicolor/scalable/apps/damson.svg" for n in 16 24 32 48 64 128 256 512; do mkdir -p "$s/icons/hicolor/${n}x$n/apps"; "$b" --export-icon "$n" "$s/icons/hicolor/${n}x$n/apps/damson.png" done install -Dm644 LICENSE "$s/licenses/damson/LICENSE" install -Dm644 assets/syntax/LICENSES.md "$s/licenses/damson/syntax-definitions.md" install -Dm644 assets/syntax/KSyntaxHighlighting-MIT.txt "$s/licenses/damson/KSyntaxHighlighting-MIT.txt" } # ---------------------------------------------------------------- common part (same in every project) # Builds into dist/ (and never writes to releases/): # $NAME--Linux-x86_64.tar.gz bin/ share/ [lib/] laid out like a prefix, with install.sh and uninstall.sh # $NAME--x86_64.AppImage GUI apps (DESKTOP set); BUNDLE_LIBS=1 adds the non-desktop library closure # $NAME--arch-x86_64.pkg.tar.zst makepkg from that tar.gz, offline ($PKGDIR/PKGBUILD gets version and checksum) # $NAME--amd64.deb the same tree under /usr, for apt # $NAME--Setup.exe and $NAME--Windows-portable.zip when WIN=1 (mingw cross build, Inno Setup in wine) # SHA256SUMS- # It also writes packaging/nix/default.nix (fetches the release tar.gz; version and hash filled in here) and the # glibc floor read from the binary into installer.sh, the PKGBUILD and the .deb. Nothing is downloaded: appimagetool # and libmpv-2.dll come from ~/.local/opt/build-tools. # SKIP_BUILD=1 packages the existing build, NO_WIN=1 skips Windows. CARGO_TARGET_DIR is honoured. cd "$root"; PKGDIR=${PKGDIR:-packaging/arch} tools=${BUILD_TOOLS:-$HOME/.local/opt/build-tools} [ "${SKIP_BUILD:-}" = 1 ] || build tdir=${CARGO_TARGET_DIR:-$root/target} rel=$tdir/release # ZIG_GLIBC: built with cargo-zigbuild against that glibc, so the binary runs on older distributions too. [ -z "${ZIG_GLIBC:-}" ] || rel=$tdir/x86_64-unknown-linux-gnu/release out=$root/dist mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}"; work=$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/package.XXXXXX"); trap 'rm -rf "$work"' EXIT export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct 2>/dev/null || date +%s)} # hicolor PNGs from an SVG: icon_pngs icon_pngs() { install -Dm644 "$1" "$2/icons/hicolor/scalable/apps/$3.svg" for n in 16 24 32 48 64 128 256 512; do mkdir -p "$2/icons/hicolor/${n}x$n/apps"; rsvg-convert -w "$n" -h "$n" "$1" -o "$2/icons/hicolor/${n}x$n/apps/$3.png" done } # glibc floor: the newest GLIBC_x.y symbol version any shipped binary (or EXTRA_ELF library) needs. glibc=$(for b in "${BINS[@]}" ${EXTRA_ELF[@]+"${EXTRA_ELF[@]}"}; do objdump -T "$rel/$b"; done | grep -o 'GLIBC_[0-9.]*' | sed 's/GLIBC_//' | sort -uV | tail -n 1) [ -n "$glibc" ] || { echo "could not read the glibc version from the binary" >&2; exit 1; } sed -i "s/^app=$APP main=\([^ ]*\) need=.*/app=$APP main=\1 need=$glibc/; s/glibc [0-9.]* or newer\./glibc $glibc or newer./" installer.sh sed -i "s/'glibc>=[0-9.]*'/'glibc>=$glibc'/" $PKGDIR/PKGBUILD # tar.gz: bin/ and share/ laid out like a prefix, so installer.sh, the PKGBUILD, the .deb and Nix just copy them. rm -rf "$out"; mkdir -p "$out" t=$work/$APP-$ver mkdir -p "$t/bin" "$t/share" # stage may add $t/lib too for b in "${BINS[@]}"; do install -m755 "$rel/$b" "$t/bin/$b"; done stage "$t/share" install -m755 installer.sh "$t/install.sh" printf '#!/bin/sh\n# Removes %s installed by install.sh. --purge also deletes settings and data; --system or --prefix DIR as for install.sh.\nexec sh "$(dirname "$0")/install.sh" --uninstall "$@"\n' "$NAME" > "$t/uninstall.sh" chmod 755 "$t/uninstall.sh" cp README.md "$t/" find "$t" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + tgz=$NAME-$ver-Linux-x86_64.tar.gz tar -C "$work" --sort=name --owner=0 --group=0 --numeric-owner -cf - "$APP-$ver" | gzip -n -9 > "$out/$tgz" # AppImage (GUI apps): the same tree under usr/, desktop file and icon at the top. if [ -n "${DESKTOP:-}" ]; then a=$work/AppDir mkdir -p "$a/usr" cp -R "$t/bin" "$t/share" "$a/usr/"; [ ! -d "$t/lib" ] || cp -R "$t/lib" "$a/usr/" if [ "${BUNDLE_LIBS:-0}" = 1 ]; then # Libraries every desktop already has (glibc, graphics, windowing, sound servers, fonts) stay with the host. skip='^(linux-vdso|ld-linux|libc|libm|libdl|libpthread|librt|libutil|libresolv|libnsl|libgcc_s|libstdc\+\+|libGL|libGLX|libGLdispatch|libEGL|libOpenGL|libGLESv2|libgbm|libdrm|libvulkan|libX11|libX11-xcb|libxcb.*|libXau|libXdmcp|libXext|libXfixes|libXrandr|libXrender|libXi|libXcursor|libXss|libXv|libXxf86vm|libXinerama|libwayland-.*|libxkbcommon.*|libfontconfig|libfreetype|libharfbuzz|libglib-2.0|libgobject-2.0|libgio-2.0|libgmodule-2.0|libdbus-1|libsystemd|libudev|libasound|libpulse.*|libpipewire-0.3|libjack|libsndio|libcap|libselinux|libpcre2-8|libffi|libz|libexpat|libnss.*)\.so' mkdir -p "$a/usr/lib" ldd "$rel/${BINS[0]}" | awk '/=> \//{print $3} $1 ~ /^\// {print $1}' | while read -r lib; do name=$(basename "$lib"); [[ $name =~ $skip ]] || cp -L "$lib" "$a/usr/lib/$name" done fi cp "$a/usr/share/applications/$DESKTOP" "$a/" icon=$(sed -n 's/^Icon=//p' "$a/$DESKTOP" | head -n 1) for ext in svg png; do f=$(find "$a/usr/share/icons" -name "$icon.$ext" | sort -V | tail -n 1) [ -n "$f" ] && { cp "$f" "$a/$icon.$ext"; break; } done cat > "$a/AppRun" </dev/null) ARCH=x86_64 "$work/squashfs-root/AppRun" --no-appstream "$a" "$out/$NAME-$ver-x86_64.AppImage" >"$work/ait.log" 2>&1 \ || { tail -20 "$work/ait.log"; exit 1; } fi # Arch package from the local tar.gz; the repo's PKGBUILD gets this version and checksum. sum=$(sha256sum "$out/$tgz" | cut -d' ' -f1) sed -i "s/^pkgver=.*/pkgver=$ver/; s/^sha256sums=.*/sha256sums=('$sum')/" $PKGDIR/PKGBUILD mkdir "$work/arch"; cp $PKGDIR/PKGBUILD "$work/arch/" (cd "$work/arch" && makepkg --printsrcinfo > "$root/$PKGDIR/.SRCINFO") (cd "$work/arch" && TARBALL="file://$out/$tgz" makepkg -f -C --nodeps --noconfirm >"$work/makepkg.log" 2>&1) \ || { tail -20 "$work/makepkg.log"; exit 1; } cp "$work"/arch/"$APP"-bin-"$ver"-*-x86_64.pkg.tar.zst "$out/$NAME-$ver-arch-x86_64.pkg.tar.zst" # .deb: the tar.gz tree under /usr (licenses go to /usr/share/doc// as Debian expects). d=$work/deb mkdir -p "$d/root/usr" "$d/root/usr/share/doc/$APP" "$d/control" for x in bin lib share; do [ ! -d "$t/$x" ] || cp -R "$t/$x" "$d/root/usr/"; done if [ -d "$d/root/usr/share/licenses/$APP" ]; then cp -R "$d/root/usr/share/licenses/$APP/." "$d/root/usr/share/doc/$APP/"; rm -rf "$d/root/usr/share/licenses" fi cp README.md "$d/root/usr/share/doc/$APP/" { echo "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"; echo "Upstream-Name: $NAME" echo "Source: $URL"; echo; echo "Files: *"; echo "License: $LICENSE"; } > "$d/root/usr/share/doc/$APP/copyright" size=$(du -sk "$d/root" | cut -f1) cat > "$d/control/control" < Installed-Size: $size Depends: libc6 (>= $glibc)${DEB_DEPENDS:+, $DEB_DEPENDS} ${DEB_RECOMMENDS:+Recommends: $DEB_RECOMMENDS }Section: ${DEB_SECTION:-misc} Priority: optional Homepage: $URL Description: $SUMMARY Built from $URL (version $ver). Needs glibc $glibc or newer. CTL (cd "$d/root" && find . -type f -printf '%P\n' | sort | xargs -d '\n' md5sum) > "$d/control/md5sums" find "$d/root" "$d/control" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + echo 2.0 > "$d/debian-binary" tar -C "$d/control" --sort=name --owner=0 --group=0 --numeric-owner -czf "$d/control.tar.gz" . tar -C "$d/root" --sort=name --owner=0 --group=0 --numeric-owner -cJf "$d/data.tar.xz" . deb=$out/$NAME-$ver-amd64.deb (cd "$d" && ar rcD "$deb" debian-binary control.tar.gz data.tar.xz) ! command -v dpkg-deb >/dev/null || dpkg-deb --info "$deb" >/dev/null # Nix: packaging/nix/default.nix fetches this release's tar.gz (flake.nix at the top calls it). mkdir -p packaging/nix sri=sha256-$(openssl dgst -sha256 -binary "$out/$tgz" | base64 -w0) cat > packaging/nix/default.nix < flake.nix </dev/null || { echo "Windows needs mingw-w64-gcc (sudo pacman -S mingw-w64-gcc), or NO_WIN=1." >&2; exit 1; } if [ -n "${WIN_DLLS[*]:-}" ] && [ "${WIN_MPV:-0}" = 1 ]; then # import library for libmpv-2.dll, so the cross linker can link "mpv" lib=$tools/winlib; mkdir -p "$lib" if [ ! -f "$lib/libmpv.dll.a" ]; then { echo "LIBRARY libmpv-2.dll"; echo EXPORTS x86_64-w64-mingw32-objdump -p "$tools/libmpv-2.dll" | sed -n '/\[Ordinal\/Name Pointer\] Table/,/^$/p' | awk '/^\s*\[ *[0-9]+\] \+base/ {print $NF}'; } > "$lib/mpv.def" x86_64-w64-mingw32-dlltool -d "$lib/mpv.def" -D libmpv-2.dll -l "$lib/libmpv.dll.a" fi export RUSTFLAGS="${RUSTFLAGS:-} -L $lib" fi [ "${SKIP_BUILD:-}" = 1 ] || nice cargo build --release --locked -q -j 2 --target x86_64-pc-windows-gnu w=$work/win/$NAME; mkdir -p "$w" for b in "${BINS[@]}"; do install -m755 "$tdir/x86_64-pc-windows-gnu/release/$b.exe" "$w/"; done for f in ${WIN_DLLS[@]+"${WIN_DLLS[@]}"}; do install -m644 "$tools/$f" "$w/"; done install -m644 LICENSE "$w/LICENSE.txt" find "$work/win" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + (cd "$work/win" && zip -qrX9 "$out/$NAME-$ver-Windows-portable.zip" "$NAME") iscc="$HOME/.wine/drive_c/users/$USER/AppData/Local/Programs/Inno Setup 7/ISCC.exe" WINEDEBUG=-all wine "$iscc" /Q "/DVersion=$ver" "/DSrc=Z:$w" "/DOut=Z:$out" "Z:$root/packaging/$APP.iss" >"$work/iscc.log" 2>&1 \ || { tail -20 "$work/iscc.log"; exit 1; } fi (cd "$out" && sha256sum "$NAME-$ver"-* > "SHA256SUMS-$ver") echo "glibc floor: $glibc" ls -l "$out"