build_darwin.sh 2.0 KB

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