From f79292f86760a71bc2b8c3db5ad5166830c2818b Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 13:40:46 +0800 Subject: [PATCH] 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) --- src/api/files.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/api/files.rs b/src/api/files.rs index 51a8940c..be7901ca 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -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])