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

Commit 36c247f

Browse files
louis-janhiento09
andauthored
feat: cpuinfo as node module - new build scripts (#813)
Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 455ae53 commit 36c247f

File tree

16 files changed

+354
-177
lines changed

16 files changed

+354
-177
lines changed

.github/workflows/cortex-build.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,14 @@ jobs:
392392
node-version: "20.x"
393393
registry-url: "https://registry.npmjs.org"
394394

395-
- run: yarn install && yarn build && yarn build:binary
395+
- uses: actions/setup-python@v3
396+
with:
397+
python-version: "3.10"
398+
399+
- run: pip3 install --upgrade setuptools
400+
if: runner.os == 'macOS'
401+
402+
- run: yarn install && yarn build:binary
396403
working-directory: ./cortex-js
397404

398405
- name: Get Cer for code signing
@@ -408,11 +415,16 @@ jobs:
408415
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
409416
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
410417

418+
- name: update app info
419+
run: |
420+
cd cortex-js
421+
make update-app-info
422+
411423
- name: Code Signing macOS
412424
if: runner.os == 'macOS'
413425
run: |
414426
cd cortex-js
415-
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
427+
make codesign-binary CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
416428
417429
- name: Create MacOS PKG Installer
418430
if: runner.os == 'macOS'
@@ -421,6 +433,7 @@ jobs:
421433
mkdir installer
422434
cp cortex installer/cortex
423435
pkgbuild --identifier ai.cortex.pkg --install-location ./usr/local/bin/ --root ./installer cortex-installer.pkg
436+
make codesign-installer CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
424437
425438
- name: Create MacOS PKG Installer
426439
if: runner.os == 'Linux'
@@ -432,6 +445,20 @@ jobs:
432445
cp cortex cortexso/usr/local/bin/cortex
433446
dpkg-deb --build cortexso
434447
448+
- uses: nick-fields/retry@v3
449+
with:
450+
continue_on_error: true
451+
retry_wait_seconds: 10
452+
timeout_minutes: 10
453+
max_attempts: 3
454+
shell: cmd
455+
command: |
456+
cd cortex-js
457+
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
458+
make codesign-binary CODE_SIGN=true CORTEX_VERSION="0.${{ needs.create-draft-release.outputs.version }}" AZURE_KEY_VAULT_URI="${{ secrets.AZURE_KEY_VAULT_URI }}" AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}" AZURE_TENANT_ID="${{ secrets.AZURE_TENANT_ID }}" AZURE_CLIENT_SECRET="${{ secrets.AZURE_CLIENT_SECRET }}" AZURE_CERT_NAME="${{ secrets.AZURE_CERT_NAME }}"
459+
name: Code Signing Windows
460+
if: runner.os == 'Windows'
461+
435462
- name: Compile .ISS to .EXE Installer
436463
uses: Minionguyjpro/Inno-Setup-Action@v1.2.2
437464
if: runner.os == 'Windows'
@@ -449,7 +476,7 @@ jobs:
449476
command: |
450477
cd cortex-js
451478
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
452-
make codesign CODE_SIGN=true AZURE_KEY_VAULT_URI="${{ secrets.AZURE_KEY_VAULT_URI }}" AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}" AZURE_TENANT_ID="${{ secrets.AZURE_TENANT_ID }}" AZURE_CLIENT_SECRET="${{ secrets.AZURE_CLIENT_SECRET }}" AZURE_CERT_NAME="${{ secrets.AZURE_CERT_NAME }}"
479+
make codesign-installer CODE_SIGN=true CORTEX_VERSION="0.${{ needs.create-draft-release.outputs.version }}" AZURE_KEY_VAULT_URI="${{ secrets.AZURE_KEY_VAULT_URI }}" AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}" AZURE_TENANT_ID="${{ secrets.AZURE_TENANT_ID }}" AZURE_CLIENT_SECRET="${{ secrets.AZURE_CLIENT_SECRET }}" AZURE_CERT_NAME="${{ secrets.AZURE_CERT_NAME }}"
453480
name: Code Signing Windows
454481
if: runner.os == 'Windows'
455482

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ dist
44
*.lock
55
node_modules
66
.turbo
7+
package-lock.json
78

