Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit c38f3cb

Browse files
committed
Fix setup tool to use Cargo environment variables
- Use CARGO_MANIFEST_DIR for reliable repo root detection - Use CARGO_TARGET_DIR for correct target directory in workspace - Remove fragile directory traversal fallbacks - Require running via 'cargo setup' with clear error message - Properly handle workspace member structure (setup/ -> workspace root) Fixes workspace compatibility issues where binary was expected at server/target/ instead of workspace target/ directory.
1 parent d7b0f84 commit c38f3cb

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

setup/src/main.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,18 @@ fn detect_available_tools() -> Result<CLITool> {
212212
}
213213

214214
fn get_repo_root() -> Result<PathBuf> {
215-
let current_exe = std::env::current_exe()
216-
.context("Failed to get current executable path")?;
217-
218-
// Navigate up from target/debug/setup or target/release/setup to repo root
219-
let mut path = current_exe.parent()
220-
.and_then(|p| p.parent()) // target/
221-
.and_then(|p| p.parent()) // repo root
222-
.ok_or_else(|| anyhow!("Could not determine repository root"))?;
223-
224-
// If we're running via cargo run, we might be in a different location
225-
// Try to find Cargo.toml in current dir or parents
226-
let mut current = std::env::current_dir().context("Failed to get current directory")?;
227-
loop {
228-
if current.join("Cargo.toml").exists() && current.join("server").exists() {
229-
path = &current;
230-
break;
231-
}
232-
if let Some(parent) = current.parent() {
233-
current = parent.to_path_buf();
234-
} else {
235-
break;
215+
// Require CARGO_MANIFEST_DIR - only available when running via cargo
216+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
217+
.context("❌ Setup tool must be run via cargo (e.g., 'cargo setup'). CARGO_MANIFEST_DIR not found.")?;
218+
219+
let manifest_path = PathBuf::from(manifest_dir);
220+
// If we're in a workspace member (like setup/), go up to workspace root
221+
if manifest_path.file_name() == Some(std::ffi::OsStr::new("setup")) {
222+
if let Some(parent) = manifest_path.parent() {
223+
return Ok(parent.to_path_buf());
236224
}
237225
}
238-
239-
Ok(path.to_path_buf())
226+
Ok(manifest_path)
240227
}
241228

242229
fn install_rust_server() -> Result<PathBuf> {
@@ -303,8 +290,12 @@ fn build_rust_server() -> Result<PathBuf> {
303290
return Err(anyhow!("❌ Failed to build Rust server:\n Error: {}", stderr.trim()));
304291
}
305292

293+
// Use CARGO_TARGET_DIR if set, otherwise use workspace default
294+
let target_dir = std::env::var("CARGO_TARGET_DIR")
295+
.unwrap_or_else(|_| repo_root.join("target").to_string_lossy().to_string());
296+
306297
// Verify the binary exists
307-
let binary_path = server_dir.join("target").join("release").join("dialectic-mcp-server");
298+
let binary_path = PathBuf::from(target_dir).join("release").join("dialectic-mcp-server");
308299
if !binary_path.exists() {
309300
return Err(anyhow!("❌ Build verification failed: Built binary not found at {}", binary_path.display()));
310301
}

0 commit comments

Comments
 (0)