ml-explore / mlx-swift

Swift API for MLX
https://ml-explore.github.io/mlx-swift/
MIT License
470 stars 35 forks source link

Add support for cocoapods #58

Open ArshanKhanifar opened 3 months ago

ArshanKhanifar commented 3 months ago

I want to use this library in my react native project, would be awesome if it was also packaged as a cocoapods package.

davidkoski commented 3 months ago

I am not familiar with cocoapods -- is that something you would be interested in contributing?

ArshanKhanifar commented 3 months ago

Already had a jab at it following this blogpost on a fork I made, but had no luck when installing from cocoapods:

pod 'mlx-swift', :git => 'https://github.com/ArshanKhanifar/mlx-swift.git', :branch => 'main', :submodules => true
ArshanKhanifar commented 3 months ago

Here was the error:

Errno::ENOENT - No such file or directory @ rb_check_realpath_internal - /Users/arshankhanifar/ritual/ritual-mlx/example/ios/Pods/mlx-swift/Source/Cmlx/include/mlx
davidkoski commented 3 months ago

That looks like it wasn't checked out with git submodules. Take a look at this:

ArshanKhanifar commented 3 months ago

I ended up flattening the library, and re-running the build here's the error now:

error: Multiple commands produce '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo.png'
    note: Target 'mlx-swift' (project 'Pods') has copy command from '/Users/arshankhanifar/ritual/ritual-mlx/example/ios/Pods/mlx-swift/Source/Cmlx/mlx-c/docs/src/_static/mlx_logo.png' to '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo.png'
    note: Target 'mlx-swift' (project 'Pods') has copy command from '/Users/arshankhanifar/ritual/ritual-mlx/example/ios/Pods/mlx-swift/Source/Cmlx/mlx/docs/src/_static/mlx_logo.png' to '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo.png'
error: Multiple commands produce '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo_dark.png'
    note: Target 'mlx-swift' (project 'Pods') has copy command from '/Users/arshankhanifar/ritual/ritual-mlx/example/ios/Pods/mlx-swift/Source/Cmlx/mlx-c/docs/src/_static/mlx_logo_dark.png' to '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo_dark.png'
    note: Target 'mlx-swift' (project 'Pods') has copy command from '/Users/arshankhanifar/ritual/ritual-mlx/example/ios/Pods/mlx-swift/Source/Cmlx/mlx/docs/src/_static/mlx_logo_dark.png' to '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo_dark.png'
ClangStatCache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.4.sdk /Users/arshankhanifar/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphoneos17.4-21E210-99a79c02cfa501706f5b564e46d84afe.sdkstatcache
[build-log-2.log](https://github.com/ml-explore/mlx-swift/files/14817169/build-log-2.log)

I've also attached the full log:

ArshanKhanifar commented 3 months ago

build-log-2.log

ArshanKhanifar commented 3 months ago

Following this, might work now

ArshanKhanifar commented 3 months ago

no luck, same errors build-log-3.log

davidkoski commented 3 months ago

From looking at the build log it looks like cocoapods is trying to "build" all of the files in the repository -- pngs from the docs, .py files from the python integration, etc. In fact the error seems to be it picking up multiple copies of the logo (e.g. from the docs):

error: Multiple commands produce '/Users/arshankhanifar/Library/Developer/Xcode/DerivedData/RitualMlxExample-cqxikxirjkpdqfeyyjznhtlcwxgq/Build/Products/Debug-iphoneos/mlx-swift/mlx_logo.png'

The build process is fairly complex. If cocoapods can use the swiftpm build or the CMake build you will be much better off. Otherwise you will need to figure out how to get it to compile each of the targets along the same lines as the swiftpm build.

Is there a reason you can't just use the swiftpm build?

ArshanKhanifar commented 3 months ago

I want to create a React Native wrapper for this library, and React Native only works with cocoapods. There's this issue to add support for SPM but they have their own challenges.

tctrautman commented 2 months ago

I'm also hoping to see this be available for React Native apps -- @ArshanKhanifar have you made any progress since this last post?

It sounds like getting cocoapods to work with SPM won't happen anytime soon, which leaves getting the CMake installation to work with cocoapods 😟. Anything you've learned would be appreciated -- my initial research made this sound pretty tricky.