build_darwin.sh 2.0 KB

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