mlx-swift icon indicating copy to clipboard operation
mlx-swift copied to clipboard

Add support for cocoapods

Open ArshanKhanifar opened this issue 10 months ago • 11 comments

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

ArshanKhanifar avatar Mar 31 '24 17:03 ArshanKhanifar

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

davidkoski avatar Mar 31 '24 17:03 davidkoski

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 avatar Mar 31 '24 17:03 ArshanKhanifar

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

ArshanKhanifar avatar Mar 31 '24 17:03 ArshanKhanifar

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

  • https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx/troubleshooting#Installation

davidkoski avatar Mar 31 '24 17:03 davidkoski

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 avatar Mar 31 '24 18:03 ArshanKhanifar

Following this, might work now

ArshanKhanifar avatar Mar 31 '24 18:03 ArshanKhanifar

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

ArshanKhanifar avatar Mar 31 '24 18:03 ArshanKhanifar

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?

davidkoski avatar Mar 31 '24 19:03 davidkoski

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.

ArshanKhanifar avatar Apr 04 '24 18:04 ArshanKhanifar

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.

tctrautman avatar Apr 24 '24 03:04 tctrautman