Skip to content

Commit d410ba7

Browse files
committed
ci: Build ONNX from source for Win
Signed-off-by: Anush008 <[email protected]>
1 parent c5927b5 commit d410ba7

File tree

3 files changed

+2655
-57
lines changed

3 files changed

+2655
-57
lines changed

.github/workflows/CI.yml

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22
env:
3-
DEBUG: napi:*
3+
DEBUG: 'napi:*'
44
APP_NAME: fastembed
55
MACOSX_DEPLOYMENT_TARGET: '10.13'
66
permissions:
@@ -33,76 +33,98 @@ jobs:
3333
target: x86_64-pc-windows-msvc
3434
- host: ubuntu-latest
3535
target: x86_64-unknown-linux-gnu
36-
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
36+
docker: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian'
3737
build: yarn build --target x86_64-unknown-linux-gnu
3838
- host: macos-latest
3939
target: aarch64-apple-darwin
4040
build: yarn build --target aarch64-apple-darwin
41-
name: stable - ${{ matrix.settings.target }} - node@20
42-
runs-on: ${{ matrix.settings.host }}
41+
name: 'stable - ${{ matrix.settings.target }} - node@20'
42+
runs-on: '${{ matrix.settings.host }}'
4343
steps:
4444
- uses: actions/checkout@v4
45-
- name: Setup node
46-
uses: actions/setup-node@v4
47-
if: ${{ !matrix.settings.docker }}
48-
with:
49-
node-version: 20
50-
cache: yarn
51-
- name: Install
52-
uses: dtolnay/rust-toolchain@stable
53-
if: ${{ !matrix.settings.docker }}
54-
with:
55-
toolchain: stable
56-
targets: ${{ matrix.settings.target }}
57-
- name: Cache cargo
58-
uses: actions/cache@v4
45+
- name: Restore Builds
46+
id: cache-build-restore
47+
uses: actions/cache/restore@v4
5948
with:
49+
key: '${{ runner.os }}-cargo-${{ hashFiles(''**/Cargo.lock'') }}'
6050
path: |
51+
~/.cargo/bin/
6152
~/.cargo/registry/index/
6253
~/.cargo/registry/cache/
6354
~/.cargo/git/db/
64-
.cargo-cache
55+
~/.cache/ort.pyke.io
6556
target/
66-
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
67-
- uses: goto-bus-stop/setup-zig@v2
68-
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
69-
with:
70-
version: 0.13.0
71-
- name: Setup toolchain
72-
run: ${{ matrix.settings.setup }}
73-
if: ${{ matrix.settings.setup }}
74-
shell: bash
75-
- name: Setup node x86
76-
if: matrix.settings.target == 'i686-pc-windows-msvc'
77-
run: yarn config set supportedArchitectures.cpu "ia32"
78-
shell: bash
79-
- name: Install dependencies
80-
run: yarn install
81-
- name: Setup node x86
57+
/onnxruntime/build/Windows/
58+
- name: Setup node
8259
uses: actions/setup-node@v4
83-
if: matrix.settings.target == 'i686-pc-windows-msvc'
60+
if: '${{ !matrix.settings.docker }}'
8461
with:
8562
node-version: 20
8663
cache: yarn
87-
architecture: x86
88-
- name: Build in docker
64+
- name: Install Rust
65+
uses: dtolnay/rust-toolchain@stable
66+
if: '${{ !matrix.settings.docker }}'
67+
with:
68+
toolchain: stable
69+
targets: '${{ matrix.settings.target }}'
70+
- name: Install dependencies
71+
run: yarn install
72+
- name: Build in Docker for Ubuntu
8973
uses: addnab/docker-run-action@v3
90-
if: ${{ matrix.settings.docker }}
74+
if: matrix.settings.host == 'ubuntu-latest'
9175
with:
92-
image: ${{ matrix.settings.docker }}
93-
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
94-
run: ${{ matrix.settings.build }}
95-
- name: Build
96-
run: ${{ matrix.settings.build }}
97-
if: ${{ !matrix.settings.docker }}
76+
image: '${{ matrix.settings.docker }}'
77+
options: >-
78+
--user 0:0 -v ${{ github.workspace
79+
}}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{
80+
github.workspace
81+
}}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{
82+
github.workspace
83+
}}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{
84+
github.workspace }}:/build -w /build
85+
run: '${{ matrix.settings.build }}'
86+
- name: Compile ONNX Runtime for Windows
87+
if: matrix.settings.host == 'windows-latest'
88+
run: >
89+
git clone https://github.com/microsoft/onnxruntime --recursive
90+
--branch v1.19.2 --single-branch --depth 1
91+
92+
cd onnxruntime
93+
94+
.\build.bat --update --build --config Release --parallel
95+
--compile_no_warning_as_error --skip_submodule_sync
96+
97+
cd ..
98+
- name: Build with ORT_LIB_LOCATION for Windows
99+
run: |
100+
set ORT_LIB_LOCATION=%CD%\onnxruntime\build\Windows\Release
101+
${{ matrix.settings.build }}
102+
if: matrix.settings.host == 'windows-latest'
103+
- name: Build for MacOS
104+
run: '${{ matrix.settings.build }}'
105+
if: matrix.settings.host == 'macos-latest'
98106
- name: Upload artifact
99107
uses: actions/upload-artifact@v4
100108
with:
101-
name: bindings-${{ matrix.settings.target }}
102-
path: ${{ env.APP_NAME }}.*.node
109+
name: 'bindings-${{ matrix.settings.target }}'
110+
path: '${{ env.APP_NAME }}.*.node'
103111
if-no-files-found: error
112+
- name: Always Save Cache
113+
id: cache-build-save
114+
if: always() && steps.cache-build-restore.outputs.cache-hit != 'true'
115+
uses: actions/cache/save@v4
116+
with:
117+
key: '${{ steps.cache-build-restore.outputs.cache-primary-key }}'
118+
path: |
119+
~/.cargo/bin/
120+
~/.cargo/registry/index/
121+
~/.cargo/registry/cache/
122+
~/.cargo/git/db/
123+
~/.cache/ort.pyke.io
124+
target/
125+
/onnxruntime/build/Windows/
104126
test-macOS-windows-binding:
105-
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
127+
name: 'Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}'
106128
needs:
107129
- build
108130
strategy:
@@ -116,29 +138,29 @@ jobs:
116138
node:
117139
- '18'
118140
- '20'
119-
runs-on: ${{ matrix.settings.host }}
141+
runs-on: '${{ matrix.settings.host }}'
120142
steps:
121143
- uses: actions/checkout@v4
122144
- name: Setup node
123145
uses: actions/setup-node@v4
124146
with:
125-
node-version: ${{ matrix.node }}
147+
node-version: '${{ matrix.node }}'
126148
cache: yarn
127149
architecture: x64
128150
- name: Install dependencies
129151
run: yarn install
130152
- name: Download artifacts
131153
uses: actions/download-artifact@v4
132154
with:
133-
name: bindings-${{ matrix.settings.target }}
155+
name: 'bindings-${{ matrix.settings.target }}'
134156
path: .
135157
- name: List packages
136158
run: ls -R .
137159
shell: bash
138160
- name: Test bindings
139161
run: yarn test
140162
test-linux-x64-gnu-binding:
141-
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
163+
name: 'Test bindings on Linux-x64-gnu - node@${{ matrix.node }}'
142164
needs:
143165
- build
144166
strategy:
@@ -153,7 +175,7 @@ jobs:
153175
- name: Setup node
154176
uses: actions/setup-node@v4
155177
with:
156-
node-version: ${{ matrix.node }}
178+
node-version: '${{ matrix.node }}'
157179
cache: yarn
158180
- name: Install dependencies
159181
run: yarn install
@@ -166,7 +188,9 @@ jobs:
166188
run: ls -R .
167189
shell: bash
168190
- name: Test bindings
169-
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
191+
run: >-
192+
docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node
193+
}}-slim yarn test
170194
publish:
171195
name: Publish
172196
runs-on: ubuntu-latest
@@ -205,5 +229,5 @@ jobs:
205229
echo "Not a release, skipping publish"
206230
fi
207231
env:
208-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
232+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
233+
NPM_TOKEN: '${{ secrets.NPM_TOKEN }}'

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ $RECYCLE.BIN/
184184
#Added by cargo
185185

186186
/target
187-
Cargo.lock
188187

189188
.pnp.*
190189
.yarn/*

0 commit comments

Comments
 (0)