From 7e2d13b64183fac248a61293431a9f9721852f48 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Mon, 26 Oct 2026 12:45:00 -0400 Subject: [PATCH] fix(fex): x86 programs use DroidDeck's own FEX build, kept to the catalog's version --- .../droiddeck/launcher/FrontEndActivity.kt | 2 +- .../droiddeck/launcher/session/FexCatalog.kt | 4 +- .../launcher/session/SessionFiles.kt | 1 + .../launcher/session/SessionService.kt | 2 +- .../overlay/usr/local/bin/droiddeck-fex | 17 ++++ .../usr/local/bin/droiddeck-fex-update | 81 +++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-steam-x64 | 76 +---------------- tools/tests/test_droiddeck_fex.py | 33 ++++++++ tools/tests/test_fex_install.py | 2 +- tools/tests/test_fex_select.py | 6 +- 10 files changed, 142 insertions(+), 82 deletions(-) create mode 100755 tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 8bf9166f0c..a80e3c5d61 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -2124,7 +2124,7 @@ class FrontEndActivity : ComponentActivity() { val scanGeneration = ++libraryScanGeneration val artRefreshesAtStart = HashMap(steamArtRefreshes) if (shortcutPicker) shortcutLibraryScanning = true - if (SessionPrefs.steamClientArch(this) == "x86_64" && !OfflineMode.enabled(this)) { + if (!OfflineMode.enabled(this)) { Thread({ com.droiddeck.launcher.session.FexCatalog.refresh(this) }, "fex-catalog").start() } Thread({ diff --git a/app/src/main/java/com/droiddeck/launcher/session/FexCatalog.kt b/app/src/main/java/com/droiddeck/launcher/session/FexCatalog.kt index 73f42cb141..92cd7652da 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/FexCatalog.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/FexCatalog.kt @@ -8,7 +8,7 @@ import org.json.JSONObject import java.io.File /** - * The FEX build DroidDeck-Components' fex.json names for the x86-64 client. A session uses the last copy read. + * The FEX build DroidDeck-Components' fex.json names for x86 programs. A session uses the last copy read. * Components' build-fex.yml replaces the archive on its single `fex` release and records the build's version; * a release per build (fex-2610-r5) is still read. */ @@ -62,7 +62,7 @@ object FexCatalog { return build } - /** For droiddeck-steam-x64: the build and every source its archive may come from (it checks the sha256). */ + /** For droiddeck-fex-update: the build and every source its archive may come from (it checks the sha256). */ fun environment(build: Build, sources: List = DownloadSource.candidates(build.url)): List = listOf( "BL_FEX_TAG=${build.tag}", "BL_FEX_SHA256=${build.sha256}", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 0e10fca293..d9c59b1b88 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -81,6 +81,7 @@ object SessionFiles { "usr/local/bin/droiddeck-steam-games" to "usr/local/bin/droiddeck-steam-games", "usr/local/bin/droiddeck-pad-defaults" to "usr/local/bin/droiddeck-pad-defaults", "usr/local/bin/droiddeck-steam-x64" to "usr/local/bin/droiddeck-steam-x64", + "usr/local/bin/droiddeck-fex-update" to "usr/local/bin/droiddeck-fex-update", "usr/local/bin/droiddeck-steamrt-shim" to "usr/local/bin/droiddeck-steamrt-shim", "usr/local/bin/droiddeck-x64-arm-proton" to "usr/local/bin/droiddeck-x64-arm-proton", "usr/local/bin/droiddeck-x64-arm-webhelper" to "usr/local/bin/droiddeck-x64-arm-webhelper", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index b6f35f96a1..c85f11bbaf 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -777,8 +777,8 @@ class SessionService : Service() { SessionArtifacts.recordClient(it, arch) SessionArtifacts.markSteamLogs(it, File(SessionPrefs.steamRoot(this, arch), "logs")) } - if (arch == "x86_64") FexCatalog.cached(this)?.let { guest.addAll(FexCatalog.environment(it)) } } + FexCatalog.cached(this)?.let { guest.addAll(FexCatalog.environment(it)) } if (SessionState.mode == MODE_STEAM) { guest.add("BL_GAMESCOPE_STRETCH_16X9=" + (if (SessionPrefs.stretch16x9(this)) "1" else "0")) } diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex index 6ca792143d..ad4232a350 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex @@ -27,6 +27,8 @@ PRELOADS = "/usr/local/lib/droiddeck-fex" URUNTIME = "/usr/local/lib/droiddeck/uruntime" HOST_PRELOAD = "/etc/ld.so.preload" FEX_APPID = "3127680" +OWN_FEX = "/usr/local" +OWN_FEX_TAG = os.path.join(OWN_FEX, "share", "fex-emu", ".droiddeck-tag") SNIPER_APPID = "1628350" SLR4_APPID = "4183110" INSTALL_DIRS = {FEX_APPID: "FEX-Emu", SNIPER_APPID: "SteamLinuxRuntime_sniper", SLR4_APPID: "SteamLinuxRuntime_4"} @@ -152,8 +154,21 @@ def first_dir(prefix, candidates): return None +def update_own_fex(): + wanted = os.environ.get("BL_FEX_TAG") + if not wanted: + return + if (read_text(OWN_FEX_TAG) or "").strip() == wanted and os.access(os.path.join(OWN_FEX, "bin", "FEX"), os.X_OK): + return + say("installing DroidDeck's FEX build %s" % wanted) + if subprocess.call([os.path.join(BIN_DIR, "droiddeck-fex-update")], stdout=sys.stderr) != 0: + say("DroidDeck's FEX build %s did not install; using the FEX already here" % wanted) + + def fex_install(): prefixes = [] + if os.path.isfile(OWN_FEX_TAG): + prefixes.append((OWN_FEX, False)) tool = app_dir(FEX_APPID) if tool: prefixes += [(os.path.join(tool, sub), True) for sub in ("usr", "", "files/usr", "files")] @@ -445,6 +460,7 @@ def describe(fex, platform, graphics=None): def prepare(app=SNIPER_APPID): with locked(): + update_own_fex() fex = fex_install() platform = runtime_platform(app) status = describe(fex, platform) @@ -730,6 +746,7 @@ def extracted(): def want_fex(): with locked(): + update_own_fex() status = describe(fex_install(), runtime_platform(), graphics_platform()) if not status["ready"]: request_install() diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update new file mode 100755 index 0000000000..33346cfbb6 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update @@ -0,0 +1,81 @@ +#!/bin/bash +FEX_TAG=fex-2610-r5 +FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4 +FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst + +# Whether every program in the FEX tree at $1 finds its libraries (r4 did not without libxxhash). +fex_loads() { + local b out + for b in FEX FEXServer unsquashfs; do + out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue + echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2 + return 1 + done +} + +# Installs one FEX build only once its archive matches the sha256 and it loads. The files it replaces are kept +# until the installed copy loads too, and put back otherwise; the tag is written last. +fex_install() { + local tag=$1 sha=$2 urls=$3 dst=/ tmp u f + tmp=$(mktemp -d) + for u in $urls; do + curl -fsSL --retry 2 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break + rm -f "$tmp/fex.tzst" + done + if [ ! -s "$tmp/fex.tzst" ]; then + echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2 + rm -rf "$tmp" + return 1 + fi + if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then + rm -rf "$tmp" + return 1 + fi + (cd "$tmp/root" && find . ! -type d) > "$tmp/files" + mkdir "$tmp/old" + while IFS= read -r f; do + f=${f#./} + if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then + cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; } + fi + done < "$tmp/files" + if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" && + mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then + rm -rf "$tmp" + return 0 + fi + echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2 + while IFS= read -r f; do + f=${f#./} + [ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f" + done < "$tmp/files" + tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2 + rm -rf "$tmp" + return 1 +} + +# The build DroidDeck-Components' fex.json names (the app passes it as BL_FEX_*) comes first, then a working +# installed one, then FEX_TAG above. Sets FEX_NOW and FEX_FROM. +fex_ready() { + local have ok= + have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true) + [ -x /usr/local/bin/FEX ] && fex_loads / && ok=1 + if [ -n "${BL_FEX_TAG:-}" ]; then + if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi + step "downloading FEX ($BL_FEX_TAG)" + if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi + if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi + fi + if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi + step "downloading FEX ($FEX_TAG)" + if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi + if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi + return 1 +} + +if [ "${BASH_SOURCE[0]}" = "$0" ]; then + set -eu + step() { echo "== STEP $*" >&2; } + fex_ready || exit 1 + echo "$FEX_NOW ($FEX_FROM)" +fi diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 index 8461fdf8a6..17d4490f17 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-x64 @@ -1,8 +1,5 @@ #!/bin/bash set -eu -FEX_TAG=fex-2610-r5 -FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4 -FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst ROOTFS_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/fex-rootfs-ubuntu-24.04-2026-08-11/Ubuntu_24_04.sqsh ROOTFS_SHA256=2854b06d3ff1b8f6e526135bfb6dd5b7b30ab3ab73e79ae933a3d9fed959a178 CDN=https://client-update.fastly.steamstatic.com @@ -18,6 +15,7 @@ ARM_STEAM=${XDG_DATA_HOME:-$REAL_HOME/.local/share}/Steam LOG=$X64_HOME/steam-x64.log mkdir -p "$X64_HOME" step() { echo "== STEP $(date -u +%H:%M:%S) $*" | tee -a "$LOG"; } +. "${BASH_SOURCE[0]%/*}/droiddeck-fex-update" x64_default_dir() { local d @@ -319,76 +317,6 @@ print("droiddeck-steam-x64: %d Linux title(s) on DroidDeck direct (%d on the new PY } -# Whether every program in the FEX tree at $1 finds its libraries (r4 did not without libxxhash). -fex_loads() { - local b out - for b in FEX FEXServer unsquashfs; do - out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue - echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2 - return 1 - done -} - -# Installs one FEX build only once its archive matches the sha256 and it loads. The files it replaces are kept -# until the installed copy loads too, and put back otherwise; the tag is written last. -fex_install() { - local tag=$1 sha=$2 urls=$3 dst=/ tmp u f - tmp=$(mktemp -d) - for u in $urls; do - curl -fsSL --retry 2 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break - rm -f "$tmp/fex.tzst" - done - if [ ! -s "$tmp/fex.tzst" ]; then - echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2 - rm -rf "$tmp" - return 1 - fi - if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then - rm -rf "$tmp" - return 1 - fi - (cd "$tmp/root" && find . ! -type d) > "$tmp/files" - mkdir "$tmp/old" - while IFS= read -r f; do - f=${f#./} - if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then - cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; } - fi - done < "$tmp/files" - if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" && - mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then - rm -rf "$tmp" - return 0 - fi - echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2 - while IFS= read -r f; do - f=${f#./} - [ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f" - done < "$tmp/files" - tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2 - rm -rf "$tmp" - return 1 -} - -# The build DroidDeck-Components' fex.json names (the app passes it as BL_FEX_*) comes first, then a working -# installed one, then FEX_TAG above. Sets FEX_NOW and FEX_FROM. -x64_fex() { - local have ok= - have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true) - [ -x /usr/local/bin/FEX ] && fex_loads / && ok=1 - if [ -n "${BL_FEX_TAG:-}" ]; then - if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi - step "downloading FEX ($BL_FEX_TAG)" - if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi - if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi - fi - if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi - step "downloading FEX ($FEX_TAG)" - if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi - if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi - return 1 -} - # A resumable download that reports every tenth of its size as a step. x64_fetch() { local url=$1 out=$2 label=$3 total pid rc=0 last=-1 pct @@ -406,7 +334,7 @@ x64_fetch() { } x64_prepare() { -x64_fex || { step "FEX could not be installed; see $LOG"; exit 1; } +fex_ready || { step "FEX could not be installed; see $LOG"; exit 1; } step "FEX ready ($FEX_NOW, $FEX_FROM)" # The client's opt-in to its SteamRT3 build; without it, it re-executes through steam.sh, whose checks fail under proot. mkdir -p "$STEAM_X64" && : > "$STEAM_X64/.steam-enable-steamrt64-client" diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py index e65b21277e..fda93362e0 100644 --- a/tools/tests/test_droiddeck_fex.py +++ b/tools/tests/test_droiddeck_fex.py @@ -48,6 +48,8 @@ class FexTestCase(unittest.TestCase): "HOST_PRELOAD": str(self.tmp / "ld.so.preload"), "DEVICE_FONTS": str(self.tmp / "android-fonts"), "FONT_RULES": str(self.tmp / "66-droiddeck-device-fonts.conf"), + "OWN_FEX": str(self.tmp / "own"), + "OWN_FEX_TAG": str(self.tmp / "own/share/fex-emu/.droiddeck-tag"), } patcher = mock.patch.dict(G, patches) patcher.start() @@ -202,6 +204,37 @@ class LocateTest(FexTestCase): self.assertEqual((fex["bin"], fex["server"], fex["portable"]), (str(tool / "usr/bin/FEX"), str(tool / "usr/bin/FEXServer"), True)) self.assertTrue(fex["host_thunks"].endswith("HostThunks") and fex["guest_thunks"].endswith("GuestThunks") and fex["thunks_db"]) + def own_fex(self, tag): + own = self.tmp / "own" + self.write(own / "bin/FEX", mode=0o755) + self.write(own / "bin/FEXServer", mode=0o755) + self.write(own / "share/fex-emu/.droiddeck-tag", tag + "\n") + return own + + def test_droiddeck_s_own_build_comes_before_the_steam_tool(self): + self.fex_tool(self.steam) + own = self.own_fex("fex-2610-r7") + fex = FEX["fex_install"]() + self.assertEqual((fex["bin"], fex["server"], fex["portable"]), (str(own / "bin/FEX"), str(own / "bin/FEXServer"), False)) + + def test_the_build_the_session_names_is_installed_once(self): + self.own_fex("fex-2610-r6") + calls = [] + with mock.patch.dict(os.environ, {"BL_FEX_TAG": "fex-2610-r7"}), \ + mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(args) or 0): + FEX["update_own_fex"]() + self.write(self.tmp / "own/share/fex-emu/.droiddeck-tag", "fex-2610-r7\n") + FEX["update_own_fex"]() + self.assertEqual([[str(BIN / "droiddeck-fex-update")]], calls) + + def test_no_build_is_installed_without_one_from_the_session(self): + calls = [] + with mock.patch.dict(os.environ, {}, clear=False), \ + mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(args) or 0): + os.environ.pop("BL_FEX_TAG", None) + FEX["update_own_fex"]() + self.assertEqual([], calls) + def test_library_folders_are_read(self): other = self.tmp / "other" (other / "steamapps/common").mkdir(parents=True) diff --git a/tools/tests/test_fex_install.py b/tools/tests/test_fex_install.py index 355b540381..51d5279e89 100644 --- a/tools/tests/test_fex_install.py +++ b/tools/tests/test_fex_install.py @@ -6,7 +6,7 @@ import tempfile import textwrap import unittest -SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64" +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-fex-update" SOURCE = SCRIPT.read_text() START = SOURCE.index("fex_install() {") END = SOURCE.index("\n}\n", START) + 3 diff --git a/tools/tests/test_fex_select.py b/tools/tests/test_fex_select.py index 94008a1c70..3b351520e7 100644 --- a/tools/tests/test_fex_select.py +++ b/tools/tests/test_fex_select.py @@ -5,9 +5,9 @@ import tempfile import textwrap import unittest -SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64" +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-fex-update" SOURCE = SCRIPT.read_text() -START = SOURCE.index("x64_fex() {") +START = SOURCE.index("fex_ready() {") END = SOURCE.index("\n}\n", START) + 3 X64_FEX = SOURCE[START:END] @@ -35,7 +35,7 @@ class FexSelectTest(unittest.TestCase): fex.chmod(0o755) body = (X64_FEX.replace("/usr/local/share/fex-emu/.droiddeck-tag", "$ROOT/tag") .replace("/usr/local/bin/FEX", "$ROOT/FEX")) - script = HARNESS + body + 'if x64_fex; then echo "NOW $FEX_NOW|$FEX_FROM"; else echo FAILED; fi\n' + script = HARNESS + body + 'if fex_ready; then echo "NOW $FEX_NOW|$FEX_FROM"; else echo FAILED; fi\n' env = dict(os.environ, ROOT=root, LOADS="1" if loads else "0", INSTALLABLE=" ".join(installable)) env.pop("BL_FEX_TAG", None) if catalog: