-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Changes from 4 commits
b23219d
ad44bf9
e27036e
d66dc60
7983ece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/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 explicitTarget = Boolean(process.env.TARGET || process.env.CARGO_BUILD_TARGET); | ||
| let buildTarget = process.env.TARGET || process.env.CARGO_BUILD_TARGET || ""; | ||
|
|
||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
| 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; | ||
| } | ||
| 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}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "bundle": { | ||
| "externalBin": [ | ||
| "binaries/codex_monitor_daemon", | ||
| "binaries/codex_monitor_daemonctl" | ||
| ] | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.