Skip to content

Commit 53e6eb5

Browse files
committed
fix(desktop): carry native sidecar packaging repair to main
1 parent 891674c commit 53e6eb5

5 files changed

Lines changed: 87 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ jobs:
245245
run: |
246246
bun desktop/scripts/prepare-sidecar.ts --target aarch64-apple-darwin
247247
bun desktop/scripts/prepare-sidecar.ts --target x86_64-apple-darwin
248+
lipo -create desktop/src-tauri/binaries/ocx-aarch64-apple-darwin \
249+
desktop/src-tauri/binaries/ocx-x86_64-apple-darwin \
250+
-output desktop/src-tauri/binaries/ocx-universal-apple-darwin
251+
lipo -verify_arch arm64 x86_64 desktop/src-tauri/binaries/ocx-universal-apple-darwin
248252
249253
- name: Prepare sidecar
250254
if: runner.os != 'macOS'
@@ -344,6 +348,12 @@ jobs:
344348
RELEASE_VERSION: ${{ inputs.version }}
345349
run: bun desktop/scripts/windows-installer-config.ts "$RELEASE_VERSION" "$RUNNER_TEMP/opencodex-msi.json"
346350

351+
- name: Preserve the compiled Linux sidecar
352+
if: runner.os == 'Linux'
353+
run: |
354+
chmod +x desktop/scripts/appimage-patchelf.py
355+
echo "PATCHELF=$GITHUB_WORKSPACE/desktop/scripts/appimage-patchelf.py" >> "$GITHUB_ENV"
356+
347357
# Release signing is intentionally secret-gated. Developer ID, notarization,
348358
# and updater signatures require maintainer-owned credentials; builds without
349359
# those secrets remain useful for local validation but are not release assets.
@@ -363,6 +373,10 @@ jobs:
363373
# diagnostics on the first attempt; Apple signing commands stay non-verbose.
364374
run: bunx tauri ${{ runner.os == 'Linux' && '--verbose' || '' }} build --ci --target ${{ matrix.target }} --bundles ${{ matrix.bundles }} --config "${{ runner.os == 'Windows' && format('{0}/opencodex-msi.json', runner.temp) || '{}' }}"
365375

