build_darwin.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 -trimpath -cover -o dist/ollama-darwin-$TARGETARCH-cov
  11. done
  12. lipo -create -output dist/ollama dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
  13. rm -f dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
  14. if [ -n "$APPLE_IDENTITY" ]; then
  15. codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama
  16. else
  17. echo "Skipping code signing - set APPLE_IDENTITY"
  18. fi
  19. chmod +x dist/ollama
  20. # build and optionally sign the mac app
  21. npm install --prefix macapp
  22. if [ -n "$APPLE_IDENTITY" ]; then
  23. npm run --prefix macapp make:sign
  24. else
  25. npm run --prefix macapp make
  26. fi
  27. cp macapp/out/make/zip/darwin/universal/Ollama-darwin-universal-$VERSION.zip dist/Ollama-darwin.zip
  28. # sign the binary and rename it
  29. if [ -n "$APPLE_IDENTITY" ]; then
  30. codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime dist/ollama
  31. else
  32. echo "WARNING: Skipping code signing - set APPLE_IDENTITY"
  33. fi
  34. ditto -c -k --keepParent dist/ollama dist/temp.zip
  35. if [ -n "$APPLE_IDENTITY" ]; then
  36. xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
  37. fi
  38. mv dist/ollama dist/ollama-darwin
  39. rm -f dist/temp.zip