Files
obs-localvocal/flatpak/build.sh
Florent Poinsaut 0e150fa29c Add Flatpak packaging support (#297)
* Initial plan

* feat: add Flatpak packaging support for obs-localvocal

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>

* fix: add disable-submodules: true to CTranslate2 git source in Flatpak manifest

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>

* fix: explicitly set OPENBLAS_INCLUDE_DIR and OPENBLAS_LIBRARY for CTranslate2 in Flatpak manifest

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>

* fix: correct OPENBLAS_INCLUDE_DIR to include/openblas subdirectory for CTranslate2

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/e3f2f7ef-fbe0-4462-b494-7ec90d19173a

* fix(flatpak): set ACCELERATION env var for obs-localvocal cmake configure

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/be96d349-07f2-4bf2-b6eb-17e6981b2c41

* feat(flatpak): add build.sh to make ACCELERATION configurable at build time

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/1d2428e1-3f26-4138-9bbd-7b1980a798fc

* fix(flatpak/cmake): resolve nvidia build failure - skip OpenCL and use local source

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/de149655-15b1-442a-9a1b-d443ef035fc1

* fix(flatpak/build.sh): replace Python heredoc with pure awk shell substitution

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/8e3820a8-3cb7-41d9-9d3f-87d2fac050c6

* fix(flatpak): pre-populate corrosion source to fix network-blocked sandbox build

cmake/BuildWebVTT.cmake uses FetchContent to clone corrosion-rs/corrosion
at configure time. The Flatpak sandbox blocks network access, causing the
clone to fail with "Could not resolve host: github.com".

Fix: add corrosion v0.5 as a pre-downloaded manifest source (dest: corrosion-src)
so flatpak-builder fetches it before entering the sandbox, and point CMake's
FetchContent at the pre-populated directory via FETCHCONTENT_SOURCE_DIR_CORROSION.

Also quote the ACCELERATION variable comparisons in BuildWhispercpp.cmake
for safer string comparison style.

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/65942026-4cfd-4684-92be-626897d87509

* fix(flatpak): add Rust SDK extension and vendor cargo dependencies for offline build

After the corrosion network-clone fix, the next error was:
  rustc not found in PATH or /root/.cargo/bin

The Flatpak sandbox has no network access, so the Rust toolchain must be
provided via an SDK extension, and all cargo crate dependencies must be
pre-downloaded by flatpak-builder (before the sandbox starts).

Changes:
- flatpak/com.obsproject.Studio.Plugin.LocalVocal.yaml:
  * Add sdk-extensions: org.freedesktop.Sdk.Extension.rust-stable//24.08
    (KDE SDK 6.8 is based on freedesktop SDK 24.08; this provides rustc/cargo
    at /usr/lib/sdk/rust-stable/bin)
  * Add append-path for the Rust bin dir to obs-localvocal build-options
  * Add CARGO_HOME=/run/build/obs-localvocal/cargo to env so cargo reads the
    vendor config and locates the pre-populated crate archives
  * Add inline source creating cargo/config.toml that redirects crates-io to
    the pre-vendored directory (absolute path, avoids network)
  * Reference new cargo-sources.json for the 67 crate archives

- flatpak/cargo-sources.json (new):
  Generated by flatpak-cargo-generator from
  deps/c-webvtt-in-video-stream/Cargo.lock.
  134 entries (67 archives + 67 .cargo-checksum.json inlines).
  The auto-generated cargo/config entry is removed since the manifest
  provides a correct config.toml with an absolute vendor path instead.

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/a70f729f-6724-4ef8-9aab-3a54344fda02

* fix(flatpak): use base-extensions to mount rust-stable at branch 24.08

sdk-extensions always resolves extension branches from the SDK branch (6.8),
so org.freedesktop.Sdk.Extension.rust-stable//24.08 was turned into
org.freedesktop.Sdk.Extension.rust-stable//24.08/x86_64/6.8 - a ref that
does not exist.

Replace sdk-extensions with base/base-version/base-extensions:
  base: org.freedesktop.Sdk
  base-version: "24.08"
  base-extensions:
    - org.freedesktop.Sdk.Extension.rust-stable

base-extensions resolves extension branches from base-version (24.08),
matching the only existing branch of the rust-stable extension.
KDE SDK 6.8 is itself built on org.freedesktop.Sdk//24.08, so using
that runtime as the base is fully compatible.

Local prerequisites:
  flatpak install flathub org.freedesktop.Sdk//24.08
  flatpak install flathub org.freedesktop.Sdk.Extension.rust-stable//24.08

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/a0eabff0-15c4-45be-b38b-0ada230bc17e

* fix(flatpak): install Rust toolchain as a module to avoid SDK branch mismatch

Remove base/base-version/base-extensions (the previous fix that caused
app/org.freedesktop.Sdk/x86_64/24.08 not installed because `base` resolves
refs as apps, not runtimes).

The underlying problem is that sdk-extensions always inherits the SDK branch
(6.8), but org.freedesktop.Sdk.Extension.rust-stable only exists at branch
24.08. There is no standard flatpak-builder mechanism to override the branch
for sdk-extensions.

Add a rust-toolchain module that installs Rust 1.89.0 directly to
/usr/lib/sdk/rust-stable/ using the same source (URL + SHA256) as
org.freedesktop.Sdk.Extension.rust-stable//24.08 on Flathub.

Benefits:
- Keeps sdk: org.kde.Sdk//6.8 (Qt6 headers remain available for ENABLE_QT=ON)
- No change needed to obs-localvocal build-options (append-path and CARGO_HOME
  continue to work as-is)
- Files installed to /usr/ are build-environment-only, NOT exported in the
  final extension package (prefix: /app/plugins/LocalVocal/)
- No manual flatpak install of any extension required before building

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/ecb4889b-352f-44a8-a681-0dc164fc4493

* fix(flatpak): install Rust toolchain under writable /app prefix, not read-only /usr

In a build-extension: true flatpak sandbox, /usr/ is the SDK mount and
is read-only.  The previous iteration used --prefix=/usr/lib/sdk/rust-stable
which caused:

  touch: cannot touch '/usr/lib/sdk/rust-stable/lib/rust-install-probe':
  Read-only file system

Fix by installing to /app/plugins/LocalVocal/rust-toolchain instead, which
is inside the extension's writable overlay.  Three changes:

1. rust-toolchain module: change --prefix to /app/plugins/LocalVocal/rust-toolchain
2. obs-localvocal build-options: update append-path accordingly
3. cleanup: add /rust-toolchain so the ~300 MB toolchain is stripped from
   the final extension package (cleanup runs after all modules are built,
   so rustc/cargo are available during the obs-localvocal build)

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/f844f598-0354-4a77-9ec7-3334d1485cd9

* fix(flatpak): add opencl-headers module and pre-bundle whispercpp prebuilt binary

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/b191ba1a-bad6-47a4-9b34-2fc1a738d919

* fix(flatpak): replace USE_SYSTEM_ONNXRUNTIME with FetchContent pre-bundle

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/23e8f01e-2866-404d-a181-d195b86406cf

* fix(flatpak): bypass ExternalProject git-clone failures for CTranslate2 and SentencePiece

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/eee2c356-902f-405a-b4c6-a976caa6c1bc

* fix(flatpak): fix post-install cpu_features path for builddir:true layout

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/fc306650-14f7-4a09-abc5-a84e083d6cda

* fix(flatpak/patches): fix malformed patch hunk headers — wrong line numbers and new-line count

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/06b4f42a-13b0-4d97-bc72-05737c028b7f

* fix(flatpak): prepend /app/lib to LD_LIBRARY_PATH so uic can find libicui18n.so.77

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/f3efa268-b29a-4ba5-9aea-1e1d816d8933

* fix(flatpak): add cmake-level uic wrapper to robustly fix libicui18n.so.77 error

cmake AutoUIC spawns /app/libexec/qt/uic as a child of ninja via
`cmake -E cmake_autogen`.  LD_LIBRARY_PATH set by flatpak-builder's
prepend-ld-library-path may not propagate reliably through that
subprocess chain.

Add a thin uic-wrapper shell script module that hard-codes /app/lib
into LD_LIBRARY_PATH before exec-ing the real uic binary.  cmake 3.14+
respects CMAKE_AUTOUIC_EXECUTABLE to override uic discovery; point it
at the wrapper so AutoUIC always uses the wrapper regardless of how
flatpak-builder sets up the environment.

Keep prepend-ld-library-path: /app/lib as belt-and-suspenders.
Add /uic-wrapper to cleanup so it is not shipped in the final package.

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/1af4d028-aa0b-4b05-a94d-90c8d636241b

* fix(flatpak): stage ICU 77 libraries at build time so uic-wrapper finds them

Root cause: /app/lib does NOT contain libicui18n.so.77 in the extension
build sandbox (OBS Studio may store ICU elsewhere, or the path is not
in the default dynamic-linker search path). Setting LD_LIBRARY_PATH to
/app/lib therefore never helped.

New approach in the qt-uic-wrapper module:

  1. At module-build time, locate the three ICU 77 .so files by checking
     six common installation directories (fast path) and falling back to
     a depth-limited `find` search.  Fail loudly if any library cannot
     be located so the problem is immediately visible.

  2. Copy the found libraries (dereferencing symlinks with cp -L) into
     ${FLATPAK_DEST}/icu-for-uic/ — a writable path inside our extension
     prefix that is guaranteed to exist when obs-localvocal later builds.

  3. Rewrite the wrapper to use `export LD_LIBRARY_PATH` (not `exec env
     VAR=...`) and point at /app/plugins/LocalVocal/icu-for-uic.

Remove the now-unnecessary prepend-ld-library-path: /app/lib from
obs-localvocal build-options; add /icu-for-uic to cleanup.

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/c0ad4a75-639b-46db-a6fe-97f8ca13bc67

* fix(flatpak): use SDK's uic when available; ICU shim uses any version as fallback

The previous attempt staged libicui18n.so.77 copies but find returned nothing
because the library genuinely does not exist anywhere in the extension build
sandbox. Root cause: OBS Studio's uic requires libicui18n.so.77, but the
extension sandbox only mounts the SDK (/usr), not the OBS app's private ICU.

New strategy in qt-uic-wrapper:

  Step 1 (primary): locate the KDE Platform SDK's own uic binary in /usr.
  The SDK ships Qt 6.8 including uic, linked against the SDK's ICU. It has
  no unsatisfied dependencies. Common paths checked first (fast), then a
  broader find /usr fallback. If found, write a one-line wrapper with no ICU
  setup needed at all.

  Step 2 (fallback, only if no SDK uic exists): use OBS Studio's uic at
  /app/libexec/qt/uic with an ICU shim. Instead of searching only for
  .so.77, search for ANY version of libicuXXX in the SDK (/usr), stage it
  as .so.77, and keep a copy under the original name so intra-ICU DT_NEEDED
  entries (e.g. libicuuc.so.74) also resolve from our staging dir.

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/502a8cf1-54ef-466d-b500-a1642ca1e11f

* fix(flatpak): always set LD_LIBRARY_PATH=/app/lib in uic wrapper; fix ICU .so.77.1 detection

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/ff0038ad-dbc2-4c9b-acff-f995229274e6

* fix(flatpak): use for-loop glob for ICU detection; guard uic path against shell injection

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/ff0038ad-dbc2-4c9b-acff-f995229274e6

* Fix flatpak uic: lazy-stage ICU 77 in wrapper, no /app/lib in LD_LIBRARY_PATH

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/5e50645b-1a3f-4437-9a15-b9666fb90e5d

* flatpak: uic-wrapper searches SDK /usr/lib* paths first for ICU 77

Co-authored-by: FlorentPoinsaut <1256948+FlorentPoinsaut@users.noreply.github.com>
Agent-Logs-Url: https://github.com/FlorentPoinsaut/obs-localvocal/sessions/9665b858-6bf0-4b37-b496-1de0faff41b7

* Fix ICU compatible version + doc

* Use org.freedesktop.Sdk//25.08

* Use local dir for localvocal in flatpak and remove cmake patches

* Get dep with archive in flatpak

* Add DICU_HASH_OVERRIDE

* Fix cmake format

* Fix bis cmake format

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-03-26 18:02:11 +00:00

81 lines
2.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Build the obs-localvocal Flatpak extension.
#
# Usage:
# [ACCELERATION=<value>] ./flatpak/build.sh [flatpak-builder options] <build-dir>
#
# ACCELERATION controls the GPU/CPU backend compiled into the plugin.
# Allowed values (default: generic):
# generic portable CPU-only build (OpenBLAS)
# nvidia CUDA-accelerated build
# amd ROCm/HIP-accelerated build
#
# Examples:
# ./flatpak/build.sh build-dir
# ACCELERATION=nvidia ./flatpak/build.sh --install build-dir
# ACCELERATION=amd ./flatpak/build.sh --repo=repo build-dir
set -euo pipefail
ACCELERATION="${ACCELERATION:-generic}"
case "${ACCELERATION}" in
generic | nvidia | amd) ;;
*)
printf 'Error: ACCELERATION="%s" is invalid. Allowed values: generic, nvidia, amd.\n' \
"${ACCELERATION}" >&2
exit 1
;;
esac
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
MANIFEST="${SCRIPT_DIR}/com.obsproject.Studio.Plugin.LocalVocal.yaml"
# Create a temporary directory and ensure it is removed on exit
WORK_DIR="$(mktemp -d)"
trap 'rm -rf "${WORK_DIR}"' EXIT
# Produce a patched copy of the manifest with the requested ACCELERATION value.
# Two substitutions are needed:
# 1. build-options.env entry: ACCELERATION: generic
# 2. CMake cache variable: -DACCELERATION=generic
PATCHED="${WORK_DIR}/$(basename "${MANIFEST}")"
sed \
-e "s/ACCELERATION: generic/ACCELERATION: ${ACCELERATION}/" \
-e "s/-DACCELERATION=generic/-DACCELERATION=${ACCELERATION}/" \
"${MANIFEST}" > "${PATCHED}"
# Replace the upstream obs-localvocal git source with the local repository so
# that cmake improvements in this fork (e.g. USE_SYSTEM_WHISPERCPP support,
# the conditional OpenCL search for nvidia) are applied during the build.
# The awk script detects the 6-space YAML list item whose next line is the
# locaal-ai git URL, skips all lines in that item, and emits a type:dir entry
# in its place. Every other line is passed through unchanged.
awk -v repo_dir="${REPO_DIR}" '
in_skip && /^ - / {
print " - type: dir"
print " path: " repo_dir
in_skip = 0
}
in_skip { next }
/^ - type: git$/ { pending = $0; next }
pending && /^ url: https:\/\/github\.com\/locaal-ai\/obs-localvocal\.git$/ {
in_skip = 1; pending = ""; next
}
pending { print pending; pending = "" }
{ print }
END {
if (in_skip) {
print " - type: dir"
print " path: " repo_dir
}
}
' "${PATCHED}" > "${PATCHED}.tmp" && mv "${PATCHED}.tmp" "${PATCHED}"
# The manifest references the metainfo XML via a relative path; copy it so
# flatpak-builder can find it relative to the patched manifest location.
cp "${SCRIPT_DIR}/com.obsproject.Studio.Plugin.LocalVocal.metainfo.xml" "${WORK_DIR}/"
exec flatpak-builder "$@" "${PATCHED}"