[PR #14322] [MERGED] mlx: try loading library via rpath before searching directories #14618

Closed
opened 2026-04-13 00:59:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14322
Author: @natl-set
Created: 2/19/2026
Status: Merged
Merged: 2/19/2026
Merged by: @pdevine

Base: mainHead: mlx-rpath-loading


📝 Commits (1)

  • 0792a0c mlx: try loading library via rpath before searching directories

📊 Changes

1 file changed (+29 additions, -0 deletions)

View changed files

📝 x/mlxrunner/mlx/dynamic.go (+29 -0)

📄 Description

Problem

The existing code in x/mlxrunner/mlx/dynamic.go manually searches directories for libmlxc.* and passes full paths to dlopen, bypassing the binary's rpath. This means MLX libraries installed via package managers (e.g., Homebrew) aren't found even when rpath is correctly set at link time.

Solution

This PR adds a fallback that tries loading via rpath first (using just the library name), before falling back to the existing directory search. This follows standard Unix/macOS conventions and works with any installation that sets rpath.

Changes

  • Added tryLoadByName() function that attempts to load libmlxc.dylib (or libmlxc.so on Linux) using just the library name
  • This allows the system to use rpath, LD_LIBRARY_PATH, or standard search paths
  • Falls back to existing directory search if rpath loading fails

Benefits

  • Homebrew users: Works out of the box without requiring OLLAMA_LIBRARY_PATH environment variable
  • Other package managers: Any installation that sets rpath correctly will work
  • No breaking changes: Existing behavior (OLLAMA_LIBRARY_PATH, directory search) still works as fallback
  • Standards compliant: Uses standard OS library loading mechanisms

Testing

  • Tested on macOS with Homebrew-installed mlx-c
  • ollama --version no longer shows MLX warning
  • Library loads correctly via rpath set at build time

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14322 **Author:** [@natl-set](https://github.com/natl-set) **Created:** 2/19/2026 **Status:** ✅ Merged **Merged:** 2/19/2026 **Merged by:** [@pdevine](https://github.com/pdevine) **Base:** `main` ← **Head:** `mlx-rpath-loading` --- ### 📝 Commits (1) - [`0792a0c`](https://github.com/ollama/ollama/commit/0792a0cd9be2def7ef0f49e8a501756b9ddc6201) mlx: try loading library via rpath before searching directories ### 📊 Changes **1 file changed** (+29 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `x/mlxrunner/mlx/dynamic.go` (+29 -0) </details> ### 📄 Description ## Problem The existing code in `x/mlxrunner/mlx/dynamic.go` manually searches directories for `libmlxc.*` and passes full paths to `dlopen`, bypassing the binary's rpath. This means MLX libraries installed via package managers (e.g., Homebrew) aren't found even when rpath is correctly set at link time. ## Solution This PR adds a fallback that tries loading via rpath first (using just the library name), before falling back to the existing directory search. This follows standard Unix/macOS conventions and works with any installation that sets rpath. ## Changes - Added `tryLoadByName()` function that attempts to load `libmlxc.dylib` (or `libmlxc.so` on Linux) using just the library name - This allows the system to use rpath, `LD_LIBRARY_PATH`, or standard search paths - Falls back to existing directory search if rpath loading fails ## Benefits - **Homebrew users**: Works out of the box without requiring `OLLAMA_LIBRARY_PATH` environment variable - **Other package managers**: Any installation that sets rpath correctly will work - **No breaking changes**: Existing behavior (OLLAMA_LIBRARY_PATH, directory search) still works as fallback - **Standards compliant**: Uses standard OS library loading mechanisms ## Testing - Tested on macOS with Homebrew-installed mlx-c - `ollama --version` no longer shows MLX warning - Library loads correctly via rpath set at build time --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 00:59:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14618