Skip to content

Commit ef0b224

Browse files
author
Vladislav Forsh
committed
fix(tauri): bundle canonical daemon sidecar
1 parent 40f6fcb commit ef0b224

14 files changed

Lines changed: 248 additions & 26 deletions

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,23 @@ Build binaries:
109109

110110
```bash
111111
cd src-tauri
112-
cargo build --bin codex_monitor_daemon --bin codex_monitor_daemonctl
112+
cargo build --bin codex-monitor-daemon --bin codex-monitor-daemonctl
113113
```
114114

115115
Examples:
116116

117117
```bash
118118
# Show current daemon status
119-
./target/debug/codex_monitor_daemonctl status
119+
./target/debug/codex-monitor-daemonctl status
120120

121121
# Start daemon using host/token from settings.json
122-
./target/debug/codex_monitor_daemonctl start
122+
./target/debug/codex-monitor-daemonctl start
123123

124124
# Stop daemon
125-
./target/debug/codex_monitor_daemonctl stop
125+
./target/debug/codex-monitor-daemonctl stop
126126

127127
# Print equivalent daemon start command
128-
./target/debug/codex_monitor_daemonctl command-preview
128+
./target/debug/codex-monitor-daemonctl command-preview
129129
```
130130

131131
Useful overrides:

REMOTE_BACKEND_POC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cd src-tauri
1414
# pick a strong token (or export CODEX_MONITOR_DAEMON_TOKEN)
1515
TOKEN="change-me"
1616

17-
cargo run --bin codex_monitor_daemon -- \
17+
cargo run --bin codex-monitor-daemon -- \
1818
--listen 127.0.0.1:4732 \
1919
--data-dir "$HOME/.local/share/codex-monitor-daemon" \
2020
--token "$TOKEN"

docs/mobile-ios-tailscale-blueprint.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Headless alternative (no desktop UI required):
4141

4242
1. Build daemon + daemonctl:
4343
- `cd src-tauri`
44-
- `cargo build --bin codex_monitor_daemon --bin codex_monitor_daemonctl`
44+
- `cargo build --bin codex-monitor-daemon --bin codex-monitor-daemonctl`
4545
2. Start daemon from CLI:
46-
- `./target/debug/codex_monitor_daemonctl start`
46+
- `./target/debug/codex-monitor-daemonctl start`
4747
3. Verify daemon status:
48-
- `./target/debug/codex_monitor_daemonctl status`
48+
- `./target/debug/codex-monitor-daemonctl status`
4949

5050
## iOS Setup
5151

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"pretauri:dev": "npm run sync:material-icons",
3030
"tauri:dev": "npm run doctor:strict && tauri dev",
3131
"pretauri:build": "npm run sync:material-icons",
32-
"tauri:build": "npm run doctor:strict && tauri build",
32+
"tauri:build": "npm run doctor:strict && tauri build && bash ./src-tauri/scripts/cleanup-daemon-legacy-names.sh",
3333
"pretauri:dev:win": "npm run sync:material-icons",
3434
"tauri:dev:win": "npm run doctor:win && tauri dev --config src-tauri/tauri.windows.conf.json",
3535
"pretauri:build:win": "npm run sync:material-icons",

scripts/macos-fix-openssl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ libssl="${openssl_prefix}/lib/libssl.3.dylib"
4545
libcrypto="${openssl_prefix}/lib/libcrypto.3.dylib"
4646
frameworks_dir="${app_path}/Contents/Frameworks"
4747
bin_path="${app_path}/Contents/MacOS/codex-monitor"
48-
daemon_path="${app_path}/Contents/MacOS/codex_monitor_daemon"
48+
daemon_path="${app_path}/Contents/MacOS/codex-monitor-daemon"
4949

5050
if [[ ! -f "${libssl}" || ! -f "${libcrypto}" ]]; then
5151
echo "OpenSSL dylibs not found at ${openssl_prefix}/lib"

src-tauri/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ description = "A Tauri App"
55
authors = ["you"]
66
edition = "2021"
77
default-run = "codex-monitor"
8+
autobins = false
89

910
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1011

1112
[features]
1213
custom-protocol = ["tauri/custom-protocol"]
14+
daemon-binaries = []
1315

1416
[lib]
1517
# The `_lib` suffix may seem redundant but it is necessary
@@ -18,6 +20,20 @@ custom-protocol = ["tauri/custom-protocol"]
1820
name = "codex_monitor_lib"
1921
crate-type = ["staticlib", "cdylib", "rlib"]
2022

