ml-explore / mlx-swift

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

ninja failed linking Swift static library libMLX.a #26

Closed CharlieTLe closed 9 months ago

CharlieTLe commented 9 months ago

After following the steps for building with CMake in https://github.com/ml-explore/mlx-swift#cmake, the ninja command fails to run with the output:

$ ninja
[1/8] Linking Swift static library libMLX.a
FAILED: libMLX.a CMakeFiles/MLX.dir/Source/MLX/Cmlx+Util.swift.o CMakeFiles/MLX.dir/Source/MLX/DType.swift.o CMakeFiles/MLX.dir/Source/MLX/Device.swift.o CMakeFiles/MLX.dir/Source/MLX/Factory.swift.o CMakeFiles/MLX.dir/Source/MLX/Foundation+Util.swift.o CMakeFiles/MLX.dir/Source/MLX/MLXArray+Indexing.swift.o CMakeFiles/MLX.dir/Source/MLX/MLXArray+Init.swift.o CMakeFiles/MLX.dir/Source/MLX/MLXArray+Ops.swift.o CMakeFiles/MLX.dir/Source/MLX/MLXArray.swift.o CMakeFiles/MLX.dir/Source/MLX/Nested.swift.o CMakeFiles/MLX.dir/Source/MLX/Ops+Array.swift.o CMakeFiles/MLX.dir/Source/MLX/Ops.swift.o CMakeFiles/MLX.dir/Source/MLX/Protocols.swift.o CMakeFiles/MLX.dir/Source/MLX/Stream.swift.o CMakeFiles/MLX.dir/Source/MLX/Transforms+Compile.swift.o CMakeFiles/MLX.dir/Source/MLX/Transforms+Eval.swift.o CMakeFiles/MLX.dir/Source/MLX/Transforms+Grad.swift.o CMakeFiles/MLX.dir/Source/MLX/Transforms+Internal.swift.o CMakeFiles/MLX.dir/Source/MLX/Transforms.swift.o MLX.swiftmodule
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -j 10 -num-threads 10 -emit-library -static -o libMLX.a -module-name MLX -module-link-name MLX -emit-module -emit-module-path MLX.swiftmodule -emit-dependencies  -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -output-file-map CMakeFiles/MLX.dir//output-file-map.json -I /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/Cmlx/include -I /Users/charliele/Work/repos/github/ml-explore/mlx-swift/build/_deps/mlx-c-src /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Cmlx+Util.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Device.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Factory.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Foundation+Util.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/MLXArray+Indexing.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/MLXArray+Init.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/MLXArray+Ops.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/MLXArray.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Nested.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Ops+Array.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Ops.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Protocols.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Stream.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Transforms+Compile.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Transforms+Eval.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Transforms+Grad.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Transforms+Internal.swift /Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/Transforms.swift    && :
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
/Users/charliele/Work/repos/github/ml-explore/mlx-swift/Source/MLX/DType.swift:4:8: error: no such module 'Numerics'
import Numerics
       ^
error: fatalError
ninja: build stopped: subcommand failed.

It seems like the swift-numerics package is not being checked out which provides the Complex type (according to @davidkoski).

davidkoski commented 9 months ago

So I thought maybe something like this:

FetchContent_Declare(
  swift-numerics
  GIT_REPOSITORY "https://github.com/apple/swift-numerics.git"
  GIT_TAG "1.0.2")
FetchContent_MakeAvailable(swift-numerics)

swift-numerics has a CMakeLists.txt, but it fails to build:

-- Could NOT find swift-numerics (missing: swift-numerics_DIR)
CMake Error at build/_deps/swift-numerics-src/CMakeLists.txt:22 (include):
  include could not find requested file:

    SwiftSupport

CMake Error at build/_deps/swift-numerics-src/Sources/ComplexModule/CMakeLists.txt:21 (_install_target):
  Unknown CMake command "_install_target".

That looks like a failure in the swift-numerics package -- it has a cmake/modules directory with SwiftSupport in it but it isn't finding it.

@andresy looking for advice :-)

davidkoski commented 9 months ago

This should be fixed with #30 and is part of CI with #31.

OK to close?

CharlieTLe commented 9 months ago

Works now, thank you.