-
-
Notifications
You must be signed in to change notification settings - Fork 262
fix: bundle daemon sidecars in app build #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vforsh
wants to merge
5
commits into
Dimillian:main
Choose a base branch
from
vforsh:fix/bundle-daemon-sidecars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b23219d
fix: bundle daemon sidecars in app build
ad44bf9
fix: move tauri external bins to bundle-only config
e27036e
fix: run sidecar prebuild command cross-platform
d66dc60
docs: split macOS launchd daemon setup into docs guide
7983ece
fix: honor Tauri target triple for sidecar builds
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ CodexMonitor.zip | |
| .claude/ | ||
| .cursor/ | ||
| public/assets/material-icons/ | ||
| src-tauri/binaries/ | ||
|
|
||
| # Nix | ||
| result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # macOS launchd: Start Codex Monitor Daemon on Login | ||
|
|
||
| Use a user `LaunchAgent` so the daemon starts automatically when you log in. | ||
|
|
||
| ## Prerequisite | ||
|
|
||
| Confirm the installed app binaries exist: | ||
|
|
||
| ```bash | ||
| APP_BIN_DIR="/Applications/Codex Monitor.app/Contents/MacOS" | ||
| ls -l "$APP_BIN_DIR/codex_monitor_daemon" "$APP_BIN_DIR/codex_monitor_daemonctl" | ||
| ``` | ||
|
|
||
| ## 1) Create LaunchAgent plist | ||
|
|
||
| Create `~/Library/LaunchAgents/com.dimillian.codexmonitor.daemon.plist`: | ||
|
|
||
| ```xml | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>Label</key> | ||
| <string>com.dimillian.codexmonitor.daemon</string> | ||
| <key>ProgramArguments</key> | ||
| <array> | ||
| <string>/Applications/Codex Monitor.app/Contents/MacOS/codex_monitor_daemon</string> | ||
| <string>--listen</string> | ||
| <string>127.0.0.1:4732</string> | ||
| <string>--token</string> | ||
| <string>YOUR_TOKEN_HERE</string> | ||
| </array> | ||
| <key>RunAtLoad</key> | ||
| <true/> | ||
| <key>KeepAlive</key> | ||
| <true/> | ||
| <key>StandardOutPath</key> | ||
| <string>/tmp/com.dimillian.codexmonitor.daemon.out.log</string> | ||
| <key>StandardErrorPath</key> | ||
| <string>/tmp/com.dimillian.codexmonitor.daemon.err.log</string> | ||
| </dict> | ||
| </plist> | ||
| ``` | ||
|
|
||
| ## 2) Load and start | ||
|
|
||
| ```bash | ||
| launchctl bootout "gui/$(id -u)" ~/Library/LaunchAgents/com.dimillian.codexmonitor.daemon.plist 2>/dev/null || true | ||
| launchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/com.dimillian.codexmonitor.daemon.plist | ||
| launchctl kickstart -k "gui/$(id -u)/com.dimillian.codexmonitor.daemon" | ||
| ``` | ||
|
|
||
| ## 3) Check status and logs | ||
|
|
||
| ```bash | ||
| launchctl print "gui/$(id -u)/com.dimillian.codexmonitor.daemon" | ||
| tail -f /tmp/com.dimillian.codexmonitor.daemon.out.log /tmp/com.dimillian.codexmonitor.daemon.err.log | ||
| ``` | ||
|
|
||
| ## 4) Disable | ||
|
|
||
| ```bash | ||
| launchctl bootout "gui/$(id -u)" ~/Library/LaunchAgents/com.dimillian.codexmonitor.daemon.plist | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import { chmodSync, copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs"; | ||
| import { dirname, join, resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import process from "node:process"; | ||
|
|
||
| const scriptDir = dirname(fileURLToPath(import.meta.url)); | ||
| const repoRoot = resolve(scriptDir, ".."); | ||
| const srcTauriDir = join(repoRoot, "src-tauri"); | ||
| const binariesDir = join(srcTauriDir, "binaries"); | ||
|
|
||
| const envBuildTarget = | ||
| process.env.TAURI_ENV_TARGET_TRIPLE || process.env.TARGET || process.env.CARGO_BUILD_TARGET || ""; | ||
| const explicitTarget = Boolean(envBuildTarget); | ||
| let buildTarget = envBuildTarget; | ||
|
|
||
| if (!buildTarget) { | ||
| const rustcVersion = run("rustc", ["-vV"], { captureOutput: true }); | ||
| const hostLine = rustcVersion.stdout | ||
| .split(/\r?\n/) | ||
| .find((line) => line.startsWith("host: ")); | ||
| if (!hostLine) { | ||
| console.error("Failed to resolve Rust target triple"); | ||
| process.exit(1); | ||
| } | ||
| buildTarget = hostLine.replace("host: ", "").trim(); | ||
| } | ||
|
|
||
| if (!buildTarget) { | ||
| console.error("Failed to resolve Rust target triple"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const isWindowsTarget = buildTarget.includes("windows"); | ||
| const binExt = isWindowsTarget ? ".exe" : ""; | ||
| const releaseDir = explicitTarget | ||
| ? join(srcTauriDir, "target", buildTarget, "release") | ||
| : join(srcTauriDir, "target", "release"); | ||
|
|
||
| mkdirSync(binariesDir, { recursive: true }); | ||
|
|
||
| const daemonSidecarPath = join( | ||
| binariesDir, | ||
| `codex_monitor_daemon-${buildTarget}${binExt}`, | ||
| ); | ||
| const daemonctlSidecarPath = join( | ||
| binariesDir, | ||
| `codex_monitor_daemonctl-${buildTarget}${binExt}`, | ||
| ); | ||
|
|
||
| bootstrapSidecarPath(daemonSidecarPath, isWindowsTarget); | ||
| bootstrapSidecarPath(daemonctlSidecarPath, isWindowsTarget); | ||
|
|
||
| const cargoArgs = ["build", "--release"]; | ||
| if (explicitTarget) { | ||
| cargoArgs.push("--target", buildTarget); | ||
| } | ||
| cargoArgs.push("--bin", "codex_monitor_daemon", "--bin", "codex_monitor_daemonctl"); | ||
|
|
||
| run("cargo", cargoArgs, { cwd: srcTauriDir }); | ||
|
|
||
| copyFileSync( | ||
| join(releaseDir, `codex_monitor_daemon${binExt}`), | ||
| daemonSidecarPath, | ||
| ); | ||
| copyFileSync( | ||
| join(releaseDir, `codex_monitor_daemonctl${binExt}`), | ||
| daemonctlSidecarPath, | ||
| ); | ||
|
|
||
| if (!isWindowsTarget) { | ||
| chmodSync(daemonSidecarPath, 0o755); | ||
| chmodSync(daemonctlSidecarPath, 0o755); | ||
| } | ||
|
|
||
| console.log(`Prepared sidecars for ${buildTarget} in ${binariesDir}`); | ||
|
|
||
| function bootstrapSidecarPath(path, isWindows) { | ||
| if (!existsSync(path)) { | ||
| writeFileSync(path, ""); | ||
| } | ||
| if (!isWindows) { | ||
| chmodSync(path, 0o755); | ||
| } | ||
| } | ||
|
|
||
| function run(command, args, options = {}) { | ||
| const { captureOutput = false, ...spawnOptions } = options; | ||
| const result = spawnSync(command, args, { | ||
| encoding: captureOutput ? "utf8" : undefined, | ||
| stdio: captureOutput ? ["ignore", "pipe", "pipe"] : "inherit", | ||
| ...spawnOptions, | ||
| }); | ||
|
|
||
| if (result.status !== 0) { | ||
| if (captureOutput && result.stdout) { | ||
| process.stdout.write(result.stdout); | ||
| } | ||
| if (captureOutput && result.stderr) { | ||
| process.stderr.write(result.stderr); | ||
| } | ||
| process.exit(result.status ?? 1); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| repo_root="$(cd "${script_dir}/.." && pwd)" | ||
| src_tauri_dir="${repo_root}/src-tauri" | ||
| binaries_dir="${src_tauri_dir}/binaries" | ||
|
|
||
| build_target="${TARGET:-${CARGO_BUILD_TARGET:-}}" | ||
| if [[ -z "${build_target}" ]]; then | ||
| build_target="$(rustc -vV | awk '/^host: / { print $2 }')" | ||
| fi | ||
| if [[ -z "${build_target}" ]]; then | ||
| echo "Failed to resolve Rust target triple" | ||
| exit 1 | ||
| fi | ||
|
|
||
| cargo_target_args=() | ||
| release_dir="${src_tauri_dir}/target/release" | ||
| if [[ -n "${TARGET:-${CARGO_BUILD_TARGET:-}}" ]]; then | ||
| cargo_target_args=(--target "${build_target}") | ||
| release_dir="${src_tauri_dir}/target/${build_target}/release" | ||
| fi | ||
|
|
||
| bin_ext="" | ||
| if [[ "${build_target}" == *windows* ]]; then | ||
| bin_ext=".exe" | ||
| fi | ||
|
|
||
| mkdir -p "${binaries_dir}" | ||
|
|
||
| daemon_sidecar_path="${binaries_dir}/codex_monitor_daemon-${build_target}${bin_ext}" | ||
| daemonctl_sidecar_path="${binaries_dir}/codex_monitor_daemonctl-${build_target}${bin_ext}" | ||
|
|
||
| # Bootstrap sidecar paths so tauri's build-script path checks can pass. | ||
| if [[ ! -f "${daemon_sidecar_path}" ]]; then | ||
| : > "${daemon_sidecar_path}" | ||
| fi | ||
| if [[ ! -f "${daemonctl_sidecar_path}" ]]; then | ||
| : > "${daemonctl_sidecar_path}" | ||
| fi | ||
| if [[ -z "${bin_ext}" ]]; then | ||
| chmod +x "${daemon_sidecar_path}" "${daemonctl_sidecar_path}" | ||
| fi | ||
|
|
||
| ( | ||
| cd "${src_tauri_dir}" | ||
| if [[ ${#cargo_target_args[@]} -gt 0 ]]; then | ||
| cargo build --release "${cargo_target_args[@]}" \ | ||
| --bin codex_monitor_daemon \ | ||
| --bin codex_monitor_daemonctl | ||
| else | ||
| cargo build --release \ | ||
| --bin codex_monitor_daemon \ | ||
| --bin codex_monitor_daemonctl | ||
| fi | ||
| ) | ||
|
|
||
| cp -f \ | ||
| "${release_dir}/codex_monitor_daemon${bin_ext}" \ | ||
| "${daemon_sidecar_path}" | ||
| cp -f \ | ||
| "${release_dir}/codex_monitor_daemonctl${bin_ext}" \ | ||
| "${daemonctl_sidecar_path}" | ||
|
|
||
| if [[ -z "${bin_ext}" ]]; then | ||
| chmod +x "${daemon_sidecar_path}" "${daemonctl_sidecar_path}" | ||
| fi | ||
|
|
||
| echo "Prepared sidecars for ${build_target} in ${binaries_dir}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "bundle": { | ||
| "externalBin": [ | ||
| "binaries/codex_monitor_daemon", | ||
| "binaries/codex_monitor_daemonctl" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tauri build --helpallowsuniversal-apple-darwin, but this hook forwardsTAURI_ENV_TARGET_TRIPLEdirectly tocargo build --target. When the build target is universal, Cargo rejects it (could not find specification for target "universal-apple-darwin"), sobeforeBuildCommandfails before Tauri can do its universal macOS build flow. This makes supported universal macOS builds fail whenever sidecar prep runs.Useful? React with 👍 / 👎.