build_darwin.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. set -e
  3. export VERSION=${VERSION:-$(git describe --tags --first-parent --abbrev=7 --long --dirty --always | sed -e "s/^v//g")}
  4. export GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=$VERSION\" \"-X=github.com/ollama/ollama/server.mode=release\"'"
  5. mkdir -p dist
  6. for TARGETARCH in arm64 amd64; do
  7. rm -rf llm/llama.cpp/build
  8. GOOS=darwin GOARCH=$TARGETARCH go generate ./...
  9. CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -trimpath -o dist/ollama-darwin-$TARGETARCH
  10. CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -C app -trimpath -o ../dist/ollama-app-darwin-$TARGETARCH
  11. done
  12. lipo -create -output dist/ollama dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
  13. lipo -create -output dist/ollama-app dist/ollama-app-darwin-arm64 dist/ollama-app-darwin-amd64
  14. rm -f dist/ollama-darwin-* dist/ollama-app-darwin-*
  15. # create the mac app
  16. rm -rf dist/Ollama.app
  17. cp -R app/darwin/Ollama.app dist/
  18. /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" dist/Ollama.app/Contents/Info.plist
  19. mkdir -p dist/Ollama.app/Contents/MacOS
  20. mv dist/ollama-app dist/Ollama.app/Contents/MacOS/Ollama
  21. cp dist/ollama dist/Ollama.app/Contents/Resources/ollama
  22. # sign and notarize the app
  23. if [ -n "$APPLE_IDENTITY" ]; then
  24. codesign -f --timestamp --options=runtime --sign "$APPLE_IDENTITY" --identifier ai.ollama.ollama dist/Ollama.app/Contents/MacOS/Ollama
  25. codesign -f --timestamp --options=runtime --sign "$APPLE_IDENTITY" --identifier ai.ollama.ollama dist/Ollama.app/Contents/Resources/ollama
  26. codesign -f --timestamp --options=runtime --sign "$APPLE_IDENTITY" --identifier ai.ollama.ollama dist/Ollama.app
  27. ditto -c -k --keepParent dist/Ollama.app dist/Ollama-darwin.zip
  28. rm -rf dist/Ollama.app
  29. xcrun notarytool submit dist/Ollama-darwin.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
  30. unzip dist/Ollama-darwin.zip -d dist
  31. rm -f dist/Ollama-darwin.zip
  32. xcrun stapler staple "dist/Ollama.app"
  33. ditto -c -k --keepParent dist/Ollama.app dist/Ollama-darwin.zip
  34. rm -rf dist/Ollama.app
  35. else
  36. echo "Skipping code signing - set APPLE_IDENTITY"
  37. fi
  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. mv dist/ollama dist/ollama-darwin
  49. rm -f dist/temp.zip