diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45348a4..c22d0d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,6 +100,7 @@ jobs: python test/integration/release.py backend/target/debug/omarchy-audio-service python test/integration/packaging.py backend/target/debug/omarchy-audio-service python packaging/build-release.py --output "$RUNNER_TEMP/audio-upgrade-candidate" --binary backend/target/debug/omarchy-audio-service + python test/integration/native_startup.py "$RUNNER_TEMP/audio-upgrade-candidate" python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/runtime.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service" python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/routed_audio.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service" python "$RUNNER_TEMP/audio-upgrade-candidate/test/integration/profiles.py" "$RUNNER_TEMP/audio-upgrade-candidate/bin/omarchy-audio-service" @@ -113,9 +114,16 @@ jobs: python test/integration/upgrade.py "$RUNNER_TEMP/audio-upgrade-candidate" legacy-plugin release-candidate: - name: Build self-contained plugin candidate + name: Build self-contained plugin candidate (${{ matrix.arch }}) needs: [test, qml-runtime] - runs-on: ubuntu-24.04 + runs-on: ${{ matrix.runner }} + strategy: + matrix: + include: + - runner: ubuntu-24.04 + arch: x86_64 + - runner: ubuntu-24.04-arm + arch: aarch64 timeout-minutes: 15 steps: - name: Check out plugin @@ -131,12 +139,14 @@ jobs: python3 packaging/build-release.py --output "$RUNNER_TEMP/audio-plugin" python3 packaging/build-release.py --check "$RUNNER_TEMP/audio-plugin" python3 test/integration/lifecycle.py "$RUNNER_TEMP/audio-plugin/bin/omarchy-audio-service" - tar -C "$RUNNER_TEMP/audio-plugin" -czf "$RUNNER_TEMP/omarchy-audio-control-linux-x86_64.tar.gz" . + python3 test/integration/release.py "$RUNNER_TEMP/audio-plugin/bin/omarchy-audio-service" + python3 test/integration/native_backend.py + tar -C "$RUNNER_TEMP/audio-plugin" -czf "$RUNNER_TEMP/omarchy-audio-control-linux-${{ matrix.arch }}.tar.gz" . - name: Upload candidate for review uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: omarchy-audio-control-linux-x86_64 - path: ${{ runner.temp }}/omarchy-audio-control-linux-x86_64.tar.gz + name: omarchy-audio-control-linux-${{ matrix.arch }} + path: ${{ runner.temp }}/omarchy-audio-control-linux-${{ matrix.arch }}.tar.gz if-no-files-found: error retention-days: 14 diff --git a/README.md b/README.md index 092962a..8d0d91d 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,26 @@ until discarded or until the advanced window closes. ## Install -Requires **Omarchy Quattro on x86_64 Linux**, PipeWire and WirePlumber, with -Omarchy's usual audio and desktop tools. Installation needs no Rust toolchain. +Requires **Omarchy Quattro on x86_64 or aarch64 Linux**, PipeWire and WirePlumber, +with Omarchy's usual audio and desktop tools. The Git checkout includes an +x86_64 backend, so x86_64 installation needs no Rust toolchain. + +On **aarch64** (including Asahi Linux), install Rust/Cargo **1.85+**, libclang, +pkg-config, and the PipeWire and libpulse development headers before enabling +the plugin. For Arch-based systems: + +```bash +sudo pacman -S --needed rust clang pkgconf pipewire libpulse +``` + +The plugin builds a native backend on first startup and after updates that +change runtime sources. The panel shows **Preparing audio service…** until the +build finishes. Builds stay under +`${XDG_CACHE_HOME:-~/.cache}/omarchy-audio-control/`; dependencies are reused +across updates, and the plugin checkout remains unchanged. Later starts use +the cached executable. If preparation fails, install the requirements above +and reload the plugin. Manual binary replacement after each update is no +longer needed. ```bash omarchy plugin add https://github.com/ssupt/omarchy-audio-control.git --enable diff --git a/backend-release.json b/backend-release.json index 426fad3..43ca95a 100644 --- a/backend-release.json +++ b/backend-release.json @@ -1,7 +1,7 @@ { - "buildId": "3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84", + "buildId": "3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d", "target": "x86_64-unknown-linux-gnu", "version": "0.1.0", "protocolVersion": 1, - "sha256": "e37256102a94ca5ab01c7a1bb1bbb8afe0b3c9cdc56609d723fb43080efe40ec" + "sha256": "7faad268771810e4aa53463d36e7f66d4cf35079c103e05bfcd9414d4f763d0e" } diff --git a/backend/build.rs b/backend/build.rs index 79207b0..2e98bd1 100644 --- a/backend/build.rs +++ b/backend/build.rs @@ -31,6 +31,7 @@ fn main() { "backend/build.rs".into(), "packaging/manifest.template.json".into(), "packaging/build-release.py".into(), + "packaging/launch-backend.py".into(), ]; collect_sources(root, &root.join("backend/src"), &mut files); println!( diff --git a/bin/omarchy-audio-service b/bin/omarchy-audio-service index e967ff1..a062f04 100755 Binary files a/bin/omarchy-audio-service and b/bin/omarchy-audio-service differ diff --git a/manifest.json b/manifest.json index a659e46..07a09eb 100644 --- a/manifest.json +++ b/manifest.json @@ -11,9 +11,9 @@ "service" ], "entryPoints": { - "barWidget": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/panels/Panel.qml", - "panel": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/panels/AdvancedAudio.qml", - "service": "runtime/3b9a83e019dc97d72fc5811b677ffca8800577e0aad56b3ed924b393c0871d84/qml/core/Service.qml" + "barWidget": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/panels/Panel.qml", + "panel": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/panels/AdvancedAudio.qml", + "service": "runtime/3b427ced50a7f5b6ee554fb64f8f92e682b8f09aa8777112d27a84eec53d787d/qml/core/Service.qml" }, "barWidget": { "displayName": "Advanced Audio Control", diff --git a/packaging/build-release.py b/packaging/build-release.py index d717952..58ba755 100644 --- a/packaging/build-release.py +++ b/packaging/build-release.py @@ -14,7 +14,8 @@ def source_id(root): names = ['backend/Cargo.toml', 'backend/Cargo.lock', 'backend/build.rs', - 'packaging/manifest.template.json', 'packaging/build-release.py'] + 'packaging/manifest.template.json', 'packaging/build-release.py', + 'packaging/launch-backend.py'] for directory in ('qml', 'backend/src', 'scripts'): paths = ((root / directory).rglob('*') if directory != 'scripts' else (root / directory).iterdir()) @@ -76,8 +77,8 @@ def verify(root): info = inspect(binary) if info['buildId'] != source_id(root) or metadata['buildId'] != info['buildId']: raise ValueError('Backend does not match the plugin sources; rebuild the release') - if info['target'] != 'x86_64-unknown-linux-gnu' or metadata['target'] != info['target']: - raise ValueError('This release targets Omarchy on x86_64 Linux') + if info['target'] not in ('x86_64-unknown-linux-gnu', 'aarch64-unknown-linux-gnu') or metadata['target'] != info['target']: + raise ValueError('This release requires a native x86_64 or aarch64 Linux backend') if any(metadata.get(key) != info.get(key) for key in ('version', 'protocolVersion')): raise ValueError('Backend version metadata does not match the executable') if not os.access(binary, os.X_OK): diff --git a/packaging/launch-backend.py b/packaging/launch-backend.py new file mode 100644 index 0000000..c2d56b3 --- /dev/null +++ b/packaging/launch-backend.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 +"""Prepare a backend for this CPU without changing the installed plugin.""" +import fcntl +import importlib.util +import json +import os +from pathlib import Path +import platform +import shutil +import stat +import struct +import subprocess +import sys +import tempfile + +TARGETS = { + 'x86_64': ('x86_64-unknown-linux-gnu', 62), + 'aarch64': ('aarch64-unknown-linux-gnu', 183), +} + + +def release_tools(root): + spec = importlib.util.spec_from_file_location('audio_release', root/'packaging/build-release.py') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def matches(binary, target, machine, build_id, tools, cached=False): + try: + descriptor = os.open(binary, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK) + with os.fdopen(descriptor, 'rb') as stream: + metadata = os.fstat(stream.fileno()) + if not stat.S_ISREG(metadata.st_mode): + return False + if cached and (metadata.st_uid != os.getuid() or metadata.st_nlink != 1 + or metadata.st_mode & 0o022): + return False + header = stream.read(20) + # Never execute a foreign ELF (including via binfmt/QEMU). + if (len(header) != 20 or header[:6] != b'\x7fELF\x02\x01' + or struct.unpack_from('= 5900, 'Slow preparation was bypassed' + finally: + if success: + # This PID comes from hello on the private temporary daemon. + try: + os.kill(int(success[1]), signal.SIGTERM) + except ProcessLookupError: + pass +print('PASS: packaged native startup and preparation beyond the hello deadline') diff --git a/test/integration/release.py b/test/integration/release.py index b739bda..29e82d5 100644 --- a/test/integration/release.py +++ b/test/integration/release.py @@ -38,6 +38,11 @@ def rejected(check, message): nested_extra.write_text('// Added after the backend was built\n') rejected(lambda: release.verify(candidate), 'Added nested Rust source was accepted') nested_extra.unlink() + launcher = candidate/'packaging/launch-backend.py' + original_launcher = launcher.read_bytes() + launcher.write_bytes(original_launcher + b'\n# Changed native preparation\n') + rejected(lambda: release.verify(candidate), 'Modified native launcher was accepted') + launcher.write_bytes(original_launcher) executable = candidate/'bin/omarchy-audio-service' original = executable.read_bytes() executable.write_bytes(b'broken executable') diff --git a/test/integration/runtime.py b/test/integration/runtime.py index 1c8f3e6..6b3367d 100644 --- a/test/integration/runtime.py +++ b/test/integration/runtime.py @@ -65,7 +65,10 @@ def stop(process): PULSE_SERVER='unix:'+str(work/'audio-test-pulse'), XDG_STATE_HOME=str(work / 'state'), XDG_CACHE_HOME=str(work / 'cache'), AUDIO_CONTROL_PRIVATE_RUNTIME_DIR=temporary, - AUDIO_INTEGRATION_LOG=str(work / 'operations'), PATH=str(binaries)+os.pathsep+os.environ['PATH']) + AUDIO_INTEGRATION_LOG=str(work / 'operations'), + # The private config must not invoke user tool-manager shims + # whose trust/configuration changes with XDG_CONFIG_HOME. + PATH=str(binaries)+os.pathsep+os.defpath+os.pathsep+os.environ['PATH']) # Remove inherited per-store overrides so tests cannot touch user documents. for key in ('OMARCHY_AUDIO_CONTROL_FILE', 'OMARCHY_AUDIO_PREFERENCES_FILE', 'OMARCHY_AUDIO_RULES_FILE', 'OMARCHY_AUDIO_SCENES_FILE'): env.pop(key, None) @@ -370,7 +373,11 @@ def pipewire(): Process { id: crashProc } Timer { interval: 25000; running: true; onTriggered: { console.log("RUNTIME_FAILURE timeout"); Qt.quit() } } } -'''.replace('DIAGNOSTICS_URL', json.dumps(((ROOT/ENTRY_POINTS['service']).parent.parent/'diagnostics/AudioDiagnosticsController.qml').as_uri())).replace('BACKEND_PROPERTIES', json.dumps({} if PACKAGED else {'backendCommand':[str(BINARY),'--plugin']})).replace('RUNTIME_URL', json.dumps((ROOT/ENTRY_POINTS['service']).with_name('AudioRuntime.qml').as_uri())).replace('SCRIPTS_PATH', json.dumps(str(ROOT/'scripts'))).replace('SERVICE_URL', json.dumps((ROOT/ENTRY_POINTS['service']).as_uri())).replace('UI_PROBE', +'''.replace('DIAGNOSTICS_URL', json.dumps(((ROOT/ENTRY_POINTS['service']).parent.parent/'diagnostics/AudioDiagnosticsController.qml').as_uri())).replace('BACKEND_PROPERTIES', json.dumps({} if PACKAGED else { + # Preparation can outlast the five-second protocol deadline on first ARM + # builds. A delayed preparation must finish before hello is sent. + 'backendPreparationCommand': [sys.executable, '-c', 'import time; time.sleep(6); print('+repr(str(BINARY))+')'] +})).replace('RUNTIME_URL', json.dumps((ROOT/ENTRY_POINTS['service']).with_name('AudioRuntime.qml').as_uri())).replace('SCRIPTS_PATH', json.dumps(str(ROOT/'scripts'))).replace('SERVICE_URL', json.dumps((ROOT/ENTRY_POINTS['service']).as_uri())).replace('UI_PROBE', ('var panel = Qt.createComponent('+json.dumps((ROOT/ENTRY_POINTS['barWidget']).as_uri())+'); ' 'var advanced = Qt.createComponent('+json.dumps((ROOT/ENTRY_POINTS['panel']).as_uri())+'); ' 'if (panel.status !== Component.Ready || advanced.status !== Component.Ready) { '