Skip to content

Commit

Permalink
Fix ninja build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Feb 8, 2025
1 parent f67b797 commit f69c8c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ jobs:
arch: arm64

steps:
- name: Install linux dependencies
- name: Install Linux dependencies
if: matrix.os == 'linux'
run: sudo apt-get install -y ninja-build libblas-dev liblapack-dev liblapacke-dev

- name: Install mac dependencies
- 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:
Expand Down Expand Up @@ -61,15 +67,26 @@ jobs:
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 }} ^
--CDCMAKE_BUILD_TYPE=Release
-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/mlx.node mlx-${{ matrix.os }}-${{ matrix.arch }}.node
run: cp build/Release/node_mlx.node mlx-${{ matrix.os }}-${{ matrix.arch }}.node

- name: Prepare .metallib file
if: matrix.os == 'mac' && matrix.arch == 'arm64'
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE "." ${CMAKE_JS_INC})
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
set_target_properties(${PROJECT_NAME} PROPERTIES
PREFIX ""
OUTPUT_NAME "mlx"
OUTPUT_NAME "node_mlx"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Release"
SUFFIX ".node")
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
target_link_libraries(${PROJECT_NAME} delayimp)
endif()

# Add source files.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The core APIs are in native bindings.
const core = require(__dirname + '/build/Release/mlx.node');
const core = require(__dirname + '/build/Release/node_mlx.node');

// Helper for creating complex number.
core.Complex = (re, im) => {
Expand Down
2 changes: 1 addition & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
const version = packageJson.version;

const prefix = `${urlPrefix}/v${version}/mlx-${os}-${arch}`;
const tasks = [ download(`${prefix}.node.gz`, path.join(dir, 'mlx.node')) ];
const tasks = [ download(`${prefix}.node.gz`, path.join(dir, 'node_mlx.node')) ];
if (os == 'mac' && arch == 'arm64')
tasks.push(download(`${prefix}.metallib.gz`, path.join(dir, 'mlx.metallib')));
await Promise.all(tasks);
Expand Down

0 comments on commit f69c8c4

Please sign in to comment.