Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

fix(linux): install app-private libs to /usr/lib/Handy (#1639) (#1727)

CJ Paisd1180c42ceb3
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 84c3810f..d93cfccd 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -388,12 +388,13 @@ jobs:
cp -L "$f" "$f.real" && mv "$f.real" "$f"
fi
done
- # Add the shared libs to the deb package under /usr/lib
+ # Ship ORT in Handy's private lib dir under its SONAME only — the one
+ # name the loader resolves (handy has NEEDED libonnxruntime.so.1).
+ # Shipping the .so/.so.x.y.z aliases too would triplicate the lib as
+ # real files and draw ldconfig warnings (issue #1639).
# deb.files key = destination in package, value = source on disk
- jq --arg so "$ORT_DIR/lib/libonnxruntime.so" \
- --arg so1 "$ORT_DIR/lib/libonnxruntime.so.1" \
- --arg sov "$ORT_DIR/lib/libonnxruntime.so.1.24.2" \
- '.bundle.linux.deb.files["/usr/lib/libonnxruntime.so"] = $so | .bundle.linux.deb.files["/usr/lib/libonnxruntime.so.1"] = $so1 | .bundle.linux.deb.files["/usr/lib/libonnxruntime.so.1.24.2"] = $sov' \
+ jq --arg so1 "$ORT_DIR/lib/libonnxruntime.so.1" \
+ '.bundle.linux.deb.files["/usr/lib/Handy/libonnxruntime.so.1"] = $so1' \
src-tauri/tauri.conf.json > tmp.json && mv tmp.json src-tauri/tauri.conf.json
# Windows x64 links a BASELINE ONNX Runtime dynamically instead of statically
@@ -659,7 +660,7 @@ jobs:
# Run under a virtual X server: handy initializes GTK on startup even
# on the headless --list-devices path, which fails without a display.
HANDY_NO_GTK_LAYER_SHELL=1 \
- LD_LIBRARY_PATH="${root}/usr/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" \
+ LD_LIBRARY_PATH="${root}/usr/lib/Handy:${root}/usr/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" \
xvfb-run -a "${root}/usr/bin/handy" --list-devices >/tmp/handy-package-smoke.log
echo "${label} --list-devices smoke passed"
}
@@ -670,10 +671,18 @@ jobs:
listing="$(mktemp)"
dpkg-deb -c "$deb" > "$listing"
require_pattern "$listing" 'usr/bin/handy$' "handy binary"
- require_pattern "$listing" 'usr/lib/libtranscribe\.so' "transcribe runtime library"
- require_pattern "$listing" 'usr/lib/libggml-cpu.*\.so' "ggml CPU backend module"
+ require_pattern "$listing" 'usr/lib/Handy/libtranscribe\.so\.[0-9]+$' "transcribe runtime library (SONAME)"
+ require_pattern "$listing" 'usr/lib/Handy/libggml-cpu.*\.so' "ggml CPU backend module"
if [[ "${{ inputs.platform }}" == *"ubuntu-22.04"* && "${{ inputs.target }}" == "x86_64-unknown-linux-gnu" ]]; then
- require_pattern "$listing" 'usr/lib/libonnxruntime\.so' "ONNX Runtime library"
+ require_pattern "$listing" 'usr/lib/Handy/libonnxruntime\.so\.[0-9]+$' "ONNX Runtime library (SONAME)"
+ fi
+ # Handy's libs must stay out of the ldconfig-scanned /usr/lib
+ # (issue #1639): app-private libs belong in /usr/lib/Handy only.
+ # `[^/]+` excludes the Handy/ subdir, so only direct hits match.
+ if grep -Eq 'usr/lib/[^/]+\.so' "$listing"; then
+ echo "ERROR: libraries installed directly into /usr/lib (issue #1639):" >&2
+ grep -E 'usr/lib/[^/]+\.so' "$listing" >&2
+ exit 1
fi
root="$(mktemp -d)"
dpkg-deb -x "$deb" "$root"
@@ -692,8 +701,14 @@ jobs:
listing="$(mktemp)"
rpm -qpl "$rpm_pkg" > "$listing"
require_pattern "$listing" '/usr/bin/handy$' "handy binary"
- require_pattern "$listing" '/usr/lib/libtranscribe\.so' "transcribe runtime library"
- require_pattern "$listing" '/usr/lib/libggml-cpu.*\.so' "ggml CPU backend module"
+ require_pattern "$listing" '/usr/lib/Handy/libtranscribe\.so\.[0-9]+$' "transcribe runtime library (SONAME)"
+ require_pattern "$listing" '/usr/lib/Handy/libggml-cpu.*\.so' "ggml CPU backend module"
+ # Same /usr/lib pollution guard as the deb audit (issue #1639).
+ if grep -Eq 'usr/lib/[^/]+\.so' "$listing"; then
+ echo "ERROR: libraries installed directly into /usr/lib (issue #1639):" >&2
+ grep -E 'usr/lib/[^/]+\.so' "$listing" >&2
+ exit 1
+ fi
rm -f "$listing"
done
fi
@@ -708,7 +723,13 @@ jobs:
cd "$workdir"
./Handy.AppImage --appimage-extract >/dev/null
require_path "squashfs-root/usr/bin/handy" "AppImage handy binary"
- require_path "squashfs-root/usr/lib/libtranscribe.so" "AppImage transcribe runtime library"
+ # The SONAME (libtranscribe.so.N) is the name the loader
+ # resolves; the bare .so alias may or may not be present.
+ if ! find "squashfs-root/usr/lib" -name 'libtranscribe.so*' | grep -q .; then
+ echo "ERROR: missing AppImage transcribe runtime library" >&2
+ find "squashfs-root/usr/lib" -maxdepth 1 -type f >&2
+ exit 1
+ fi
if ! find "squashfs-root/usr/lib" -name 'libggml-cpu*.so*' | grep -q .; then
echo "ERROR: missing AppImage ggml CPU backend module" >&2
find "squashfs-root/usr/lib" -maxdepth 1 -type f >&2
diff --git a/BUILD.md b/BUILD.md
index f1bb8056..e3698dcc 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -130,15 +130,16 @@ sudo cp usr/bin/handy /usr/bin/
sudo cp -a usr/lib/. /usr/lib/
sudo cp -r usr/share/icons/hicolor/* /usr/share/icons/hicolor/
sudo cp usr/share/applications/Handy.desktop /usr/share/applications/
-sudo ldconfig
```
+The runtime libraries live in the app-private `/usr/lib/Handy/` (on the binary's rpath), so no `ldconfig` step is needed.
+
After subsequent rebuilds, copy the binary and any refreshed runtime libraries:
```bash
sudo cp src-tauri/target/release/handy /usr/bin/
-sudo cp -a src-tauri/transcribe-libs/. /usr/lib/
-sudo ldconfig
+sudo mkdir -p /usr/lib/Handy
+sudo cp -a src-tauri/transcribe-libs/. /usr/lib/Handy/
```
Resources only need re-copying if they change upstream (new icons, sounds, models, etc.).
diff --git a/src-tauri/.gitignore b/src-tauri/.gitignore
index ec2ffc6b..c5fc3d19 100644
--- a/src-tauri/.gitignore
+++ b/src-tauri/.gitignore
@@ -8,5 +8,6 @@
# Staged by build.rs: transcribe-cpp shared runtime libraries (Windows DLLs /
# Linux .so), bundled next to the executable — to the install root via
-# tauri.windows.conf.json on Windows, into /usr/lib via tauri.conf.json on Linux.
+# tauri.windows.conf.json on Windows, into /usr/lib/Handy (deb/rpm) via
+# tauri.conf.json on Linux.
/transcribe-libs/
diff --git a/src-tauri/build.rs b/src-tauri/build.rs
index 66e209d9..edcb0844 100644
--- a/src-tauri/build.rs
+++ b/src-tauri/build.rs
@@ -7,13 +7,16 @@ fn main() {
// Linux ships transcribe-cpp as a shared libtranscribe + loadable ggml
// backend modules (the `dynamic-backends` posture in Cargo.toml). Bake an
// $ORIGIN-relative rpath into the `handy` binary so it finds libtranscribe
- // next to it in the package — AppImage `usr/bin/handy` -> `usr/lib`, and
- // deb/rpm `/usr/bin/handy` -> `/usr/lib`. transcribe's
+ // next to it in the package — deb/rpm install into the app-private
+ // `/usr/lib/Handy` (the dir tauri already uses for resources; keeps
+ // Handy's libs out of the ldconfig-scanned `/usr/lib`, issue #1639) while
+ // the AppImage keeps them in `usr/lib` (linuxdeploy's layout), hence both
+ // entries. transcribe's
// init_backends_default() then loads the ggml modules co-located there.
// (Windows resolves DLLs from the exe directory, so it needs no rpath;
// macOS links transcribe-cpp statically via the `metal` feature.)
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux") {
- println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib");
+ println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib/Handy:$ORIGIN/../lib");
}
// Stage transcribe-cpp's shared runtime libraries (and the dlopen'd ggml
@@ -157,8 +160,8 @@ fn stage_onnxruntime_dll() {
/// ggml modules) may be the same dir — the `BTreeSet` below dedups them.
///
/// Where the staged dir lands: Windows bundles it beside `handy.exe` (DLLs resolve
-/// from the exe dir); Linux maps it into `/usr/lib`, on the binary's
-/// `$ORIGIN/../lib` rpath.
+/// from the exe dir); Linux deb/rpm map it into the app-private `/usr/lib/Handy`
+/// and the AppImage into `usr/lib`, both on the binary's rpath.
fn stage_transcribe_runtime_libs() {
use std::collections::BTreeSet;
use std::path::PathBuf;
@@ -190,7 +193,9 @@ fn stage_transcribe_runtime_libs() {
let _ = std::fs::remove_dir_all(&dest);
std::fs::create_dir_all(&dest).expect("create transcribe-libs staging dir");
- let mut copied = 0usize;
+ // Collect every candidate library name first (across both dirs) so the
+ // pruning below can see each lib's whole symlink family at once.
+ let mut libs: std::collections::BTreeMap<String, PathBuf> = Default::default();
for dir in &dirs {
println!("cargo:rerun-if-changed={}", dir.display());
for entry in std::fs::read_dir(dir)
@@ -200,21 +205,50 @@ fn stage_transcribe_runtime_libs() {
let src = entry.path();
let name = src.file_name().and_then(|s| s.to_str()).unwrap_or("");
// Match by NAME, not extension: Linux versions its libs
- // (libtranscribe.so.0, .so.0.0.7) and the loader needs the SONAME, so
- // an extension-only filter would copy just the bare dev symlink and
- // ship a broken package. `fs::copy` dereferences the version symlinks
- // into real files.
+ // (libtranscribe.so.0, .so.0.1.3) and the loader needs the SONAME, so
+ // an extension-only filter would miss the versioned names entirely.
let is_lib = name.ends_with(".dll")
|| name.ends_with(".dylib")
|| name.ends_with(".so")
|| name.contains(".so.");
if is_lib {
- std::fs::copy(&src, dest.join(name))
- .unwrap_or_else(|e| panic!("copy {}: {e}", src.display()));
- copied += 1;
+ libs.insert(name.to_string(), src);
+ }
+ }
+ }
+
+ // A Linux install dir carries each lib as a symlink chain (libfoo.so ->
+ // libfoo.so.0 -> libfoo.so.0.1.3), and tauri's deb/rpm bundlers flatten
+ // symlinks into real files — staging every name would triplicate each lib
+ // on disk and draw "not a symbolic link" warnings from ldconfig (issue
+ // #1639). Only one name per lib is ever resolved at runtime: the SONAME
+ // (`libfoo.so.N`) for the NEEDED core libs, and the bare unversioned name
+ // for the dlopen'd ggml backend modules. Stage exactly that name;
+ // `fs::copy` dereferences the symlink so the staged file is the real
+ // library.
+ let mut best: std::collections::BTreeMap<&str, (&str, &PathBuf, usize)> = Default::default();
+ for (name, src) in &libs {
+ let (stem, rank) = match split_versioned_so(name) {
+ // Windows/macOS names (.dll/.dylib) are unversioned: keep as-is.
+ None => (name.as_str(), 0),
+ // Prefer the SONAME form (exactly one numeric suffix), then the
+ // bare `.so`; fully-versioned names only as a last resort.
+ Some((stem, depth)) => (stem, if depth == 1 { 0 } else { depth + 1 }),
+ };
+ match best.get(stem) {
+ Some(&(_, _, existing)) if existing <= rank => {}
+ _ => {
+ best.insert(stem, (name, src, rank));
}
}
}
+
+ let mut copied = 0usize;
+ for &(name, src, _) in best.values() {
+ std::fs::copy(src, dest.join(name))
+ .unwrap_or_else(|e| panic!("copy {}: {e}", src.display()));
+ copied += 1;
+ }
if copied == 0 {
panic!(
"no transcribe-cpp runtime libraries found under {dirs:?}; a shared / \
@@ -225,6 +259,23 @@ fn stage_transcribe_runtime_libs() {
println!("cargo:warning=Staged {copied} transcribe-cpp runtime library file(s)");
}
+/// Split a versioned ELF shared-library name into (stem, version depth):
+/// `libfoo.so` -> ("libfoo", 0), `libfoo.so.0` -> ("libfoo", 1),
+/// `libfoo.so.0.1.3` -> ("libfoo", 3). Returns None for names that aren't a
+/// `.so` optionally followed by dot-separated numeric components.
+fn split_versioned_so(name: &str) -> Option<(&str, usize)> {
+ let idx = name.find(".so")?;
+ let (stem, rest) = (&name[..idx], &name[idx + 3..]);
+ if rest.is_empty() {
+ return Some((stem, 0));
+ }
+ let comps: Vec<&str> = rest.strip_prefix('.')?.split('.').collect();
+ comps
+ .iter()
+ .all(|c| !c.is_empty() && c.bytes().all(|b| b.is_ascii_digit()))
+ .then_some((stem, comps.len()))
+}
+
/// Generate tray menu translations from frontend locale files.
///
/// Source of truth: src/i18n/locales/*/translation.json
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 33105dd7..adddea81 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -47,7 +47,7 @@
"deb": {
"depends": ["libgtk-layer-shell0", "libopenblas0"],
"files": {
- "/usr/lib": "transcribe-libs"
+ "/usr/lib/Handy": "transcribe-libs"
}
},
"rpm": {
@@ -59,7 +59,7 @@
"type": "none"
},
"files": {
- "/usr/lib": "transcribe-libs"
+ "/usr/lib/Handy": "transcribe-libs"
}
},
"appimage": {