-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7f008bb
Showing
12 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: build | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: >- | ||
${{ | ||
(matrix.os == 'mac' && matrix.arch == 'arm64') && | ||
'macos-14' || | ||
(fromJson('{"linux":"ubuntu-22.04","mac":"macos-13","win":"windows-2022"}')[matrix.os]) | ||
}} | ||
continue-on-error: false | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [linux, mac] | ||
arch: [arm64, x64] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build | ||
if: matrix.os != 'linux' || matrix.arch == runner.arch | ||
run: | | ||
yarn | ||
yarn build | ||
- name: Set up QEMU | ||
if: matrix.os == 'linux' && matrix.arch != runner.arch | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platform: matrix.arch | ||
|
||
- name: Enable multi-arch containers in QEMU | ||
if: matrix.os == 'linux' && matrix.arch != runner.arch | ||
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | ||
|
||
- name: Build (in docker) | ||
if: matrix.os == 'linux' && matrix.arch != runner.arch | ||
uses: addnab/docker-run-action@v3 | ||
with: | ||
image: node:lts-alpine | ||
options: --platform=linux/${{ matrix.arch }} -v ${{ github.workspace }}:/build -w /build | ||
run: | | ||
yarn | ||
yarn build |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# TypeScript compiled files | ||
/dist/ | ||
|
||
# Everything else should keep same with .npmignore | ||
*.swp | ||
*.zip | ||
|
||
yarn.lock | ||
package-lock.json | ||
npm-debug.log | ||
yarn-error.log | ||
/node_modules/ | ||
/build/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "deps/mlx"] | ||
path = deps/mlx | ||
url = https://github.com/ml-explore/mlx | ||
[submodule "deps/kizunapi"] | ||
path = deps/kizunapi | ||
url = https://github.com/photoionization/kizunapi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Unused source files | ||
/src/ | ||
.github | ||
tsconfig.json | ||
|
||
# Everything else should keep same with .gitignore | ||
*.swp | ||
*.zip | ||
|
||
yarn.lock | ||
package-lock.json | ||
npm-debug.log | ||
/node_modules/ | ||
/build/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Required by cmake-js. | ||
# https://github.com/cmake-js/cmake-js#node-api-and-node-addon-api | ||
cmake_minimum_required(VERSION 3.15) | ||
cmake_policy(SET CMP0091 NEW) | ||
cmake_policy(SET CMP0042 NEW) | ||
|
||
# Define project name. | ||
project(node-mlx) | ||
|
||
# Use C++17. | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Define NAPI_VERSION. | ||
add_definitions(-DNAPI_VERSION=9) | ||
|
||
# Use cmake-js. | ||
add_library(${PROJECT_NAME} SHARED ${CMAKE_JS_SRC}) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC}) | ||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" 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}) | ||
endif() | ||
|
||
# Add source files. | ||
file(GLOB SOURCE_FILES "src/*") | ||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES}) | ||
|
||
# Use kizunapi. | ||
target_include_directories(${PROJECT_NAME} PRIVATE "deps/kizunapi") | ||
|
||
# Link with MLX. | ||
option(MLX_BUILD_TESTS "Build tests for mlx" OFF) | ||
option(MLX_BUILD_EXAMPLES "Build examples for mlx" OFF) | ||
option(MLX_ENABLE_X64_MAC "Enable building for x64 macOS" ON) | ||
add_subdirectory(deps/mlx) | ||
target_link_libraries(${PROJECT_NAME} mlx) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright © 2023 Apple Inc. | ||
Copyright © 2024 zcbenz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# node-mlx | ||
|
||
:construction: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require(__dirname + '/../build/Release/node-mlx.node') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@frost-beta/mlx", | ||
"version": "0.0.1", | ||
"description": "Node-API bindings for MLX", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"install": "prebuild-install -r napi || echo 'No prebuilt binary of MLX found.'", | ||
"build": "cmake-js build" | ||
}, | ||
"author": "zcbenz", | ||
"license": "MIT", | ||
"dependencies": { | ||
"prebuild-install": "7.1.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/frost-beta/node-mlx" | ||
}, | ||
"binary": { | ||
"napi_versions": [ | ||
9 | ||
] | ||
}, | ||
"devDependencies": { | ||
"cmake-js": "7.3.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <kizunapi.h> | ||
|
||
namespace { | ||
|
||
napi_value Init(napi_env env, napi_value exports) { | ||
return exports; | ||
} | ||
|
||
} // namespace | ||
|
||
NAPI_MODULE(mlx, Init) |