Skip to content

Commit e9815b9

Browse files
committed
Co-locate mlx.metallib with binary and update install
Ensure mlx.metallib is colocated with the executable and make installs/symlinks compatible with Homebrew. Formula: install the binary and mlx.metallib into libexec and create a bin symlink so dladdr-based lookup finds mlx.metallib next to the real executable. Swift: on startup resolve the real executable path and chdir to its directory (resolving symlinks) so metallib lookup succeeds even when the binary is symlinked. Docs: reorganize README Install section with explicit Homebrew, shell script, and manual download instructions.
1 parent f69b340 commit e9815b9

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

Formula/perspective.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ class Perspective < Formula
99
depends_on :macos
1010

1111
def install
12-
bin.install "perspective"
13-
lib.install "mlx.metallib" if File.exist?("mlx.metallib")
12+
# Both files must be colocated — mlx-swift uses dladdr to find mlx.metallib
13+
# next to the binary at runtime. Using libexec keeps them together while
14+
# symlinking the executable into bin/ on the PATH.
15+
libexec.install "perspective"
16+
libexec.install "mlx.metallib" if File.exist?("mlx.metallib")
17+
bin.install_symlink libexec/"perspective"
1418
end
1519

1620
test do

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,25 @@ A lightweight, open-source Swift CLI for running **Apple Foundation Models** and
1717

1818
Foundation Models requires Apple Intelligence to be enabled. MLX mode works on any Apple Silicon Mac.
1919

20-
## Install from Release
20+
## Install
2121

22-
The quickest way to install:
22+
### Homebrew
23+
24+
```bash
25+
brew install techopolis/tap/perspective
26+
```
27+
28+
### Shell Script
29+
30+
The quickest way to install without Homebrew:
2331

2432
```bash
2533
curl -fsSL https://raw.githubusercontent.com/techopolis/PerspectiveCLI/main/scripts/remote-install.sh | bash
2634
```
2735

28-
Or download the latest release archive manually:
36+
### Manual Download
37+
38+
Download the latest release archive from [Releases](https://github.com/techopolis/PerspectiveCLI/releases), then:
2939

3040
```bash
3141
tar xzf perspective-cli-*.tar.gz

Sources/PerspectiveCLI/PerspectiveCLI.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ import FoundationModels
1515
@main
1616
struct PerspectiveCLI {
1717
static func main() async {
18+
// mlx-swift uses dladdr to find mlx.metallib next to the binary.
19+
// When installed via symlink (e.g. Homebrew) or relocated, that lookup
20+
// can fail. Resolve the real executable path and chdir there so the
21+
// colocated metallib search succeeds regardless of install location.
22+
Self.chdirToExecutableDirectory()
23+
1824
await CLIApp.shared.run()
1925
}
26+
27+
/// Change working directory to the real (symlink-resolved) executable directory.
28+
private static func chdirToExecutableDirectory() {
29+
let execPath = ProcessInfo.processInfo.arguments[0]
30+
let execURL = URL(fileURLWithPath: execPath).resolvingSymlinksInPath()
31+
let dir = execURL.deletingLastPathComponent().path
32+
FileManager.default.changeCurrentDirectoryPath(dir)
33+
}
2034
}
2135

2236
// MARK: - Error Types

0 commit comments

Comments
 (0)