build_darwin.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_CFLAGS=-mmacosx-version-min=11.3
  10. export CGO_CXXFLAGS=-mmacosx-version-min=11.3
  11. export CGO_LDFLAGS=-mmacosx-version-min=11.3
  12. rm -rf llama/build dist/darwin-*
  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. # Generate the universal ollama binary for stand-alone usage: metal + avx
  18. lipo -create -output dist/ollama-darwin dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama
  19. echo "Building darwin amd64 with runners"
  20. rm dist/darwin-amd64/bin/ollama
  21. GOOS=darwin ARCH=amd64 GOARCH=amd64 make -j 8 dist
  22. # Generate the universal ollama binary for the app bundle: metal + no-avx
  23. lipo -create -output dist/ollama dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama
  24. if [ -n "$APPLE_IDENTITY" ]; then
  25. codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama
  26. else
  27. echo "Skipping code signing - set APPLE_IDENTITY"
  28. fi
  29. chmod +x dist/ollama
  30. # build and optionally sign the mac app
  31. npm install --prefix macapp
  32. if [ -n "$APPLE_IDENTITY" ]; then
  33. npm run --prefix macapp make:sign
  34. else
  35. npm run --prefix macapp make
  36. fi
  37. cp macapp/out/make/zip/darwin/universal/Ollama-darwin-universal-$VERSION.zip dist/Ollama-darwin.zip
  38. # sign the binary and rename it
  39. if [ -n "$APPLE_IDENTITY" ]; then
  40. codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime dist/ollama
  41. else
  42. echo "WARNING: Skipping code signing - set APPLE_IDENTITY"
  43. fi
  44. ditto -c -k --keepParent dist/ollama dist/temp.zip
  45. if [ -n "$APPLE_IDENTITY" ]; then
  46. xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
  47. fi
  48. rm -f dist/temp.zip