build_darwin.sh 1.8 KB

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