-
Notifications
You must be signed in to change notification settings - Fork 1
489 lines (425 loc) · 15.9 KB
/
napi-build.yml
File metadata and controls
489 lines (425 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# NAPI-RS Build Pipeline for CodeSight MCP Server
# Generated: 2025-01-27
name: NAPI-RS Build Pipeline
on:
push:
branches: [main, develop]
tags: ['v*']
pull_request:
branches: [main, develop]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
NODE_VERSION: '20'
RUST_VERSION: '1.75'
jobs:
# Build NAPI-RS native modules for all platforms
build-native-modules:
name: Build Native Modules (${{ matrix.triple }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Linux x64
- triple: x86_64-unknown-linux-gnu
os: ubuntu-latest
binary-name: codesight-native.linux-x64.node
- triple: x86_64-unknown-linux-musl
os: ubuntu-latest
binary-name: codesight-native.linux-x64-musl.node
# Linux ARM64
- triple: aarch64-unknown-linux-gnu
os: ubuntu-latest
binary-name: codesight-native.linux-arm64.node
- triple: aarch64-unknown-linux-musl
os: ubuntu-latest
binary-name: codesight-native.linux-arm64-musl.node
# macOS x64
- triple: x86_64-apple-darwin
os: macos-latest
binary-name: codesight-native.darwin-x64.node
# macOS ARM64
- triple: aarch64-apple-darwin
os: macos-latest
binary-name: codesight-native.darwin-arm64.node
# Windows x64
- triple: x86_64-pc-windows-msvc
os: windows-latest
binary-name: codesight-native.win32-x64.node
# Windows ARM64
- triple: aarch64-pc-windows-msvc
os: windows-latest
binary-name: codesight-native.win32-arm64.node
# Linux ARM32
- triple: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
binary-name: codesight-native.linux-arm.node
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy
targets: ${{ matrix.triple }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: typescript-mcp/package-lock.json
- name: Install NAPI-RS CLI
run: npm install -g @napi-rs/cli
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
rust-core/target/
key: ${{ runner.os }}-cargo-napi-${{ matrix.triple }}-${{ hashFiles('rust-core/**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-napi-${{ matrix.triple }}-
${{ runner.os }}-cargo-
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev build-essential
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install openssl
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
# Windows dependencies are typically handled by the Rust toolchain
- name: Build NAPI-RS module
working-directory: rust-core
run: |
# Build for specific target
cargo build --release --target ${{ matrix.triple }}
- name: Package NAPI-RS module
working-directory: rust-core
run: |
# Use NAPI-RS CLI to package the built module
napi build --platform --target ${{ matrix.triple }}
- name: Rename binary
working-directory: rust-core
run: |
# Rename the binary to match the expected naming convention
if [ "${{ runner.os }}" = "Windows" ]; then
mv target/${{ matrix.triple }}/release/code_intelligence_ffi.node typescript-mcp/${{ matrix.binary-name }}
else
mv target/${{ matrix.triple }}/release/libcode_intelligence_ffi.so typescript-mcp/${{ matrix.binary-name }}
fi
- name: Upload NAPI-RS artifacts
uses: actions/upload-artifact@v4
with:
name: napi-${{ matrix.triple }}
path: typescript-mcp/${{ matrix.binary-name }}
retention-days: 30
- name: Upload to GitHub Release (if tagged)
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
files: typescript-mcp/${{ matrix.binary-name }}
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Build and test hybrid TypeScript + Rust integration
test-hybrid-integration:
name: Test Hybrid Integration
runs-on: ubuntu-latest
needs: build-native-modules
if: github.event_name != 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: typescript-mcp/package-lock.json
- name: Install dependencies
working-directory: typescript-mcp
run: npm ci
- name: Download Linux x64 NAPI module
uses: actions/download-artifact@v4
with:
name: napi-x86_64-unknown-linux-gnu
path: typescript-mcp/
- name: Rename NAPI module for local testing
working-directory: typescript-mcp
run: |
mv codesight-native.linux-x64.node codesight-native.node
- name: Build TypeScript project
working-directory: typescript-mcp
run: |
npm run build
- name: Run hybrid tests
working-directory: typescript-mcp
run: |
npm test -- tests/basic.test.ts
- name: Test NAPI-RS integration
working-directory: typescript-mcp
run: |
# Test that the NAPI module can be loaded
node -e "
try {
const native = require('./codesight-native.node');
console.log('NAPI-RS module loaded successfully');
console.log('Available exports:', Object.keys(native));
} catch (error) {
console.error('Failed to load NAPI-RS module:', error);
process.exit(1);
}
"
# Create unified package with all native modules
package-native-modules:
name: Package Native Modules
runs-on: ubuntu-latest
needs: [build-native-modules, test-hybrid-integration]
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: typescript-mcp/package-lock.json
- name: Install dependencies
working-directory: typescript-mcp
run: npm ci
- name: Download all NAPI-RS artifacts
uses: actions/download-artifact@v4
with:
path: typescript-mcp/
- name: Organize downloaded modules
working-directory: typescript-mcp
run: |
# Create a structure for all downloaded modules
mkdir -p native-modules
mv napi-*/*.node native-modules/
# List all downloaded modules
echo "Downloaded NAPI-RS modules:"
ls -la native-modules/
- name: Create platform-specific install script
working-directory: typescript-mcp
run: |
cat > scripts/install-native.js << 'EOF'
const fs = require('fs');
const path = require('path');
const os = require('os');
// Determine the correct binary for the current platform
function getPlatformBinary() {
const platform = os.platform();
const arch = os.arch();
const binaryMap = {
'darwin x64': 'codesight-native.darwin-x64.node',
'darwin arm64': 'codesight-native.darwin-arm64.node',
'linux x64': 'codesight-native.linux-x64.node',
'linux arm64': 'codesight-native.linux-arm64.node',
'linux arm': 'codesight-native.linux-arm.node',
'win32 x64': 'codesight-native.win32-x64.node',
'win32 arm64': 'codesight-native.win32-arm64.node',
};
const key = `${platform} ${arch}`;
return binaryMap[key];
}
function installNativeModule() {
const binaryName = getPlatformBinary();
if (!binaryName) {
console.error(`Unsupported platform: ${os.platform()} ${os.arch()}`);
process.exit(1);
}
const sourcePath = path.join(__dirname, '..', 'native-modules', binaryName);
const targetPath = path.join(__dirname, '..', binaryName.replace(/\.node$/, ''));
if (fs.existsSync(sourcePath)) {
fs.copyFileSync(sourcePath, targetPath + '.node');
console.log(`Successfully installed ${binaryName}`);
} else {
console.error(`Native module not found: ${binaryName}`);
process.exit(1);
}
}
if (require.main === module) {
installNativeModule();
}
module.exports = { installNativeModule, getPlatformBinary };
EOF
- name: Update package.json scripts
working-directory: typescript-mcp
run: |
# Add install-native script to package.json
npm pkg set scripts.install-native="node scripts/install-native.js"
- name: Create native module manifest
working-directory: typescript-mcp
run: |
cat > native-modules.json << 'EOF'
{
"name": "codesight-native-modules",
"version": "0.1.0",
"description": "Multi-platform NAPI-RS native modules for CodeSight MCP Server",
"modules": [
{
"platform": "linux-x64",
"file": "codesight-native.linux-x64.node",
"triple": "x86_64-unknown-linux-gnu"
},
{
"platform": "linux-x64-musl",
"file": "codesight-native.linux-x64-musl.node",
"triple": "x86_64-unknown-linux-musl"
},
{
"platform": "linux-arm64",
"file": "codesight-native.linux-arm64.node",
"triple": "aarch64-unknown-linux-gnu"
},
{
"platform": "linux-arm64-musl",
"file": "codesight-native.linux-arm64-musl.node",
"triple": "aarch64-unknown-linux-musl"
},
{
"platform": "linux-arm",
"file": "codesight-native.linux-arm.node",
"triple": "armv7-unknown-linux-gnueabihf"
},
{
"platform": "darwin-x64",
"file": "codesight-native.darwin-x64.node",
"triple": "x86_64-apple-darwin"
},
{
"platform": "darwin-arm64",
"file": "codesight-native.darwin-arm64.node",
"triple": "aarch64-apple-darwin"
},
{
"platform": "win32-x64",
"file": "codesight-native.win32-x64.node",
"triple": "x86_64-pc-windows-msvc"
},
{
"platform": "win32-arm64",
"file": "codesight-native.win32-arm64.node",
"triple": "aarch64-pc-windows-msvc"
}
],
"installScript": "scripts/install-native.js",
"minimumNodeVersion": "18.0.0"
}
EOF
- name: Upload packaged modules
uses: actions/upload-artifact@v4
with:
name: packaged-native-modules
path: |
typescript-mcp/native-modules/
typescript-mcp/scripts/
typescript-mcp/native-modules.json
retention-days: 30
- name: Create release archive
if: startsWith(github.ref, 'refs/tags/v')
working-directory: typescript-mcp
run: |
tar -czf codesight-native-modules-${{ github.ref_name }}.tar.gz \
native-modules/ \
scripts/ \
native-modules.json
- name: Upload release archive
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
files: typescript-mcp/codesight-native-modules-${{ github.ref_name }}.tar.gz
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Performance benchmarks for NAPI-RS modules
benchmark-native-modules:
name: Benchmark Native Modules
runs-on: ubuntu-latest
needs: build-native-modules
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: typescript-mcp/package-lock.json
- name: Install dependencies
working-directory: typescript-mcp
run: npm ci
- name: Download Linux x64 NAPI module
uses: actions/download-artifact@v4
with:
name: napi-x86_64-unknown-linux-gnu
path: typescript-mcp/
- name: Rename NAPI module
working-directory: typescript-mcp
run: |
mv codesight-native.linux-x64.node codesight-native.node
- name: Run performance benchmarks
working-directory: typescript-mcp
run: |
# Create a benchmark script
cat > benchmark-native.js << 'EOF'
const { performance } = require('perf_hooks');
try {
const native = require('./codesight-native.node');
console.log('Running NAPI-RS performance benchmarks...');
// Benchmark function call overhead
const iterations = 100000;
const start = performance.now();
for (let i = 0; i < iterations; i++) {
// Test available functions
if (typeof native.testFunction === 'function') {
native.testFunction();
}
}
const end = performance.now();
const avgTime = (end - start) / iterations;
console.log(`Average function call time: ${avgTime.toFixed(4)}ms`);
console.log(`Total calls: ${iterations}`);
console.log(`Total time: ${(end - start).toFixed(2)}ms`);
// Generate benchmark report
const report = {
timestamp: new Date().toISOString(),
platform: process.platform,
arch: process.arch,
nodeVersion: process.version,
benchmarks: {
functionCallOverhead: {
iterations,
totalTime: end - start,
averageTime: avgTime,
callsPerSecond: Math.round(iterations / ((end - start) / 1000))
}
}
};
console.log('Benchmark report:', JSON.stringify(report, null, 2));
} catch (error) {
console.error('Benchmark failed:', error);
process.exit(1);
}
EOF
node benchmark-native.js
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: typescript-mcp/benchmark-results.json
retention-days: 7