Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit e416c6c

Browse files
committed
fix: single executable binary across platforms
1 parent 1fd7c9e commit e416c6c

File tree

7 files changed

+149
-43
lines changed

7 files changed

+149
-43
lines changed

.github/workflows/cortex-cpp-build.yml

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
206206
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
207207

208-
- name: Build Cortex CPP
208+
- name: Build
209209
run: |
210210
cd cortex-cpp
211211
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}"
@@ -221,36 +221,6 @@ jobs:
221221
cd cortex-cpp
222222
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
223223
224-
# Cortex-JS Build
225-
- name: "Update version by tag"
226-
run: |
227-
cd cortex-js
228-
# Remove the v prefix
229-
tag_version=${GITHUB_REF#refs/tags/v}
230-
# Remove the -cortex-js suffix
231-
new_version=${tag_version%-cortex-js}
232-
233-
# Replace the old version with the new version in package.json
234-
jq --arg version "$new_version" '.version = $version' ./package.json > /tmp/package.json && mv /tmp/package.json ./package.json
235-
236-
# Print the new version
237-
echo "Updated package.json version to: $new_version"
238-
239-
# Setup .npmrc file to publish to npm
240-
- uses: actions/setup-node@v3
241-
with:
242-
node-version: "20.x"
243-
registry-url: "https://registry.npmjs.org"
244-
245-
- run: yarn install && yarn build:binary
246-
working-directory: ./cortex-js
247-
248-
- name: Code Signing macOS
249-
if: runner.os == 'macOS'
250-
run: |
251-
cd cortex-js/dist
252-
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
253-
254224
- uses: nick-fields/retry@v3
255225
with:
256226
continue_on_error: true
@@ -276,18 +246,12 @@ jobs:
276246
cd cortex-cpp
277247
make run-e2e-test RUN_TESTS=true LLM_MODEL_URL=${{ env.LLM_MODEL_URL }} EMBEDDING_MODEL_URL=${{ env.EMBEDDING_MODEL_URL }}
278248
279-
- name: Upload CPP Artifact
249+
- name: Upload Artifact
280250
uses: actions/upload-artifact@v2
281251
with:
282252
name: cortex-cpp-${{ matrix.os }}-${{ matrix.name }}
283253
path: ./cortex-cpp/cortex-cpp
284254

285-
- name: Upload JS Artifact
286-
uses: actions/upload-artifact@v2
287-
with:
288-
name: cortex-${{ matrix.os }}-${{ matrix.name }}
289-
path: ./cortex-js/dist/cortex
290-
291255
- uses: actions/upload-release-asset@v1.0.1
292256
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
293257
env:
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI Cortex JS
2+
3+
on:
4+
push:
5+
branches:
6+
- chore/update-ci-for-cortex-artifact
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-cortex-single-binary:
11+
runs-on: ${{ matrix.runs-on }}
12+
needs: []
13+
timeout-minutes: 20
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- os: "linux"
19+
name: "amd64"
20+
runs-on: "ubuntu-20-04"
21+
22+
- os: "windows"
23+
name: "amd64"
24+
runs-on: "windows-cuda-12-0"
25+
26+
- os: "mac"
27+
name: "amd64"
28+
runs-on: "macos-13"
29+
30+
- os: "mac"
31+
name: "arm64"
32+
runs-on: "macos-latest"
33+
steps:
34+
- name: Clone
35+
id: checkout
36+
uses: actions/checkout@v3
37+
with:
38+
submodules: recursive
39+
40+
- uses: actions/setup-dotnet@v3
41+
if: runner.os == 'Windows'
42+
with:
43+
dotnet-version: "8.0.x"
44+
45+
- name: Install choco on Windows
46+
if: runner.os == 'Windows'
47+
run: |
48+
choco install make -y
49+
50+
- uses: actions/setup-node@v3
51+
with:
52+
node-version: "20.x"
53+
registry-url: "https://registry.npmjs.org"
54+
55+
- run: npm install -g yarn
56+
57+
- run: yarn install && yarn build && yarn build:binary
58+
working-directory: ./cortex-js
59+
60+
- name: Get Cer for code signing
61+
if: runner.os == 'macOS'
62+
run: base64 -d <<< "$CODE_SIGN_P12_BASE64" > /tmp/codesign.p12
63+
shell: bash
64+
env:
65+
CODE_SIGN_P12_BASE64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
66+
67+
- uses: apple-actions/import-codesign-certs@v2
68+
if: runner.os == 'macOS'
69+
with:
70+
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
71+
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
72+
73+
- name: Code Signing macOS
74+
if: runner.os == 'macOS'
75+
run: |
76+
cd cortex-js
77+
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
78+
79+
- name: Post-Bundle
80+
run: |
81+
cd cortex-js
82+
make postbundle
83+
84+
- name: Upload Artifact
85+
uses: actions/upload-artifact@v2
86+
with:
87+
name: cortex-${{ matrix.os }}-${{ matrix.name }}
88+
path: |
89+
./cortex-js/cortex
90+
./cortex-js/cortex.exe

cortex-js/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CODE_SIGN ?= false
2+
AZURE_KEY_VAULT_URI ?= xxxx
3+
AZURE_CLIENT_ID ?= xxxx
4+
AZURE_TENANT_ID ?= xxxx
5+
AZURE_CLIENT_SECRET ?= xxxx
6+
AZURE_CERT_NAME ?= xxxx
7+
DEVELOPER_ID ?= xxxx
8+
9+
postbundle:
10+
ifeq ($(RUN_TESTS),false)
11+
@echo "Skipping tests"
12+
@exit 0
13+
endif
14+
ifeq ($(OS),Windows_NT)
15+
else ifeq ($(shell uname -s),Linux)
16+
@chmod +x cortex;
17+
else
18+
@chmod +x cortex;
19+
endif
20+
21+
codesign:
22+
ifeq ($(CODE_SIGN),false)
23+
@echo "Skipping Code Sign"
24+
@exit 0
25+
endif
26+
27+
ifeq ($(OS),Windows_NT)
28+
@powershell -Command "dotnet tool install --global AzureSignTool;"
29+
@powershell -Command 'azuresigntool.exe sign -kvu "$(AZURE_KEY_VAULT_URI)" -kvi "$(AZURE_CLIENT_ID)" -kvt "$(AZURE_TENANT_ID)" -kvs "$(AZURE_CLIENT_SECRET)" -kvc "$(AZURE_CERT_NAME)" -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\cortex-js\cortex.exe";'
30+
else ifeq ($(shell uname -s),Linux)
31+
@echo "Skipping Code Sign for linux"
32+
@exit 0
33+
else
34+
find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
35+
endif

cortex-js/cortex.ico

14.7 KB
Binary file not shown.

cortex-js/installer.iss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
1818
; Define the files to be installed
1919
[Files]
2020
Source: "cortex.exe"; DestDir: "{app}"; Flags: ignoreversion
21-
Source: "node_modules\sqlite3\*"; DestDir: "{app}\node_modules\sqlite3"; Flags: ignoreversion recursesubdirs createallsubdirs
2221

2322
; Define the icons to be created
2423
[Icons]

cortex-js/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"scripts": {
1212
"dev": "nest dev",
1313
"build": "yarn build:extensions && nest build && cpx \"cpuinfo/bin/**\" dist/bin",
14-
"build:binary": "yarn build && nexe dist/src/command.js --build -r './node_modules/**/*' -o dist/cortex",
14+
"build:binary": "run-script-os",
15+
"build:binary:windows": "bun build --compile --target=bun-windows-x64 ./dist/src/command.js --outfile cortex.exe --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
16+
"build:binary:linux": "bun build --compile --target=bun-linux-x64 ./dist/src/command.js --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
17+
"build:binary:macos": "bun build --compile --target=bun-darwin-arm64 ./dist/src/command.js --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage",
1518
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1619
"build:extensions": "run-script-os",
1720
"build:extensions:windows": "powershell -command \"$jobs = Get-ChildItem -Path './src/extensions' -Directory | ForEach-Object { Start-Job -Name ($_.Name) -ScriptBlock { param($_dir); try { Set-Location $_dir; yarn; yarn build; Write-Output 'Build successful in ' + $_dir } catch { Write-Error 'Error in ' + $_dir; throw } } -ArgumentList $_.FullName }; $jobs | Wait-Job; $jobs | ForEach-Object { Receive-Job -Job $_ -Keep } | ForEach-Object { Write-Host $_ }; $failed = $jobs | Where-Object { $_.State -ne 'Completed' -or $_.ChildJobs[0].JobStateInfo.State -ne 'Completed' }; if ($failed) { Exit 1 }\"",
@@ -29,7 +32,7 @@
2932
"test:e2e": "jest --config ./test/jest-e2e.json",
3033
"typeorm": "typeorm-ts-node-esm",
3134
"build:dev": "npx nest build && chmod +x ./dist/src/command.js && npm link",
32-
"postinstall": "cortex init -s || true"
35+
"postinstall": "patch-package"
3336
},
3437
"dependencies": {
3538
"@huggingface/gguf": "^0.1.5",
@@ -55,7 +58,6 @@
5558
"readline": "^1.3.0",
5659
"reflect-metadata": "^0.2.0",
5760
"rxjs": "^7.8.1",
58-
"sqlite": "^5.1.1",
5961
"sqlite3": "^5.1.7",
6062
"systeminformation": "^5.22.11",
6163
"typeorm": "^0.3.20",
@@ -80,6 +82,7 @@
8082
"@types/uuid": "^9.0.8",
8183
"@typescript-eslint/eslint-plugin": "^6.0.0",
8284
"@typescript-eslint/parser": "^6.0.0",
85+
"bun": "^1.1.15",
8386
"cpx": "^1.5.0",
8487
"eslint": "^8.42.0",
8588
"eslint-config-prettier": "^9.0.0",
@@ -88,7 +91,7 @@
8891
"is-primitive": "^3.0.1",
8992
"jest": "^29.5.0",
9093
"nest-commander-testing": "^3.3.0",
91-
"nexe": "^4.0.0-rc.6",
94+
"patch-package": "^8.0.0",
9295
"prettier": "^3.0.0",
9396
"run-script-os": "^1.1.6",
9497
"source-map-support": "^0.5.21",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/node_modules/sqlite3/.DS_Store b/node_modules/sqlite3/.DS_Store
2+
new file mode 100644
3+
index 0000000..10f4d43
4+
Binary files /dev/null and b/node_modules/sqlite3/.DS_Store differ
5+
diff --git a/node_modules/sqlite3/lib/sqlite3.js b/node_modules/sqlite3/lib/sqlite3.js
6+
index 430a2b8..9df0857 100644
7+
--- a/node_modules/sqlite3/lib/sqlite3.js
8+
+++ b/node_modules/sqlite3/lib/sqlite3.js
9+
@@ -1,5 +1,5 @@
10+
const path = require('path');
11+
-const sqlite3 = require('./sqlite3-binding.js');
12+
+const sqlite3 = require('./../build/Release/node_sqlite3.node');
13+
const EventEmitter = require('events').EventEmitter;
14+
module.exports = exports = sqlite3;
15+

0 commit comments

Comments
 (0)