Skip to content

Commit 7371d30

Browse files
youknowoneclaude
andcommitted
Fix Windows CI symlink handling in pylib build.rs
On Windows CI with symlink support enabled, the Lib entry is a proper symlink instead of a text file. The build script now handles both cases: 1. Text file containing relative path (git without symlink support) 2. Proper symlink (git with symlink support) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 22569fa commit 7371d30

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

crates/pylib/build.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ fn main() {
1111
process_python_libs("./Lib/**/*");
1212
}
1313

14-
if cfg!(windows)
15-
&& let Ok(real_path) = std::fs::read_to_string("Lib")
16-
{
17-
let canonicalized_path = std::fs::canonicalize(real_path)
18-
.expect("failed to resolve RUSTPYTHONPATH during build time");
19-
// Strip the extended path prefix (\\?\) that canonicalize adds on Windows
20-
let path_str = canonicalized_path.to_str().unwrap();
21-
let path_str = path_str.strip_prefix(r"\\?\").unwrap_or(path_str);
22-
println!("cargo:rustc-env=win_lib_path={path_str}");
14+
if cfg!(windows) {
15+
// On Windows, the Lib entry can be either:
16+
// 1. A text file containing the relative path (git without symlink support)
17+
// 2. A proper symlink (git with symlink support)
18+
// We handle both cases to resolve to the actual Lib directory.
19+
let lib_path = if let Ok(real_path) = std::fs::read_to_string("Lib") {
20+
// Case 1: Text file containing relative path
21+
std::path::PathBuf::from(real_path.trim())
22+
} else {
23+
// Case 2: Symlink or directory - canonicalize directly
24+
std::path::PathBuf::from("Lib")
25+
};
26+
27+
if let Ok(canonicalized_path) = std::fs::canonicalize(&lib_path) {
28+
// Strip the extended path prefix (\\?\) that canonicalize adds on Windows
29+
let path_str = canonicalized_path.to_str().unwrap();
30+
let path_str = path_str.strip_prefix(r"\\?\").unwrap_or(path_str);
31+
println!("cargo:rustc-env=win_lib_path={path_str}");
32+
}
2333
}
2434
}
2535

0 commit comments

Comments
 (0)