Layers/scripts/linux/build.sh

67 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"
render_plugin_json() {
local entrypoint="$1"
local out="$2"
local in="$ROOT/plugin.json.in"
if [ ! -f "$in" ]; then
echo "ERROR: $in not found" >&2
exit 1
fi
sed "s|@ENTRYPOINT@|$entrypoint|g" "$in" > "$out"
}
STAGE="$ROOT/build/bin/com.jesshunter.layers"
APPDIR="$STAGE/bin"
rm -rf "$STAGE"
mkdir -p "$APPDIR" "$STAGE/resources"
if command -v rsvg-convert >/dev/null 2>&1 && [ -f "$ROOT/resources/Layers.svg" ]; then
for size in 24 48 128 256; do
if [ ! -f "$ROOT/resources/icon-${size}.png" ]; then
rsvg-convert --width "$size" --height "$size" \
"$ROOT/resources/Layers.svg" -o "$ROOT/resources/icon-${size}.png"
fi
done
fi
# Detect the running window-manager / display protocol to pick the front-end
# provider that gets compiled into the binary. Override with LAYERS_FEATURES.
detect_wm_feature() {
if [ -n "${LAYERS_FEATURES:-}" ]; then
echo "$LAYERS_FEATURES"
return
fi
# Native Wayland session AND a compositor known to ship wlr-layer-shell.
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
case "${XDG_CURRENT_DESKTOP:-}" in
*COSMIC*|*KDE*|*Plasma*|sway|Hyprland|niri|river|Wayfire)
echo "wayland"
return
;;
esac
fi
# GNOME-Wayland (mutter, no layer-shell), every X11 session, every other
# GTK3-class compositor: ship the X11 provider — XWayland honours the hints
# everywhere except cosmic-comp, where the wayland provider applies instead.
echo "x11"
}
FEATURE="$(detect_wm_feature)"
echo "build: front-end provider = $FEATURE (XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP:-<unset>}, WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-<unset>})"
cargo build --release --bin layers --no-default-features --features "$FEATURE"
cp "$ROOT/target/release/layers" "$APPDIR/Layers"
chmod +x "$APPDIR/Layers"
render_plugin_json "bin/Layers" "$STAGE/plugin.json"
[ -f "$ROOT/LICENCE" ] && cp "$ROOT/LICENCE" "$STAGE/LICENCE"
cp -r "$ROOT/resources/." "$STAGE/resources/"
echo "staged: $STAGE"
echo "bin: $APPDIR/Layers"