fix: resolve rust_register/unregister at runtime for binary-only hosts
- Replace CARGO_MANIFEST_DIR compile-time constant with runtime resolution
- Priority: MOMENTRY_RUST_* env -> current_exe sibling -> target/release fallback
- Fixes sync-mode register/unregister on release machines (A-1)
Issue: env!("CARGO_MANIFEST_DIR") expands to build machine path at compile time,
which doesn't exist on binary-only release hosts.
Solution: Resolve binary paths at runtime in this order:
1. MOMENTRY_RUST_REGISTER / MOMENTRY_RUST_UNREGISTER env (explicit override)
2. Sibling of current_exe (same directory as running momentry binary)
3. target/release fallback (dev machine)
Verified: M4ProMini deployment (2026-10-04)
This commit is contained in:
+26
-4
@@ -665,8 +665,17 @@ async fn register_file(
|
||||
|
||||
tracing::info!("[REGISTER] Sync mode: calling rust_register for {}", req.file_path);
|
||||
|
||||
let binary_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("target/debug/rust_register");
|
||||
// Resolve rust_register at runtime (see unregister for rationale).
|
||||
let binary_path = std::env::var_os("MOMENTRY_RUST_REGISTER")
|
||||
.map(std::path::PathBuf::from)
|
||||
.filter(|p| p.is_file())
|
||||
.or_else(|| {
|
||||
std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|d| d.join("rust_register")))
|
||||
.filter(|p| p.is_file())
|
||||
})
|
||||
.unwrap_or_else(|| std::path::PathBuf::from("target/release/rust_register"));
|
||||
|
||||
let mut args = vec![req.file_path.clone()];
|
||||
if req.force {
|
||||
@@ -1298,8 +1307,21 @@ async fn unregister(
|
||||
uuid
|
||||
);
|
||||
|
||||
let binary_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("target/debug/rust_unregister");
|
||||
// Resolve rust_unregister at runtime.
|
||||
// env!("CARGO_MANIFEST_DIR") is baked in at compile time and points at the
|
||||
// build machine, so it never exists on a binary-only release host.
|
||||
// Order: explicit env override -> sibling of the running executable ->
|
||||
// dev fallback next to the crate.
|
||||
let binary_path = std::env::var_os("MOMENTRY_RUST_UNREGISTER")
|
||||
.map(std::path::PathBuf::from)
|
||||
.filter(|p| p.is_file())
|
||||
.or_else(|| {
|
||||
std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|d| d.join("rust_unregister")))
|
||||
.filter(|p| p.is_file())
|
||||
})
|
||||
.unwrap_or_else(|| std::path::PathBuf::from("target/release/rust_unregister"));
|
||||
|
||||
let output = std::process::Command::new(&binary_path)
|
||||
.args(["--uuid", &uuid])
|
||||
|
||||
Reference in New Issue
Block a user