Skip to content

Commit 97c292f

Browse files
committed
fix: conditional compilation for windows
1 parent 3943f4c commit 97c292f

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

Cargo.lock

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ tiktoken-rs = "0.6.0"
2121
# Configure cargo crate to vendor openssl to avoid system mismatches
2222
cargo = { version = "0.86.0", default-features = false, features = ["vendored-openssl"] }
2323
tempfile = "3.19.1"
24-
xdg = { version = "2.5.2", features = ["serde"] }
2524
anyhow = "1.0.97"
2625
schemars = "0.8.22"
26+
27+
28+
# --- Platform Specific Dependencies ---
29+
30+
[target.'cfg(not(target_os = "windows"))'.dependencies]
31+
xdg = { version = "2.5.2", features = ["serde"] }
32+
33+
[target.'cfg(target_os = "windows")'.dependencies]
34+
dirs = "6.0.0"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44

55

6+
**Like this project? Please [star the repository](https://github.com/Govcraft/rust-docs-mcp-server) on GitHub to show your support and stay updated!**
7+
68
## Motivation
79

810
Modern AI-powered coding assistants (like Cursor, Cline, Roo Code, etc.) excel at understanding code structure and syntax but often struggle with the specifics of rapidly evolving libraries and frameworks, especially in ecosystems like Rust where crates are updated frequently. Their training data cutoff means they may lack knowledge of the latest APIs, leading to incorrect or outdated code suggestions.

src/main.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::{
2727
io::BufReader,
2828
path::PathBuf,
2929
};
30+
#[cfg(not(target_os = "windows"))]
3031
use xdg::BaseDirectories;
3132

3233
// No changes needed below this line until server initialization/running
@@ -69,19 +70,35 @@ async fn main() -> Result<(), ServerError> {
6970
eprintln!("Target Spec: {}, Parsed Name: {}, Version Req: {}", specid_str, crate_name, crate_version_req); // Use eprintln
7071

7172
// --- Determine Paths ---
72-
let xdg_dirs = BaseDirectories::with_prefix("rustdocs-mcp-server")
73-
.map_err(|e| ServerError::Xdg(format!("Failed to get XDG directories: {}", e)))?;
7473

75-
// Sanitize the version requirement string for use in the path
74+
// Sanitize the version requirement string for use in the path (needed for both paths)
7675
let sanitized_version_req = crate_version_req.replace(|c: char| !c.is_alphanumeric() && c != '.' && c != '-', "_");
7776

78-
// Construct the path for embeddings file, including the sanitized version requirement
77+
// Construct the relative path component (needed for both paths)
7978
let embeddings_relative_path = PathBuf::from(&crate_name)
8079
.join(&sanitized_version_req) // Add sanitized version req as a directory
8180
.join("embeddings.bin");
82-
let embeddings_file_path = xdg_dirs
83-
.place_data_file(embeddings_relative_path)
84-
.map_err(ServerError::Io)?;
81+
82+
#[cfg(not(target_os = "windows"))]
83+
let embeddings_file_path = {
84+
let xdg_dirs = BaseDirectories::with_prefix("rustdocs-mcp-server")
85+
.map_err(|e| ServerError::Xdg(format!("Failed to get XDG directories: {}", e)))?;
86+
xdg_dirs
87+
.place_data_file(embeddings_relative_path)
88+
.map_err(ServerError::Io)?
89+
};
90+
91+
#[cfg(target_os = "windows")]
92+
let embeddings_file_path = {
93+
let cache_dir = dirs::cache_dir().ok_or_else(|| {
94+
ServerError::Config("Could not determine cache directory on Windows".to_string())
95+
})?;
96+
let app_cache_dir = cache_dir.join("rustdocs-mcp-server");
97+
// Ensure the base app cache directory exists
98+
fs::create_dir_all(&app_cache_dir).map_err(ServerError::Io)?;
99+
app_cache_dir.join(embeddings_relative_path)
100+
};
101+
85102

86103
eprintln!("Cache file path: {:?}", embeddings_file_path); // Use eprintln
87104

0 commit comments

Comments
 (0)