From 7d6eb0d4c3fad1fec45d2e111193fbf09fa91bc2 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Wed, 16 Oct 2024 12:49:46 -0700 Subject: [PATCH] Move macos v11 support flags to build script (#7203) Having v11 support hard-coded into the cgo settings causes warnings for newer Xcode versions. This should help keep the build clean for users building from source with the latest tools, while still allow us to target the older OS via our CI processes. --- llama/llama.go | 12 ++++++------ scripts/build_darwin.sh | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/llama/llama.go b/llama/llama.go index 4918a46d..60a19a40 100644 --- a/llama/llama.go +++ b/llama/llama.go @@ -3,12 +3,12 @@ package llama /* #cgo CFLAGS: -O2 -std=c11 -DGGML_BUILD=1 -DNDEBUG -DLOG_DISABLE_LOGS -DGGML_USE_LLAMAFILE #cgo CXXFLAGS: -O2 -std=c++11 -DGGML_BUILD=1 -DNDEBUG -DLOG_DISABLE_LOGS -DGGML_USE_LLAMAFILE -#cgo darwin,arm64 CFLAGS: -DGGML_USE_METAL -DGGML_USE_ACCELERATE -DGGML_METAL_EMBED_LIBRARY -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 -DGGML_USE_BLAS -mmacosx-version-min=11.3 -#cgo darwin,arm64 CXXFLAGS: -DGGML_USE_METAL -DGGML_USE_ACCELERATE -DGGML_METAL_EMBED_LIBRARY -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 -DGGML_USE_BLAS -mmacosx-version-min=11.3 -#cgo darwin,arm64 LDFLAGS: -framework Foundation -framework Metal -framework MetalKit -framework Accelerate -mmacosx-version-min=11.3 -#cgo darwin,amd64 CFLAGS: -Wno-incompatible-pointer-types-discards-qualifiers -mmacosx-version-min=11.3 -#cgo darwin,amd64 CXXFLAGS: -Wno-incompatible-pointer-types-discards-qualifiers -mmacosx-version-min=11.3 -#cgo darwin,amd64 LDFLAGS: -framework Foundation -mmacosx-version-min=11.3 +#cgo darwin,arm64 CFLAGS: -DGGML_USE_METAL -DGGML_USE_ACCELERATE -DGGML_METAL_EMBED_LIBRARY -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 -DGGML_USE_BLAS +#cgo darwin,arm64 CXXFLAGS: -DGGML_USE_METAL -DGGML_USE_ACCELERATE -DGGML_METAL_EMBED_LIBRARY -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 -DGGML_USE_BLAS +#cgo darwin,arm64 LDFLAGS: -framework Foundation -framework Metal -framework MetalKit -framework Accelerate +#cgo darwin,amd64 CFLAGS: -Wno-incompatible-pointer-types-discards-qualifiers +#cgo darwin,amd64 CXXFLAGS: -Wno-incompatible-pointer-types-discards-qualifiers +#cgo darwin,amd64 LDFLAGS: -framework Foundation #cgo darwin,amd64,avx2 CFLAGS: -DGGML_USE_ACCELERATE -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 #cgo darwin,amd64,avx2 CXXFLAGS: -DGGML_USE_ACCELERATE -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 #cgo darwin,amd64,avx2 LDFLAGS: -framework Accelerate diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh index 981f1067..4e914d0f 100755 --- a/scripts/build_darwin.sh +++ b/scripts/build_darwin.sh @@ -16,6 +16,13 @@ for TARGETARCH in arm64 amd64; do rm -rf llm/build GOOS=darwin GOARCH=$TARGETARCH go generate ./... fi + # These require Xcode v13 or older to target MacOS v11 + # If installed to an alternate location use the following to enable + # export SDKROOT=/Applications/Xcode_12.5.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk + # export DEVELOPER_DIR=/Applications/Xcode_12.5.1.app/Contents/Developer + export CGO_CFLAGS=-mmacosx-version-min=11.3 + export CGO_CXXFLAGS=-mmacosx-version-min=11.3 + export CGO_LDFLAGS=-mmacosx-version-min=11.3 CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -trimpath -o dist/ollama-darwin-$TARGETARCH CGO_ENABLED=1 GOOS=darwin GOARCH=$TARGETARCH go build -trimpath -cover -o dist/ollama-darwin-$TARGETARCH-cov done