Fix metallib path for cargo install — use stable ~/.mlx/ directory - #328
Open
rgbkrk wants to merge 1 commit into
Open
Fix metallib path for cargo install — use stable ~/.mlx/ directory#328rgbkrk wants to merge 1 commit into
cargo install — use stable ~/.mlx/ directory#328rgbkrk wants to merge 1 commit into
Conversation
Collaborator
|
Would you please rebase onto the main branch? I'll try to take a look this weekend. |
Copy mlx.metallib to a stable versioned directory (~/.mlx/lib/v{version}/)
during the CMake build by overriding MLX_METAL_PATH. The compiled-in
METAL_PATH fallback now survives cargo install temp dir cleanup.
Previously, METAL_PATH pointed to the CMake build directory inside
Cargo's temp workspace. When cargo install copies only the binary and
deletes the temp dir, the metallib becomes unreachable at runtime:
MLX error: Failed to load the default metallib.
Fixes oxiglade#327
rgbkrk
force-pushed
the
fix/metallib-cargo-install-v0.25
branch
from
March 20, 2026 06:51
cbf768f to
6ed5172
Compare
Author
|
done |
rgbkrk
added a commit
to rgbkrk/mlx-rs
that referenced
this pull request
Mar 22, 2026
Cherry-picked metallib cargo install fix from PR oxiglade#328. Stable metallib path at ~/.mlx/lib/v{version}/ survives cargo install temp dir cleanup.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a binary using mlx-rs is installed via
cargo install, it fails at runtime:cargo installbuilds in a temporary directory, then copies only the binary to~/.cargo/bin/. The CMake build bakesMETAL_PATHas an absolute path to the metallib inside this temp dir. After install, the temp dir is deleted and the metallib is unreachable.Fix
Override
MLX_METAL_PATHin the CMake config to point to a stable versioned directory:~/.mlx/lib/v{mlx-sys-version}/. The directory is created before CMake runs so CMake outputs the compiled metallib there directly. The compiled-inMETAL_PATHnow survives temp dir cleanup.MLX's runtime metallib search order:
METAL_PATHcompiled-in fallback → now points to~/.mlx/lib/v0.2.0/mlx.metallib✅Testing
Tested with the voice TTS crate:
Fixes #327
Note: this PR is based on the v0.25.3 tag. Happy to rebase onto main if preferred — the
build.rson main has additional changes (clang_rt workaround) but the fix is the same.