build_darwin.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. set -e
  3. . $(dirname $0)/env.sh
  4. mkdir -p dist
  5. # These require Xcode v13 or older to target MacOS v11
  6. # If installed to an alternate location use the following to enable
  7. # export SDKROOT=/Applications/Xcode_12.5.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
  8. # export DEVELOPER_DIR=/Applications/Xcode_12.5.1.app/Contents/Developer
  9. export CGO_CPPFLAGS=-mmacosx-version-min=11.3
  10. rm -rf llama/build dist/darwin-*
  11. # Generate the universal ollama binary for stand-alone usage: metal + avx
  12. echo "Building binary"
  13. echo "Building darwin arm64"
  14. GOOS=darwin ARCH=arm64 GOARCH=arm64 make -j 8 dist
  15. echo "Building darwin amd64 with AVX enabled"
  16. GOOS=darwin ARCH=amd64 GOARCH=amd64 CUSTOM_CPU_FLAGS="avx" make -j 8 dist_exe
  17. lipo -create -output dist/ollama-darwin dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama
  18. # sign the binary and rename it
  19. if [ -n "$APPLE_IDENTITY" ]; then
  20. codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime dist/ollama-darwin
  21. else
  22. echo "WARNING: Skipping code signing - set APPLE_IDENTITY"
  23. fi
  24. ditto -c -k --keepParent dist/ollama-darwin dist/temp.zip
  25. if [ -n "$APPLE_IDENTITY" ]; then
  26. xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
  27. fi
  28. rm -f dist/temp.zip
  29. # Build the app bundle
  30. echo "Building app"
  31. echo "Building darwin amd64 with runners"
  32. rm dist/darwin-amd64/bin/ollama
  33. GOOS=darwin ARCH=amd64 GOARCH=amd64 make -j 8 dist
  34. # Generate the universal ollama binary for the app bundle: metal + no-avx
  35. lipo -create -output dist/ollama dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama
  36. # build and optionally sign the mac app
  37. npm install --prefix macapp
  38. if [ -n "$APPLE_IDENTITY" ]; then
  39. npm run --prefix macapp make:sign
  40. else
  41. npm run --prefix macapp make
  42. fi
  43. cp macapp/out/make/zip/darwin/universal/Ollama-darwin-universal-$VERSION.zip dist/Ollama-darwin.zip