376+
- name: Verify the packaged Linux sidecar
377+
if: runner.os == 'Linux'
378+
run: bash desktop/scripts/verify-linux-sidecar.sh
379+
366380
- name: Rename release assets
367381
shell: bash
368382
env:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
"""Keep the compiled Bun sidecar intact while linuxdeploy patches the host/libs."""
3+
import os
4+
from pathlib import Path
5+
import sys
6+
7+
8+
def main(args):
9+
root = Path(__file__).resolve().parents[2]
10+
triple = "x86_64-unknown-linux-gnu"
11+
original = root / "desktop/src-tauri/binaries" / f"ocx-{triple}"
12+
sidecar = root / "desktop/src-tauri/target" / triple / "release/bundle/appimage/OpenCodex.AppDir/usr/bin/ocx"
13+
if len(args) == 3 and args[:2] == ["--set-rpath", "$ORIGIN/../lib"] and Path(args[2]).resolve() == sidecar.resolve():
14+
# linuxdeploy's nested GTK pass runs ldd again after patching. Its
15+
# patchelf rewrite breaks the compiled Bun ELF. This sidecar depends
16+
# only on host glibc libraries; it needs no AppDir library search path.
17+
# Never bless an already-modified binary or a different executable.
18+
if sidecar.is_symlink() or original.read_bytes() != sidecar.read_bytes():
19+
raise RuntimeError("AppImage sidecar differs from the prepared CLI")
20+
print("Preserving compiled ocx bytes (no AppDir RPATH required)", file=sys.stderr)
21+
return
22+
os.execv("/usr/bin/patchelf", ["/usr/bin/patchelf", *args])
23+
24+
25+
if __name__ == "__main__":
26+
main(sys.argv[1:])
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# Run only on a Linux packaging runner, against the completed AppImage.
3+
set -euo pipefail
4+
root="$(cd "$(dirname "$0")/../.." && pwd)"
5+
bundle="$root/desktop/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/appimage"
6+
original="$root/desktop/src-tauri/binaries/ocx-x86_64-unknown-linux-gnu"
7+
shopt -s nullglob
8+
images=("$bundle"/*.AppImage)
9+
if [ "${#images[@]}" -ne 1 ]; then
10+
echo "Expected exactly one completed AppImage" >&2
11+
exit 1
12+
fi
13+
scratch="$(mktemp -d)"
14+
trap 'rm -rf "$scratch"' EXIT
15+
cd "$scratch"
16+
"${images[0]}" --appimage-extract > /dev/null
17+
sidecar="$scratch/squashfs-root/usr/bin/ocx"
18+
test ! -L "$sidecar"
19+
cmp "$original" "$sidecar"
20+
sha256sum "$original" "$sidecar"
21+
mkdir "$scratch/home"
22+
timeout 30s env OPENCODEX_HOME="$scratch/home" "$sidecar" --version

‎structure/desktop-shell.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ marker, which the GUI detects to identify the shell without using IPC.
195195

196196
## Release packaging and updater
197197

198+
Linux AppImage packaging uses `desktop/scripts/appimage-patchelf.py` to preserve
199+
the compiled Bun CLI when linuxdeploy sets the executable RPATH. Only the exact
200+
AppDir sidecar, still byte-identical to the prepared CLI, is exempt; other ELF
201+
operations use the system patchelf. `desktop/scripts/verify-linux-sidecar.sh`
202+
extracts the completed AppImage, compares its CLI bytes and runs its version command
203+
on the hosted runner before any release asset is collected.
204+
The macOS release combines both prepared CLI architectures with `lipo` into the
205+
universal external binary Tauri expects, and checks that both slices are present.
206+
198207
The release workflow packages the desktop shell as `OpenCodex-<version>-macos.dmg`,
199208
`OpenCodex-<version>-windows-x64.msi`, `OpenCodex-<version>-linux-x86_64.AppImage`, and
200209
`OpenCodex-<version>-linux-amd64.deb`. Each artifact is collected with a `.sha256` file;

‎tests/ci-workflows/release-desktop-scripts.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ describe("widget extension signing", () => {
433433
const rust = steps.find(step => step.name === "Setup Rust");
434434
expect(rust?.with?.targets).toContain("aarch64-apple-darwin,x86_64-apple-darwin");
435435
expect(rust?.with?.targets).toContain("runner.os == 'macOS'");
436+
const sidecars = steps.find(step => step.name === "Prepare macOS sidecars");
437+
expect(sidecars?.run).toContain("lipo -create desktop/src-tauri/binaries/ocx-aarch64-apple-darwin");
438+
expect(sidecars?.run).toContain("-output desktop/src-tauri/binaries/ocx-universal-apple-darwin");
439+
expect(sidecars?.run).toContain("lipo -verify_arch arm64 x86_64");
436440
const prepare = steps.find(step => step.name === "Prepare Windows installer version");
437441
expect(prepare?.if).toBe("runner.os == 'Windows'");
438442
expect(prepare?.env?.RELEASE_VERSION).toBe("${{ inputs.version }}");
@@ -444,6 +448,18 @@ describe("widget extension signing", () => {
444448
expect(indexOfStep("Prepare Windows installer version")).toBeLessThan(indexOfStep("Build desktop bundles"));
445449
});
446450

451+
test("Linux verifies the packaged CLI before collecting release assets", () => {
452+
const preserve = steps.find(step => step.name === "Preserve the compiled Linux sidecar");
453+
const verify = steps.find(step => step.name === "Verify the packaged Linux sidecar");
454+
expect(preserve?.if).toBe("runner.os == 'Linux'");
455+
expect(preserve?.run).toContain("PATCHELF=$GITHUB_WORKSPACE/desktop/scripts/appimage-patchelf.py");
456+
expect(verify?.if).toBe("runner.os == 'Linux'");
457+
expect(verify?.run).toBe("bash desktop/scripts/verify-linux-sidecar.sh");
458+
expect(indexOfStep(preserve!.name!)).toBeLessThan(indexOfStep("Build desktop bundles"));
459+
expect(indexOfStep(verify!.name!)).toBeGreaterThan(indexOfStep("Build desktop bundles"));
460+
expect(indexOfStep(verify!.name!)).toBeLessThan(indexOfStep("Rename release assets"));
461+
});
462+
447463
test("the release build hands the widget a signing identity and forbids an ad-hoc fallback", () => {
448464
const build = steps.find(step => step.name === "Build WidgetKit extension");
449465
expect(build).toBeDefined();

0 commit comments

Comments
 (0)