fix: resolve build errors in zk_c_api.cpp #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test MLX Go Bindings | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test-macos-arm64: | |
| runs-on: macos-14 # M1 Mac runners | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Install dependencies | |
| run: | | |
| # Xcode Command Line Tools should already be installed | |
| xcode-select --print-path | |
| - name: Download pre-built MLX library | |
| run: | | |
| echo "=== Downloading pre-built MLX library ===" | |
| mkdir -p lib | |
| # Try to download from latest release | |
| LATEST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "") | |
| if [ -n "$LATEST_TAG" ]; then | |
| echo "Downloading from release $LATEST_TAG" | |
| gh release download "$LATEST_TAG" -p "libmlx-macos-arm64.tar.gz" 2>/dev/null && \ | |
| tar -xzf libmlx-macos-arm64.tar.gz -C lib/ && \ | |
| echo "✅ Downloaded pre-built library" && exit 0 | |
| fi | |
| echo "⚠️ No pre-built library found, will build from source" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Build MLX C++ library (fallback) | |
| if: hashFiles('lib/libmlx.a') == '' | |
| run: | | |
| echo "=== Building MLX C++ library from source ===" | |
| mkdir -p build && cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DMLX_BUILD_TESTS=OFF \ | |
| -DMLX_BUILD_EXAMPLES=OFF \ | |
| -DMLX_BUILD_PYTHON_BINDINGS=OFF \ | |
| -DMLX_BUILD_METAL=ON | |
| make -j$(sysctl -n hw.ncpu) mlx | |
| cp libmlx.a ../lib/ | |
| - name: Run tests with Metal backend | |
| run: | | |
| echo "=== Testing Metal backend on macOS ARM64 ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: auto # Should detect Metal | |
| - name: Run tests with CPU fallback | |
| run: | | |
| echo "=== Testing CPU fallback on macOS ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: cpu # Force CPU backend | |
| - name: Run benchmarks | |
| run: | | |
| echo "=== Running benchmarks ===" | |
| CGO_ENABLED=1 go test -bench=. -benchtime=1s ./... | |
| test-linux: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Install build dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential gcc g++ cmake | |
| - name: Download pre-built MLX library | |
| run: | | |
| echo "=== Downloading pre-built MLX library ===" | |
| mkdir -p lib | |
| LATEST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "") | |
| if [ -n "$LATEST_TAG" ]; then | |
| echo "Downloading from release $LATEST_TAG" | |
| gh release download "$LATEST_TAG" -p "libmlx-linux-x64.tar.gz" 2>/dev/null && \ | |
| tar -xzf libmlx-linux-x64.tar.gz -C lib/ && \ | |
| echo "✅ Downloaded pre-built library" && exit 0 | |
| fi | |
| echo "⚠️ No pre-built library found, will build from source" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Build MLX C++ library (fallback) | |
| if: hashFiles('lib/libmlx.a') == '' | |
| run: | | |
| echo "=== Building MLX C++ library from source ===" | |
| mkdir -p build && cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DMLX_BUILD_TESTS=OFF \ | |
| -DMLX_BUILD_EXAMPLES=OFF \ | |
| -DMLX_BUILD_PYTHON_BINDINGS=OFF \ | |
| -DMLX_BUILD_METAL=OFF | |
| make -j$(nproc) mlx | |
| mkdir -p ../lib | |
| cp libmlx.a ../lib/ | |
| - name: Run tests with CPU backend | |
| run: | | |
| echo "=== Testing CPU backend on Linux ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: cpu # Force CPU backend | |
| - name: Run benchmarks | |
| run: | | |
| echo "=== Running CPU benchmarks on Linux ===" | |
| CGO_ENABLED=1 go test -bench=. -benchtime=1s ./... | |
| env: | |
| MLX_BACKEND: cpu | |
| - name: Test auto-detection (should select CPU) | |
| run: | | |
| echo "=== Testing auto backend detection on Linux ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: auto # Should detect CPU on Linux without CUDA | |
| test-windows: | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Set up MinGW | |
| uses: egor-tensin/setup-mingw@v2 | |
| with: | |
| platform: x64 | |
| - name: Install CMake | |
| run: choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y | |
| - name: Download pre-built MLX library | |
| shell: bash | |
| run: | | |
| echo "=== Downloading pre-built MLX library ===" | |
| mkdir -p lib | |
| LATEST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "") | |
| if [ -n "$LATEST_TAG" ]; then | |
| echo "Downloading from release $LATEST_TAG" | |
| gh release download "$LATEST_TAG" -p "libmlx-windows-x64.tar.gz" 2>/dev/null && \ | |
| tar -xzf libmlx-windows-x64.tar.gz -C lib/ && \ | |
| echo "✅ Downloaded pre-built library" && exit 0 | |
| fi | |
| echo "⚠️ No pre-built library found, will build from source" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Build MLX C++ library (fallback) | |
| if: hashFiles('lib/libmlx.a') == '' | |
| shell: bash | |
| run: | | |
| echo "=== Building MLX C++ library from source ===" | |
| mkdir -p build && cd build | |
| cmake .. \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DMLX_BUILD_TESTS=OFF \ | |
| -DMLX_BUILD_EXAMPLES=OFF \ | |
| -DMLX_BUILD_PYTHON_BINDINGS=OFF \ | |
| -DMLX_BUILD_METAL=OFF \ | |
| -G "MinGW Makefiles" | |
| cmake --build . --target mlx -j | |
| mkdir -p ../lib | |
| cp libmlx.a ../lib/ | |
| - name: Run tests with CPU backend | |
| shell: bash | |
| run: | | |
| echo "=== Testing CPU backend on Windows ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: cpu # Force CPU backend | |
| - name: Run benchmarks | |
| shell: bash | |
| run: | | |
| echo "=== Running CPU benchmarks on Windows ===" | |
| CGO_ENABLED=1 go test -bench=. -benchtime=1s ./... | |
| env: | |
| MLX_BACKEND: cpu | |
| - name: Test auto-detection (should select CPU) | |
| shell: bash | |
| run: | | |
| echo "=== Testing auto backend detection on Windows ===" | |
| CGO_ENABLED=1 go test -v -timeout 30s ./... | |
| env: | |
| MLX_BACKEND: auto # Should detect CPU on Windows without CUDA |