Layers/scripts/linux/build.sh

62 lines
1.9 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 — use the wayland provider (winit xdg-toplevel,
# render transparency, user pins on top via compositor).
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
echo "wayland"
return
fi
# X11 session or no WAYLAND_DISPLAY: use the X11 provider.
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"