Fix ninja build on Windows #295
This file contains 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: build | |
on: push | |
jobs: | |
build: | |
runs-on: >- | |
${{ | |
((matrix.os == 'linux' && matrix.arch == 'arm64') && | |
'ubuntu-24.04-arm' || | |
((matrix.os == 'mac' && matrix.arch == 'arm64') && | |
'macos-15' || | |
(fromJson('{"linux":"ubuntu-24.04","mac":"macos-13","win":"windows-2022"}')[matrix.os]))) | |
}} | |
continue-on-error: false | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [linux, mac, win] | |
arch: [arm64, x64] | |
exclude: | |
- os: win | |
arch: arm64 | |
steps: | |
- name: Install Linux dependencies | |
if: matrix.os == 'linux' | |
run: sudo apt-get install -y ninja-build libblas-dev liblapack-dev liblapacke-dev | |
- name: Install macOS dependencies | |
if: matrix.os == 'mac' | |
run: brew install ninja openblas | |
- name: Install Windows SDK | |
if: matrix.os == 'win' | |
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2 | |
with: | |
sdk-version: 22621 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Install node modules | |
run: yarn | |
- name: Use ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ccache-${{ matrix.os }}-${{ matrix.arch }} | |
- name: Get number of CPU cores | |
uses: SimenB/github-actions-cpu-cores@v2 | |
id: cpu-cores | |
- name: Build (Posix) | |
if: matrix.os != 'win' | |
run: | | |
yarn build -p ${{ steps.cpu-cores.outputs.count }} \ | |
-G Ninja \ | |
--CDCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
--CDCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
- name: Build (Windows) | |
if: matrix.os == 'win' | |
shell: cmd | |
run: | | |
pushd "C:\Program Files (x86)\Microsoft Visual Studio\Installer\" | |
for /f "delims=" %%x in ('.\vswhere.exe -latest -property InstallationPath') do set VSPATH=%%x | |
popd | |
call "%VSPATH%\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.arch }} | |
yarn build -p ${{ steps.cpu-cores.outputs.count }} ^ | |
-G Ninja ^ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache ^ | |
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache ^ | |
-DCMAKE_BUILD_TYPE=Release ^ | |
-DCMAKE_C_COMPILER=cl ^ | |
-DCMAKE_CXX_COMPILER=cl ^ | |
-DCMAKE_RC_COMPILER=cl | |
- name: Test | |
if: matrix.os != 'win' | |
run: yarn test | |
- name: Prepare .node file | |
run: cp build/Release/node_mlx.node mlx-${{ matrix.os }}-${{ matrix.arch }}.node | |
- name: Prepare .metallib file | |
if: matrix.os == 'mac' && matrix.arch == 'arm64' | |
run: cp build/deps/mlx/mlx/backend/metal/kernels/mlx.metallib mlx-${{ matrix.os }}-${{ matrix.arch }}.metallib | |
- name: Upload Binary Files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: mlx-${{ matrix.os }}-${{ matrix.arch }} | |
path: mlx-${{ matrix.os }}-${{ matrix.arch }}.* | |
retention-days: 1 | |
release: | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: [build] | |
runs-on: ubuntu-latest | |
permissions: | |
# Needed by action-gh-release. | |
contents: write | |
steps: | |
- name: Download Files | |
uses: actions/download-artifact@v4 | |
with: | |
merge-multiple: true | |
- name: Compress files | |
run: gzip * | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: true | |
name: node-mlx ${{ github.ref_name }} | |
body: '## Changelog' | |
files: '*.gz' |