Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Curate the AppImage's libraries and drop the dev tool from packages

Bitti68b8df0608c4
diff --git a/scripts/generate-reference-icons.mjs b/scripts/generate-reference-icons.mjs
index 603f7b7..7c19313 100644
--- a/scripts/generate-reference-icons.mjs
+++ b/scripts/generate-reference-icons.mjs
@@ -237,7 +237,7 @@ try {
await run(settings.cargo, [
"build", "--quiet",
"--manifest-path", join(repository, "src-tauri", "Cargo.toml"),
- "--bin", "reference_icons",
+ "--bin", "reference_icons", "--features", "reference-icon-tool",
], { cwd: repository });
const workerCount = Math.max(1, Math.min(specs.length, Number.isFinite(requestedWorkers) ? Math.floor(requestedWorkers) : 2));
const batches = Array.from({ length: workerCount }, () => []);
diff --git a/scripts/linux/linuxdeploy-plugin-gstreamer.sh b/scripts/linux/linuxdeploy-plugin-gstreamer.sh
new file mode 100644
index 0000000..4fe4160
--- /dev/null
+++ b/scripts/linux/linuxdeploy-plugin-gstreamer.sh
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+# Slopus's linuxdeploy GStreamer plugin, used in place of the one the Tauri
+# CLI downloads (package-linux-app.sh puts it in Tauri's local tools folder).
+#
+# The upstream plugin copies every GStreamer plugin on the build machine into
+# the AppImage. On a typical Ubuntu that includes gst-libav, which drags in
+# FFmpeg, GPL encoders such as x265, ONNX Runtime and TensorFlow Lite. Slopus
+# ships no FFmpeg (AGENTS.md), so this copies an allowlist instead: what
+# WebKitGTK needs for media playback, Web Audio and WebCodecs, with hardware
+# H.264/HEVC/AV1 through VA-API and NVIDIA's driver (va, nvcodec) and
+# royalty-free VP8/VP9/AV1/Opus software codecs.
+#
+# It also removes NVIDIA cuBLAS, which linuxdeploy finds through
+# libslopfab.so's dependencies. The CUDA libraries belong to the user's CUDA
+# installation, as for the .deb, the .rpm and the Linux worker; bundled they
+# are over 500 MB and tied to the build machine's toolkit.
+#
+# Plugin API 0, as upstream: linuxdeploy runs it with --appdir and $LINUXDEPLOY.
+set -euo pipefail
+
+ALLOWED_PLUGINS=(
+ # Core, pipelines and type detection
+ coreelements app playback typefindfunctions autodetect gio pbtypes encoding
+ # Audio
+ audioconvert audioresample audiorate audioparsers volume interleave audiomixer
+ wavparse flac opus opusparse vorbis ogg mpg123 id3demux apetag pulseaudio
+ # Video
+ videoconvertscale videorate videofilter videoparsersbad codecalpha
+ codectimestamper opengl alpha
+ # Containers
+ isomp4 matroska
+ # Codecs: hardware through the system driver, royalty-free in software
+ va nvcodec vpx aom dav1d svtav1
+)
+
+# linuxdeploy finds these through libslopfab.so; the user's CUDA provides them.
+EXCLUDED_LIBRARIES=(libcublas.so* libcublasLt.so*)
+
+appdir=""
+while (($#)); do
+ case $1 in
+ --plugin-api-version) echo 0; exit 0 ;;
+ --appdir) appdir=$2; shift 2 ;;
+ --help) printf 'Usage: %s --appdir <AppDir>\n' "$0"; exit 0 ;;
+ *) printf 'Invalid argument: %s\n' "$1" >&2; exit 1 ;;
+ esac
+done
+[[ -n $appdir ]] || { printf 'Usage: %s --appdir <AppDir>\n' "$0" >&2; exit 1; }
+[[ -n ${LINUXDEPLOY:-} ]] || { echo 'Error: $LINUXDEPLOY not set' >&2; exit 3; }
+command -v patchelf >/dev/null || { echo 'Error: patchelf not found' >&2; exit 2; }
+
+arch_dir=/usr/lib/$(uname -m)-linux-gnu
+plugins_dir=${GSTREAMER_PLUGINS_DIR:-$arch_dir/gstreamer-1.0}
+helpers_dir=${GSTREAMER_HELPERS_DIR:-$arch_dir/gstreamer1.0/gstreamer-1.0}
+[[ -d $plugins_dir ]] || { echo "Error: could not find plugins directory: $plugins_dir" >&2; exit 1; }
+
+plugins_target="$appdir/usr/lib/gstreamer-1.0"
+helpers_target="$appdir/usr/lib/gstreamer1.0/gstreamer-1.0"
+mkdir -p "$plugins_target" "$helpers_target" "$appdir/apprun-hooks"
+
+for name in "${ALLOWED_PLUGINS[@]}"; do
+ plugin="$plugins_dir/libgst$name.so"
+ if [[ -f $plugin ]]; then
+ cp "$plugin" "$plugins_target/"
+ else
+ echo "Note: GStreamer plugin $name is not installed; skipping it."
+ fi
+done
+for helper in gst-plugin-scanner gst-ptp-helper; do
+ [[ -f $helpers_dir/$helper ]] && cp "$helpers_dir/$helper" "$helpers_target/"
+done
+
+# Deploy the plugins' own dependencies, then point them at the AppImage's libs.
+"$LINUXDEPLOY" --appdir "$appdir"
+for file in "$plugins_target"/*; do
+ patchelf --set-rpath '$ORIGIN/..:$ORIGIN' "$file"
+done
+for file in "$helpers_target"/*; do
+ patchelf --set-rpath '$ORIGIN/../..' "$file"
+done
+
+for pattern in "${EXCLUDED_LIBRARIES[@]}"; do
+ find "$appdir/usr/lib" -maxdepth 1 -name "$pattern" -print -delete
+done
+
+cat > "$appdir/apprun-hooks/linuxdeploy-plugin-gstreamer.sh" <<'EOF'
+#! /bin/bash
+
+export GST_REGISTRY_REUSE_PLUGIN_SCANNER="no"
+export GST_PLUGIN_SYSTEM_PATH_1_0="${APPDIR}/usr/lib/gstreamer-1.0"
+export GST_PLUGIN_PATH_1_0="${APPDIR}/usr/lib/gstreamer-1.0"
+
+export GST_PLUGIN_SCANNER_1_0="${APPDIR}/usr/lib/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner"
+export GST_PTP_HELPER_1_0="${APPDIR}/usr/lib/gstreamer1.0/gstreamer-1.0/gst-ptp-helper"
+EOF
diff --git a/scripts/package-linux-app.sh b/scripts/package-linux-app.sh
index ab0b926..9fd0ded 100644
--- a/scripts/package-linux-app.sh
+++ b/scripts/package-linux-app.sh
@@ -54,7 +54,8 @@ if [[ $(head -c 4 "$runtime" 2>/dev/null | od -An -c | tr -d ' ') != '177ELF' ]]
fail "$runtime is missing or a Git LFS pointer. Run git lfs pull."
fi
-cargo_version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version *= *"\(.*\)"/\1/p' "$root/src-tauri/Cargo.toml")
+# A Windows checkout has CRLF line endings; keep the \r out of the comparison.
+cargo_version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version *= *"\(.*\)"/\1/p' "$root/src-tauri/Cargo.toml" | tr -d '\r')
[[ $cargo_version == "$version" ]] || fail "version $version does not match src-tauri/Cargo.toml ($cargo_version)."
# The Windows build ran `npm run build` moments ago; refuse a missing frontend
@@ -64,7 +65,7 @@ asset=$(find "$root/dist/assets" -maxdepth 1 -name '*.js' -printf '%f\n' 2>/dev/
[[ -n $asset ]] || fail 'dist/assets has no JavaScript bundle.'
# The same CLI version as package-lock.json, installed once per version.
-cli_version=$(sed -n '/"node_modules\/@tauri-apps\/cli": {/,/}/s/.*"version": "\(.*\)".*/\1/p' "$root/package-lock.json" | head -n 1)
+cli_version=$(sed -n '/"node_modules\/@tauri-apps\/cli": {/,/}/s/.*"version": "\(.*\)".*/\1/p' "$root/package-lock.json" | tr -d '\r' | head -n 1)
[[ -n $cli_version ]] || fail 'could not read the @tauri-apps/cli version from package-lock.json.'
tools="$HOME/.cache/slopus/tauri-cli-$cli_version"
if [[ ! -x $tools/bin/cargo-tauri ]]; then
@@ -72,7 +73,10 @@ if [[ ! -x $tools/bin/cargo-tauri ]]; then
cargo install tauri-cli --version "=$cli_version" --locked --root "$tools"
fi
-config='{"build":{"beforeBuildCommand":""}}'
+# useLocalToolsDir keeps the AppImage tools in $target_dir/.tauri, where our
+# GStreamer plugin replaces the downloaded one (see the plugin for why).
+build_config='"build":{"beforeBuildCommand":""}'
+config="{$build_config,\"bundle\":{\"useLocalToolsDir\":true}}"
if [[ -n ${TAURI_SIGNING_PRIVATE_KEY:-} ]]; then
# release.cmd passes the Windows path of the key file through WSLENV.
if [[ $TAURI_SIGNING_PRIVATE_KEY =~ ^[A-Za-z]:[\\/] ]] && command -v wslpath >/dev/null; then
@@ -81,13 +85,15 @@ if [[ -n ${TAURI_SIGNING_PRIVATE_KEY:-} ]]; then
fi
signed=1
else
- config='{"build":{"beforeBuildCommand":""},"bundle":{"createUpdaterArtifacts":false}}'
+ config="{$build_config,\"bundle\":{\"useLocalToolsDir\":true,\"createUpdaterArtifacts\":false}}"
signed=0
fi
target_dir=${SLOPUS_LINUX_TARGET_DIR:-"$HOME/.cache/slopus/linux-app-target"}
bundle="$target_dir/release/bundle"
rm -rf -- "$bundle"
+mkdir -p "$target_dir/.tauri"
+install -m 0755 "$root/scripts/linux/linuxdeploy-plugin-gstreamer.sh" "$target_dir/.tauri/linuxdeploy-plugin-gstreamer.sh"
(
cd -- "$root"
# The AppImage tools are themselves AppImages; WSL has no FUSE to mount them.
@@ -105,6 +111,18 @@ rpm=$(pick rpm '*.rpm')
appimage=$(pick appimage '*.AppImage')
[[ -n $deb && -n $rpm && -n $appimage ]] || fail "expected a .deb, .rpm and AppImage under $bundle."
+# The AppImage carries its own libraries; make sure none of them is FFmpeg, a
+# GPL codec or the CUDA toolkit (see scripts/linux/linuxdeploy-plugin-gstreamer.sh).
+extract=$(mktemp -d /tmp/slopus-appimage.XXXXXXXX)
+trap 'rm -rf -- "$extract"' EXIT
+(cd -- "$extract" && "$appimage" --appimage-extract >/dev/null)
+forbidden=$(find "$extract/squashfs-root" -type f \( -name 'libavcodec.so*' -o -name 'libavformat.so*' \
+ -o -name 'libavutil.so*' -o -name 'libavfilter.so*' -o -name 'libavdevice.so*' -o -name 'libswscale.so*' \
+ -o -name 'libswresample.so*' -o -name 'libpostproc.so*' -o -name 'libx264*.so*' -o -name 'libx265*.so*' -o -name 'libgstlibav.so' \
+ -o -name 'libcublas*.so*' \) -printf '%f\n')
+[[ -z $forbidden ]] || fail "the AppImage bundles libraries it must not ship: $(echo $forbidden)"
+[[ -f $extract/squashfs-root/usr/lib/Slopus/libslopfab.so ]] || fail 'the AppImage is missing libslopfab.so.'
+
stem="Slopus-$version-linux-x64"
mkdir -p -- "$artifacts"
rm -f -- "$artifacts/$stem".{deb,rpm,AppImage,AppImage.sig}
diff --git a/scripts/package-linux-worker.sh b/scripts/package-linux-worker.sh
index 9326404..63f1478 100644
--- a/scripts/package-linux-worker.sh
+++ b/scripts/package-linux-worker.sh
@@ -42,7 +42,8 @@ target_dir=${SLOPUS_LINUX_TARGET_DIR:-"$HOME/.cache/slopus/linux-worker-target"}
CARGO_TARGET_DIR=$target_dir cargo build --release --locked \
--manifest-path "$root/src-tauri/Cargo.toml" -p slopus-worker
-cargo_version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version *= *"\(.*\)"/\1/p' "$root/src-tauri/Cargo.toml")
+# A Windows checkout has CRLF line endings; keep the \r out of the comparison.
+cargo_version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version *= *"\(.*\)"/\1/p' "$root/src-tauri/Cargo.toml" | tr -d '\r')
if [[ $cargo_version != "$version" ]]; then
printf 'package-linux-worker: version %s does not match src-tauri/Cargo.toml (%s).\n' "$version" "$cargo_version" >&2
exit 1
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 8134a1a..c44dec0 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -21,6 +21,17 @@ rust-version = "1.87"
name = "slopus_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
+[features]
+# The reference icon generator (scripts/generate-reference-icons.mjs) is a
+# development tool. Behind a feature, the Tauri CLI leaves it out of installers
+# and packages, where it would otherwise land on PATH as /usr/bin/reference_icons.
+reference-icon-tool = []
+
+[[bin]]
+name = "reference_icons"
+path = "src/bin/reference_icons.rs"
+required-features = ["reference-icon-tool"]
+
[build-dependencies]
tauri-build = { version = "2", features = [] }