gallery/harnesses/gtauri/scripts/cargo-shim
gmp e019a950b1 gtauri: Tauri v2 gallery harness WORKING on emulator
Chromium owns scroll/compositor/lazy-load/image-cache; Rust owns
scan/SQLite/thumbnail-decode behind a gallery:// custom protocol.

Hard-won gotchas (see in-code comments):
- Android: no native custom-scheme support → wry rewrites the URL to
  http://gallery.localhost/... (custom_protocol_workaround). The JS
  MUST request that form; the handler receives the reverted
  gallery://localhost/... and must strip the authority.
- tauri_build::build() in build.rs must run UNCONDITIONALLY (build
  scripts run on the host: a cfg(target_os) gate silently disables it,
  which skips the rustc-cfg=mobile emission → no mobile_entry_point →
  .so with no JNI symbols → UnsatisfiedLinkError).
- build.rs must list frontend files for rerun-if-changed (a dir-level
  directive only watches the dir mtime, not content edits) — the .so
  bakes the frontend at compile time and cargo otherwise ships stale
  UI with a 'successful' build.
- logcat drops ~75% of lines under load: use the file trace.
- fetch() is CORS-restricted (page origin http://tauri.localhost);
  <img> is not — add ACAO:* anyway.

Emulator (5853 real files): grid renders, lazy thumbs via
gallery:// with on-disk cache (87 files 35-72KB), FR log clean at
60Hz, viewer opens full-res with compositor-only pan/zoom. The single
'broken' cell is a 17-byte fake test JPEG (correct behavior).
2026-10-31 18:59:51 -04:00

77 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# cargo shim: intercept `cargo tauri android android-studio-script` (the
# hidden subcommand the tauri gradle plugin's rustBuild task runs) and
# reproduce its effect with a PLAIN cargo build.
#
# Why: the cargo-tauri CLI (every subcommand that builds a Rust interface)
# starts an inotify debouncer on Cargo.toml. This host's per-user inotify
# WATCH quota (65536) is exhausted by the user's standalone syncthing
# (65,482 watches), so inotify_add_watch → ENOSPC and the CLI dies before
# doing anything. Plain cargo build uses no inotify.
#
# android-studio-script's output (verified on the tttest build): the lib .so
# placed at gen/android/app/src/main/jniLibs/<abi-dir>/lib<lib>.so.
set -euo pipefail
REAL_CARGO="$HOME/.cargo/bin/cargo"
PROJ=/mnt/Backup/prog/android/gallery/harnesses/gtauri
NDK="$HOME/android-sdk/ndk/27.0.12077973"
if [ "${1:-}" = "tauri" ] && [ "${2:-}" = "android" ] && [ "${3:-}" = "android-studio-script" ]; then
shift 3
release="" ; target="x86_64"
while [ $# -gt 0 ]; do
case "$1" in
--release) release=1 ;;
--target) shift; target="${1:-x86_64}" ;;
esac
shift
done
case "$target" in
x86_64) TRIPLE=x86_64-linux-android; ABI_DIR=x86_64; CLANG=x86_64-linux-android24-clang ;;
aarch64) TRIPLE=aarch64-linux-android; ABI_DIR=arm64-v8a; CLANG=aarch64-linux-android24-clang ;;
armv7) TRIPLE=armv7-linux-androideabi; ABI_DIR=armeabi-v7a; CLANG=armv7a-linux-androideabi24-clang ;;
i686) TRIPLE=i686-linux-android; ABI_DIR=x86; CLANG=i686-linux-android24-clang ;;
*) echo "shim: unknown target $target" >&2; exit 1 ;;
esac
prof="debug"; [ -n "$release" ] && prof="release"
echo "gtauri shim: cargo build $TRIPLE $prof (bypassing cargo-tauri)"
# env var names are CARGO_TARGET_<UPPER_TRIPLE>_... with HYPHENS → UNDERSCORES
UPPER=$(echo "$TRIPLE" | tr 'a-z-' 'A-Z_')
# cc crate (libsqlite3-sys bundled, turbojpeg cmake) wants CC_<lower_triple>
LOWER=$(echo "$UPPER" | tr 'A-Z' 'a-z')
NDK_BIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
case "$target" in x86_64) ABI=x86_64 ;; aarch64) ABI=arm64-v8a ;; armv7) ABI=armeabi-v7a ;; i686) ABI=x86 ;; esac
CCNAME=$CLANG # any valid C compiler for the target; API level is moot for cc
env \
"CARGO_TARGET_${UPPER}_LINKER=$NDK_BIN/$CLANG" \
"CARGO_TARGET_${UPPER}_RUSTFLAGS=-Clink-arg=-landroid -Clink-arg=-llog -Clink-arg=-lOpenSLES" \
"CC_${LOWER}=$NDK_BIN/$CCNAME" \
"CXX_${LOWER}=$NDK_BIN/${CCNAME}++" \
"AR_${LOWER}=$NDK_BIN/llvm-ar" \
"CC=$NDK_BIN/$CCNAME" \
"CXX=$NDK_BIN/${CCNAME}++" \
"CMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake" \
"ANDROID_PLATFORM=android-26" \
"ANDROID_STL=c++_static" \
"ANDROID_ABI=$ABI" \
"TURBOJPEG_STATIC=1" \
"$REAL_CARGO" build --package gtauri --manifest-path "$PROJ/Cargo.toml" \
--target "$TRIPLE" --features "tauri/custom-protocol" --lib --"$prof"
SO="$PROJ/target/$TRIPLE/$prof/libgtauri_lib.so"
[ -f "$SO" ] || { echo "shim: $SO not produced" >&2; exit 1; }
DEST="$PROJ/gen/android/app/src/main/jniLibs/$ABI_DIR/libgtauri_lib.so"
mkdir -p "$(dirname "$DEST")"
# /mnt/Backup's stat identity is unreliable here (cp still reports
# "same file"), so just break any link and copy fresh:
rm -f "$DEST"
cp "$SO" "$DEST"
echo "gtauri shim: .so -> jniLibs/$ABI_DIR"
exit 0
fi
exec "$REAL_CARGO" "$@"