Skip to content

Commit 29a5d8b

Browse files
[JS] Setup genai nodejs bindings compilation for macos (#1738)
CVS-161879 --------- Signed-off-by: Kirill Suvorov <[email protected]>
1 parent ce5fb83 commit 29a5d8b

File tree

3 files changed

+140
-2
lines changed

3 files changed

+140
-2
lines changed

.github/workflows/mac.yml

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
ov_artifact_name: ${{ steps.openvino_download.outputs.ov_artifact_name }}
3030
ov_wheel_source: ${{ steps.openvino_download.outputs.ov_wheel_source }}
3131
ov_version: ${{ steps.openvino_download.outputs.ov_version }}
32+
ov_latest_artifact_name: ${{ steps.openvino_latest_download.outputs.ov_artifact_name }}
3233
timeout-minutes: 10
3334
defaults:
3435
run:
@@ -47,6 +48,13 @@ jobs:
4748
platform: macos_12_6
4849
commit_packages_to_provide: wheels
4950
revision: latest_nightly
51+
52+
- uses: openvinotoolkit/openvino/.github/actions/openvino_provider@master
53+
id: openvino_latest_download
54+
with:
55+
platform: macos_12_6
56+
commit_packages_to_provide: openvino_js_package.tar.gz
57+
revision: latest_available_commit
5058

5159
genai_build_cmake:
5260
name: Build cpack - ${{ matrix.build-type }}
@@ -268,7 +276,61 @@ jobs:
268276
name: genai_samples_${{ matrix.build-type }}
269277
path: ${{ env.INSTALL_DIR }}
270278
if-no-files-found: 'error'
271-
279+
280+
genai_build_nodejs:
281+
name: Build Node.js bindings
282+
strategy:
283+
fail-fast: false
284+
matrix:
285+
build-type: [Release]
286+
needs: [ openvino_download ]
287+
timeout-minutes: 30
288+
defaults:
289+
run:
290+
shell: bash
291+
runs-on: macos-13
292+
293+
env:
294+
SRC_DIR: ${{ github.workspace }}/openvino.genai
295+
BUILD_DIR: ${{ github.workspace }}/build
296+
INSTALL_DIR: ${{ github.workspace }}/openvino.genai/src/js/bin
297+
OV_INSTALL_DIR: ${{ github.workspace }}/ov
298+
299+
steps:
300+
- name: Clone openvino.genai
301+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
302+
with:
303+
submodules: recursive
304+
path: ${{ env.SRC_DIR }}
305+
306+
- name: Download OpenVINO package
307+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
308+
with:
309+
name: ${{ needs.openvino_download.outputs.ov_latest_artifact_name }}
310+
path: ${{ env.OV_INSTALL_DIR }}
311+
merge-multiple: true
312+
313+
- name: Install build dependencies
314+
run: brew install coreutils
315+
316+
- name: Build GenAI Node.js bindings
317+
run: |
318+
source ${{ env.OV_INSTALL_DIR }}/setupvars.sh
319+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
320+
-DENABLE_JS=ON -DCPACK_GENERATOR=NPM \
321+
-DENABLE_PYTHON=OFF -DENABLE_WHEEL=OFF \
322+
-S ${{ env.SRC_DIR }} -B ${{ env.BUILD_DIR }}
323+
cmake --build ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --parallel --verbose
324+
cmake --install ${{ env.BUILD_DIR }} --config ${{ matrix.build-type }} --prefix ${{ env.INSTALL_DIR }}
325+
326+
- name: Upload Node.js bindings Build Package
327+
if: always()
328+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
329+
with:
330+
name: genai_nodejs_bindings
331+
path: ${{ env.INSTALL_DIR }}
332+
if-no-files-found: 'error'
333+
272334
genai_tests_wheel:
273335
name: Python (${{ matrix.test.name}}) Tests (wheel)
274336
needs: [ openvino_download, genai_build_wheel ]
@@ -397,6 +459,74 @@ jobs:
397459
SAMPLES_PY_DIR: "${{ env.INSTALL_DIR }}/samples/python"
398460
SAMPLES_CPP_DIR: "${{ env.INSTALL_DIR }}/samples_bin"
399461

462+
genai_nodejs_tests:
463+
name: Node.js bindings tests
464+
needs: [ openvino_download, genai_build_nodejs ]
465+
timeout-minutes: 20
466+
defaults:
467+
run:
468+
shell: bash
469+
runs-on: macos-13
470+
471+
env:
472+
SRC_DIR: ${{ github.workspace }}/openvino.genai
473+
INSTALL_DIR: ${{ github.workspace }}/install
474+
NODE_VERSION: 21
475+
476+
steps:
477+
- name: Clone openvino.genai
478+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
479+
with:
480+
path: ${{ env.SRC_DIR }}
481+
submodules: recursive
482+
483+
- name: Download OpenVINO Artifacts
484+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
485+
with:
486+
name: ${{ needs.openvino_download.outputs.ov_latest_artifact_name }}
487+
path: ${{ env.INSTALL_DIR }}
488+
merge-multiple: true
489+
490+
- name: Download GenAI JS Bildings Artifacts
491+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
492+
with:
493+
name: genai_nodejs_bindings
494+
path: ${{ env.SRC_DIR }}/src/js/bin
495+
merge-multiple: true
496+
497+
- name: Setup Node ${{ env.NODE_VERSION }}
498+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
499+
with:
500+
node-version: ${{ env.NODE_VERSION }}
501+
502+
# JS pacakges uses the OpenVINO and OpenVINO GenAI libraries from the bin directory.
503+
# Here we emulate the installation of the openvino-node package from NPM. The latest
504+
# release of the openvino-node package is installed, and we need to update the binaries
505+
# in the node_modules/openvino-node/bin directory to work correctly with GenAI
506+
- name: Install npm package tests dependencies
507+
working-directory: ${{ env.SRC_DIR }}/src/js
508+
run: |
509+
npm install --verbose
510+
rm -rf node_modules/openvino-node/bin
511+
cp -R ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
512+
513+
- name: Run npm package tests
514+
working-directory: ${{ env.SRC_DIR }}/src/js
515+
run: npm test
516+
517+
- name: Install openvino-genai-node samples dependencies
518+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
519+
run: |
520+
npm install --verbose
521+
rm -rf node_modules/openvino-node/bin
522+
cp -R ${{ env.INSTALL_DIR }}/openvino_js_package node_modules/openvino-node/bin
523+
524+
- name: Run samples tests
525+
working-directory: ${{ env.SRC_DIR }}/samples/js/text_generation
526+
run: npm test
527+
env:
528+
MODEL_PATH: ${{ env.SRC_DIR }}/src/js/tests/models/Llama-3.1-8B-Instruct-FastDraft-150M-int8-ov
529+
400530
Overall_Status:
401531
name: ci/gha_overall_status_macos
402532
needs: [openvino_download, genai_build_cmake, genai_build_wheel, genai_build_samples, genai_tests_wheel, genai_samples_tests]

src/cpp/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ if(CPACK_GENERATOR STREQUAL "NPM")
178178
# to find libopenvino.so when installing from source
179179
list(APPEND rpaths "$ORIGIN/../node_modules/openvino-node/bin")
180180
elseif(APPLE)
181-
# to find libopenvino.dylib in the same folder
181+
# to find libopenvino_genai.dylib in the same folder
182182
set(rpaths "@loader_path")
183+
# to find libopenvino.dylib when installing from npm
184+
list(APPEND rpaths "@loader_path/../../openvino-node/bin")
185+
# to find libopenvino.dylib when installing from source
186+
list(APPEND rpaths "@loader_path/../node_modules/openvino-node/bin")
183187
endif()
184188

185189
if(rpaths)

src/js/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ if(LINUX)
8585
elseif(APPLE)
8686
# to find libopenvino_genai.dylib in the same folder
8787
set(rpaths "@loader_path")
88+
# to find libopenvino.dylib when installing from npm
89+
list(APPEND rpaths "@loader_path/../../openvino-node/bin")
90+
# to find libopenvino.dylib when installing from source
91+
list(APPEND rpaths "@loader_path/../node_modules/openvino-node/bin")
8892
endif()
8993

9094
if(rpaths)

0 commit comments

Comments
 (0)