Package.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // swift-tools-version:5.5
  2. import PackageDescription
  3. #if arch(arm) || arch(arm64)
  4. let platforms: [SupportedPlatform]? = [
  5. .macOS(.v12),
  6. .iOS(.v14),
  7. .watchOS(.v4),
  8. .tvOS(.v14)
  9. ]
  10. let exclude: [String] = []
  11. let resources: [Resource] = [
  12. .process("ggml-metal.metal")
  13. ]
  14. let additionalSources: [String] = ["ggml-metal.m"]
  15. let additionalSettings: [CSetting] = [
  16. .unsafeFlags(["-fno-objc-arc"]),
  17. .define("GGML_USE_METAL")
  18. ]
  19. #else
  20. let platforms: [SupportedPlatform]? = nil
  21. let exclude: [String] = ["ggml-metal.metal"]
  22. let resources: [Resource] = []
  23. let additionalSources: [String] = []
  24. let additionalSettings: [CSetting] = []
  25. #endif
  26. let package = Package(
  27. name: "llama",
  28. platforms: platforms,
  29. products: [
  30. .library(name: "llama", targets: ["llama"]),
  31. ],
  32. targets: [
  33. .target(
  34. name: "llama",
  35. path: ".",
  36. exclude: exclude,
  37. sources: [
  38. "ggml.c",
  39. "llama.cpp",
  40. "ggml-alloc.c",
  41. "ggml-backend.c",
  42. "ggml-quants.c",
  43. ] + additionalSources,
  44. resources: resources,
  45. publicHeadersPath: "spm-headers",
  46. cSettings: [
  47. .unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
  48. .define("GGML_USE_ACCELERATE")
  49. // NOTE: NEW_LAPACK will required iOS version 16.4+
  50. // We should consider add this in the future when we drop support for iOS 14
  51. // (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
  52. // .define("ACCELERATE_NEW_LAPACK"),
  53. // .define("ACCELERATE_LAPACK_ILP64")
  54. ] + additionalSettings,
  55. linkerSettings: [
  56. .linkedFramework("Accelerate")
  57. ]
  58. )
  59. ],
  60. cxxLanguageStandard: .cxx11
  61. )