Fix long cache file path on Windows (#3065)

This commit is contained in:
Cheng
2026-01-27 08:53:26 +09:00
committed by GitHub
parent b70fc33ada
commit 343ddf0d73
2 changed files with 19 additions and 19 deletions
+7 -14
View File
@@ -3,16 +3,12 @@ __pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# tensor files
*.safe
*.safetensors
# Metal libraries
*.metallib
venv/
# Distribution / packaging
python/mlx/core
@@ -30,6 +26,7 @@ lib64/
parts/
sdist/
var/
venv/
wheels/
share/python-wheels/
*.egg-info/
@@ -37,12 +34,7 @@ share/python-wheels/
*.egg
MANIFEST
uv.lock
# vim
*.swp
# Ignore build dir
build/
.DS_Store
# Prerequisites
*.d
@@ -52,6 +44,7 @@ build/
*.lo
*.o
*.obj
*.ilk
# Precompiled Headers
*.gch
@@ -80,9 +73,9 @@ build/
# Debug symbols
*.pdb
# VSCode
# VSCode
.vscode/
.DS_Store
# Jetbrains
.cache
.cache/
# vim
*.swp
+12 -5
View File
@@ -79,6 +79,18 @@ const std::filesystem::path& ptx_cache_dir() {
cache =
std::filesystem::temp_directory_path() / "mlx" / version() / "ptx";
}
#if defined(_WIN32)
// Add "\\?\" prefix to support long file path.
const wchar_t* long_path_prefix = L"\\\\?\\";
if (cache.is_relative()) {
cache = std::filesystem::absolute(cache);
}
if (!cache.native().starts_with(long_path_prefix)) {
cache = long_path_prefix + cache.native();
}
#endif
if (!std::filesystem::exists(cache)) {
std::error_code error;
if (!std::filesystem::create_directories(cache, error)) {
@@ -93,12 +105,7 @@ const std::filesystem::path& ptx_cache_dir() {
std::filesystem::path get_ptx_path(
const std::filesystem::path& cache_dir,
const std::string& module_name) {
#ifdef _WIN32
constexpr int max_file_name_length = 140;
#else
constexpr int max_file_name_length = 245;
#endif
if (module_name.size() <= max_file_name_length) {
return cache_dir / (module_name + ".ptx");
}