23+
[[bin]]
24+
name = "codex-monitor"
25+
path = "src/main.rs"
26+
27+
[[bin]]
28+
name = "codex-monitor-daemon"
29+
path = "src/bin/codex-monitor-daemon.rs"
30+
required-features = ["daemon-binaries"]
31+
32+
[[bin]]
33+
name = "codex-monitor-daemonctl"
34+
path = "src/bin/codex-monitor-daemonctl.rs"
35+
required-features = ["daemon-binaries"]
36+
2137
[build-dependencies]
2238
tauri-build = { version = "2", features = [] }
2339

src-tauri/build.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,61 @@
11
fn main() {
2+
ensure_daemon_sidecar_stub();
23
tauri_build::build();
34

45
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") {
56
println!("cargo:rustc-link-lib=z");
67
println!("cargo:rustc-link-lib=iconv");
78
}
89
}
10+
11+
fn ensure_daemon_sidecar_stub() {
12+
use std::fs;
13+
use std::path::PathBuf;
14+
15+
let target_triple = std::env::var("TARGET").unwrap_or_default();
16+
if target_triple.is_empty() {
17+
return;
18+
}
19+
20+
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default());
21+
if manifest_dir.as_os_str().is_empty() {
22+
return;
23+
}
24+
25+
let extension = if target_triple.contains("windows") {
26+
".exe"
27+
} else {
28+
""
29+
};
30+
let sidecar_path = manifest_dir
31+
.join("target")
32+
.join("sidecars")
33+
.join(format!("codex-monitor-daemon-{target_triple}{extension}"));
34+
35+
if sidecar_path.exists() {
36+
return;
37+
}
38+
39+
if let Some(parent) = sidecar_path.parent() {
40+
let _ = fs::create_dir_all(parent);
41+
}
42+
43+
#[cfg(unix)]
44+
let stub = b"#!/bin/sh\necho \"codex-monitor-daemon sidecar placeholder\" >&2\nexit 1\n";
45+
#[cfg(not(unix))]
46+
let stub = b"";
47+
48+
if fs::write(&sidecar_path, stub).is_err() {
49+
return;
50+
}
51+
52+
#[cfg(unix)]
53+
{
54+
use std::os::unix::fs::PermissionsExt;
55+
if let Ok(metadata) = fs::metadata(&sidecar_path) {
56+
let mut permissions = metadata.permissions();
57+
permissions.set_mode(0o755);
58+
let _ = fs::set_permissions(&sidecar_path, permissions);
59+
}
60+
}
61+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TAURI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
6+
for release_dir in "${TAURI_DIR}/target/release"; do
7+
if [[ -d "${release_dir}" ]]; then
8+
rm -f \
9+
"${release_dir}/codex_monitor_daemon" \
10+
"${release_dir}/codex_monitor_daemon.exe" \
11+
"${release_dir}/codex_monitor_daemonctl" \
12+
"${release_dir}/codex_monitor_daemonctl.exe" \
13+
"${release_dir}/codex_monitor_daemon.d" \
14+
"${release_dir}/codex_monitor_daemonctl.d"
15+
fi
16+
done
17+
18+
bundle_macos_dir="${TAURI_DIR}/target/release/bundle/macos/Codex Monitor.app/Contents/MacOS"
19+
if [[ -d "${bundle_macos_dir}" ]]; then
20+
rm -f \
21+
"${bundle_macos_dir}/codex_monitor_daemon" \
22+
"${bundle_macos_dir}/codex_monitor_daemonctl"
23+
fi
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TAURI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
BINARIES_DIR="${TAURI_DIR}/target/sidecars"
6+
DAEMON_NAME="codex-monitor-daemon"
7+
8+
target_triple="${CARGO_BUILD_TARGET:-}"
9+
10+
if [[ -z "${target_triple}" ]]; then
11+
case "${TAURI_ENV_PLATFORM:-}" in
12+
macos)
13+
case "${TAURI_ENV_ARCH:-}" in
14+
arm64|aarch64) target_triple="aarch64-apple-darwin" ;;
15+
x86_64) target_triple="x86_64-apple-darwin" ;;
16+
esac
17+
;;
18+
linux)
19+
case "${TAURI_ENV_ARCH:-}" in
20+
arm64|aarch64) target_triple="aarch64-unknown-linux-gnu" ;;
21+
x86_64) target_triple="x86_64-unknown-linux-gnu" ;;
22+
esac
23+
;;
24+
windows)
25+
case "${TAURI_ENV_ARCH:-}" in
26+
arm64|aarch64) target_triple="aarch64-pc-windows-msvc" ;;
27+
x86_64) target_triple="x86_64-pc-windows-msvc" ;;
28+
esac
29+
;;
30+
esac
31+
fi
32+
33+
if [[ -z "${target_triple}" ]]; then
34+
target_triple="$(rustc -vV | awk '/^host: / { print $2 }')"
35+
fi
36+
37+
if [[ -z "${target_triple}" ]]; then
38+
echo "Failed to resolve target triple for daemon sidecar packaging"
39+
exit 1
40+
fi
41+
42+
exe_ext=""
43+
if [[ "${target_triple}" == *windows* ]]; then
44+
exe_ext=".exe"
45+
fi
46+
47+
cargo_args=(
48+
build
49+
--release
50+
--features
51+
daemon-binaries
52+
--bin
53+
codex-monitor-daemon
54+
--bin
55+
codex-monitor-daemonctl
56+
)
57+
if [[ -n "${target_triple}" ]]; then
58+
cargo_args+=(--target "${target_triple}")
59+
fi
60+
(cd "${TAURI_DIR}" && cargo "${cargo_args[@]}")
61+
62+
src_candidates=(
63+
"${TAURI_DIR}/target/${target_triple}/release/${DAEMON_NAME}${exe_ext}"
64+
"${TAURI_DIR}/target/release/${DAEMON_NAME}${exe_ext}"
65+
)
66+
67+
daemon_src=""
68+
for candidate in "${src_candidates[@]}"; do
69+
if [[ -f "${candidate}" ]]; then
70+
daemon_src="${candidate}"
71+
break
72+
fi
73+
done
74+
75+
if [[ -z "${daemon_src}" ]]; then
76+
printf 'Daemon binary not found. Looked for:\n'
77+
printf ' %s\n' "${src_candidates[@]}"
78+
exit 1
79+
fi
80+
81+
mkdir -p "${BINARIES_DIR}"
82+
daemon_sidecar="${BINARIES_DIR}/${DAEMON_NAME}-${target_triple}${exe_ext}"
83+
cp -f "${daemon_src}" "${daemon_sidecar}"
84+
chmod +x "${daemon_sidecar}" || true
85+
86+
# Canonical sidecar path used by desktop bundle file mappings.
87+
daemon_canonical="${BINARIES_DIR}/${DAEMON_NAME}${exe_ext}"
88+
cp -f "${daemon_src}" "${daemon_canonical}"
89+
chmod +x "${daemon_canonical}" || true
90+
91+
# Keep daemonctl available in the same canonical sidecar directory for macOS bundle mapping.
92+
daemonctl_name="codex-monitor-daemonctl"
93+
daemonctl_candidates=(
94+
"${TAURI_DIR}/target/${target_triple}/release/${daemonctl_name}${exe_ext}"
95+
"${TAURI_DIR}/target/release/${daemonctl_name}${exe_ext}"
96+
)
97+
daemonctl_src=""
98+
for candidate in "${daemonctl_candidates[@]}"; do
99+
if [[ -f "${candidate}" ]]; then
100+
daemonctl_src="${candidate}"
101+
cp -f "${candidate}" "${BINARIES_DIR}/${daemonctl_name}${exe_ext}"
102+
chmod +x "${BINARIES_DIR}/${daemonctl_name}${exe_ext}" || true
103+
break
104+
fi
105+
done
106+
107+
# Compatibility bridge for current tauri-bundler source lookup.
108+
# Keep these copies only in the resolved target release dir.
109+
release_dir="$(dirname "${daemon_src}")"
110+
cp -f "${daemon_src}" "${release_dir}/codex_monitor_daemon${exe_ext}"
111+
if [[ -n "${daemonctl_src}" ]]; then
112+
cp -f "${daemonctl_src}" "${release_dir}/codex_monitor_daemonctl${exe_ext}"
113+
fi
114+
115+
# If an old bundle directory exists, purge legacy executable names before rebundling.
116+
bundle_macos_dir="${TAURI_DIR}/target/release/bundle/macos/Codex Monitor.app/Contents/MacOS"
117+
if [[ -d "${bundle_macos_dir}" ]]; then
118+
rm -f \
119+
"${bundle_macos_dir}/codex_monitor_daemon" \
120+
"${bundle_macos_dir}/codex_monitor_daemonctl"
121+
fi
122+
123+
echo "Prepared daemon sidecar: ${daemon_sidecar}"

0 commit comments

Comments
 (0)