build_darwin.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. set -e
  3. . $(dirname $0)/env.sh
  4. mkdir -p dist
  5. for TARGETARCH in arm64 amd64; do
  6. if [ -n "${OLLAMA_NEW_RUNNERS}" ]; then
  7. echo "Building Go runner darwin $TARGETARCH"
  8. rm -rf llama/build
  9. GOOS=darwin ARCH=$TARGETARCH GOARCH=$TARGETARCH make -C llama -j 8
  10. else
  11. echo "Building C++ runner darwin $TARGETARCH"
  12. rm -rf llm/build
  13. GOOS=darwin GOARCH=$TARGETARCH go generate ./...
  14. fi
  15. # These require Xcode v13 or older to target MacOS v11
  16. # If installed to an alternate location use the following to enable
  17. # export SDKROOT=/Applications/Xcode_12.5.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
  18. # export DEVELOPER_DIR=/Applications/Xcode_12.5.1.app/Contents/Developer
  19. export CGO_CFLAGS=-mmacosx-version-min=11.3
  20. export CGO_CXXFLAGS=-mmacosx-version-min=11.3
  21. export CGO_LDFLAGS=-mmacosx-version-min=11.3
  22. CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -trimpath -o dist/ollama-darwin-$TARGETARCH
  23. CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -trimpath -cover -o dist/ollama-darwin-$TARGETARCH-cov
  24. done
  25. lipo -create -output dist/ollama dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
  26. rm -f dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
  27. if [ -n "$APPLE_IDENTITY" ]; then
  28. codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama
  29. else
  30. echo "Skipping code signing - set APPLE_IDENTITY"
  31. fi
  32. chmod +x dist/ollama
  33. # build and optionally sign the mac app
  34. npm install --prefix macapp
  35. if [ -n "$APPLE_IDENTITY" ]; then
  36. npm run --prefix macapp make:sign
  37. else
  38. npm run --prefix macapp make
  39. fi
  40. cp macapp/out/make/zip/darwin/universal/Ollama-darwin-universal-$VERSION.zip dist/Ollama-darwin.zip
  41. # sign the binary and rename it
  42. if [ -n "$APPLE_IDENTITY" ]; then
  43. codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime dist/ollama
  44. else
  45. echo "WARNING: Skipping code signing - set APPLE_IDENTITY"
  46. fi
  47. ditto -c -k --keepParent dist/ollama dist/temp.zip
  48. if [ -n "$APPLE_IDENTITY" ]; then
  49. xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
  50. fi
  51. mv dist/ollama dist/ollama-darwin
  52. rm -f dist/temp.zip