89
# CI - Test - Coverage
910
cortex.log
1011
api.log
1112
prism.log
1213
api.json
13-
openai-python/*
14+
openai-python/*
15+
build
16+
cortex-js/cortex.exe
17+
cortex-js/package-lock.json
18+
.vscode
19+
cortex-js/command
20+
cortex-js/src/infrastructure/commanders/test/test_data

cortex-js/Makefile

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,64 @@ AZURE_TENANT_ID ?= xxxx
55
AZURE_CLIENT_SECRET ?= xxxx
66
AZURE_CERT_NAME ?= xxxx
77
DEVELOPER_ID ?= xxxx
8+
CORTEX_EXE_IN ?= "dist/cortexso-win.exe"
9+
CORTEX_EXE_OUT ?= "cortex.exe"
10+
CORTEX_VERSION ?= "0.0.0.1"
811

9-
postbundle:
10-
ifeq ($(RUN_TESTS),false)
11-
@echo "Skipping tests"
12+
update-app-info:
13+
ifeq ($(OS),Windows_NT)
14+
@powershell -Command 'npx resedit --in $(CORTEX_EXE_IN) --out $(CORTEX_EXE_OUT) --icon "1,cortex.ico" --no-grow --company-name "Homebrew Computer Pte Ltd" --file-description "cortex cli" --file-version "$(CORTEX_VERSION)" --internal-name "cortex" --product-name "cortex" --product-version "$(CORTEX_VERSION)"'
15+
else ifeq ($(shell uname -s),Linux)
16+
@cp ./dist/cortexso-linux ./cortex
17+
else
18+
@cp ./dist/cortexso-macos ./cortex
19+
endif
20+
21+
codesign-binary:
22+
ifeq ($(CODE_SIGN),false)
23+
@echo "Skipping Code Sign"
1224
@exit 0
1325
endif
26+
1427
ifeq ($(OS),Windows_NT)
15-
@powershell -Command "7z a -ttar temp.tar cortex.exe; 7z a -tgzip cortex.tar.gz temp.tar;"
16-
@powershell -Command "7z a -ttar temp2.tar setup.exe; 7z a -tgzip cortex-installer.tar.gz temp2.tar;"
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";'
1730
else ifeq ($(shell uname -s),Linux)
18-
@chmod +x cortex;
19-
tar -czvf cortex.tar.gz cortex;
31+
@echo "Skipping Code Sign for linux"
32+
@exit 0
2033
else
21-
@chmod +x cortex;
22-
tar -czvf cortex.tar.gz cortex;
23-
tar -czvf cortex-installer.tar.gz cortex-installer.pkg;
34+
find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
2435
endif
2536

26-
27-
codesign:
37+
codesign-installer:
2838
ifeq ($(CODE_SIGN),false)
2939
@echo "Skipping Code Sign"
3040
@exit 0
3141
endif
3242

3343
ifeq ($(OS),Windows_NT)
3444
@powershell -Command "dotnet tool install --global AzureSignTool;"
35-
@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";'
3645
@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\setup.exe";'
3746
else ifeq ($(shell uname -s),Linux)
3847
@echo "Skipping Code Sign for linux"
3948
@exit 0
4049
else
4150
find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
51+
endif
52+
53+
postbundle:
54+
ifeq ($(RUN_TESTS),false)
55+
@echo "Skipping tests"
56+
@exit 0
57+
endif
58+
ifeq ($(OS),Windows_NT)
59+
@powershell -Command "7z a -ttar temp.tar cortex.exe; 7z a -tgzip cortex.tar.gz temp.tar;"
60+
@powershell -Command "7z a -ttar temp2.tar setup.exe; 7z a -tgzip cortex-installer.tar.gz temp2.tar;"
61+
else ifeq ($(shell uname -s),Linux)
62+
@chmod +x cortex;
63+
tar -czvf cortex.tar.gz cortex;
64+
else
65+
@chmod +x cortex;
66+
tar -czvf cortex.tar.gz cortex;
67+
tar -czvf cortex-installer.tar.gz cortex-installer.pkg;
4268
endif

cortex-js/cpuinfo/bin/cpuinfo

-23.4 KB
Binary file not shown.

cortex-js/cpuinfo/bin/cpuinfo.exe

-218 KB
Binary file not shown.

cortex-js/cpuinfo/binding.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "cpuinfo",
5+
"sources": ["src/cpuinfo.cpp"],
6+
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ],
7+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
8+
}
9+
]
10+
}

cortex-js/cpuinfo/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Type definitions for cpuinfo
2+
// Project: http://github.com/tryghost/node-sqlite3
3+
4+
/// <reference types="node" />
5+
export type InstructionSet = 'AVX' | 'AVX2' | 'AVX512'; // Add more as needed later
6+
declare module "cpuinfo" {
7+
declare const cpuInfo: {
8+
cpuInfo: () => InstructionSet[];
9+
}
10+
}

cortex-js/cpuinfo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = exports = { cpuInfo: require('./build/Release/cpuinfo.node') }

cortex-js/cpuinfo/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "cpuinfo",
3+
"version": "1.0.0",
4+
"description": "Get CPU instructions",
5+
"main": "index.js",
6+
"types": "./index.d.ts",
7+
"scripts": {
8+
"install": "prebuild-install -r napi || node-gyp rebuild"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"gypfile": true,
13+
"binary": {
14+
"napi_versions": [
15+
3,
16+
6
17+
]
18+
},
19+
"dependencies": {
20+
"bindings": "^1.5.0",
21+
"node-addon-api": "^7.0.0",
22+
"prebuild-install": "^7.1.1"
23+
},
24+
"devDependencies": {
25+
"@types/node": "^20.14.9",
26+
"typescript": "^5.5.3"
27+
},
28+
"peerDependencies": {
29+
"node-gyp": "8.x"
30+
},
31+
"files": [
32+
"binding.gyp",
33+
"deps/",
34+
"*.js",
35+
"*.d.ts",
36+
"src/"
37+
]
38+
}

0 commit comments

Comments
 (0)