Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cpuinfo as node module - new build scripts #813

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions .github/workflows/cortex-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,14 @@ jobs:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- run: yarn install && yarn build && yarn build:binary
- uses: actions/setup-python@v3
with:
python-version: "3.10"

- run: pip3 install --upgrade setuptools
if: runner.os == 'macOS'

- run: yarn install && yarn build:binary
working-directory: ./cortex-js

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

- name: update app info
run: |
cd cortex-js
make update-app-info

- name: Code Signing macOS
if: runner.os == 'macOS'
run: |
cd cortex-js
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
make codesign-binary CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"

- name: Create MacOS PKG Installer
if: runner.os == 'macOS'
Expand All @@ -421,6 +433,7 @@ jobs:
mkdir installer
cp cortex installer/cortex
pkgbuild --identifier ai.cortex.pkg --install-location ./usr/local/bin/ --root ./installer cortex-installer.pkg
make codesign-installer CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"

- name: Create MacOS PKG Installer
if: runner.os == 'Linux'
Expand All @@ -432,6 +445,20 @@ jobs:
cp cortex cortexso/usr/local/bin/cortex
dpkg-deb --build cortexso

- uses: nick-fields/retry@v3
with:
continue_on_error: true
retry_wait_seconds: 10
timeout_minutes: 10
max_attempts: 3
shell: cmd
command: |
cd cortex-js
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
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 }}"
name: Code Signing Windows
if: runner.os == 'Windows'

- name: Compile .ISS to .EXE Installer
uses: Minionguyjpro/[email protected]
if: runner.os == 'Windows'
Expand All @@ -449,7 +476,7 @@ jobs:
command: |
cd cortex-js
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
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 }}"
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 }}"
name: Code Signing Windows
if: runner.os == 'Windows'

Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ dist
*.lock
node_modules
.turbo
package-lock.json

# CI - Test - Coverage
cortex.log
api.log
prism.log
api.json
openai-python/*
openai-python/*
build
cortex-js/cortex.exe
cortex-js/package-lock.json
.vscode
cortex-js/command
cortex-js/src/infrastructure/commanders/test/test_data
52 changes: 39 additions & 13 deletions cortex-js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,64 @@ AZURE_TENANT_ID ?= xxxx
AZURE_CLIENT_SECRET ?= xxxx
AZURE_CERT_NAME ?= xxxx
DEVELOPER_ID ?= xxxx
CORTEX_EXE_IN ?= "dist/cortexso-win.exe"
CORTEX_EXE_OUT ?= "cortex.exe"
CORTEX_VERSION ?= "0.0.0.1"

postbundle:
ifeq ($(RUN_TESTS),false)
@echo "Skipping tests"
update-app-info:
ifeq ($(OS),Windows_NT)
@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)"'
else ifeq ($(shell uname -s),Linux)
@cp ./dist/cortexso-linux ./cortex
else
@cp ./dist/cortexso-macos ./cortex
endif

codesign-binary:
ifeq ($(CODE_SIGN),false)
@echo "Skipping Code Sign"
@exit 0
endif

ifeq ($(OS),Windows_NT)
@powershell -Command "7z a -ttar temp.tar cortex.exe; 7z a -tgzip cortex.tar.gz temp.tar;"
@powershell -Command "7z a -ttar temp2.tar setup.exe; 7z a -tgzip cortex-installer.tar.gz temp2.tar;"
@powershell -Command "dotnet tool install --global AzureSignTool;"
@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";'
else ifeq ($(shell uname -s),Linux)
@chmod +x cortex;
tar -czvf cortex.tar.gz cortex;
@echo "Skipping Code Sign for linux"
@exit 0
else
@chmod +x cortex;
tar -czvf cortex.tar.gz cortex;
tar -czvf cortex-installer.tar.gz cortex-installer.pkg;
find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
endif


codesign:
codesign-installer:
ifeq ($(CODE_SIGN),false)
@echo "Skipping Code Sign"
@exit 0
endif

ifeq ($(OS),Windows_NT)
@powershell -Command "dotnet tool install --global AzureSignTool;"
@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";'
@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";'
else ifeq ($(shell uname -s),Linux)
@echo "Skipping Code Sign for linux"
@exit 0
else
find "cortex" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
endif

postbundle:
ifeq ($(RUN_TESTS),false)
@echo "Skipping tests"
@exit 0
endif
ifeq ($(OS),Windows_NT)
@powershell -Command "7z a -ttar temp.tar cortex.exe; 7z a -tgzip cortex.tar.gz temp.tar;"
@powershell -Command "7z a -ttar temp2.tar setup.exe; 7z a -tgzip cortex-installer.tar.gz temp2.tar;"
else ifeq ($(shell uname -s),Linux)
@chmod +x cortex;
tar -czvf cortex.tar.gz cortex;
else
@chmod +x cortex;
tar -czvf cortex.tar.gz cortex;
tar -czvf cortex-installer.tar.gz cortex-installer.pkg;
endif
Binary file removed cortex-js/cpuinfo/bin/cpuinfo
Binary file not shown.
Binary file removed cortex-js/cpuinfo/bin/cpuinfo.exe
Binary file not shown.
10 changes: 10 additions & 0 deletions cortex-js/cpuinfo/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"targets": [
{
"target_name": "cpuinfo",
"sources": ["src/cpuinfo.cpp"],
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ],
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
}
]
}
10 changes: 10 additions & 0 deletions cortex-js/cpuinfo/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Type definitions for cpuinfo
// Project: http://github.com/tryghost/node-sqlite3

/// <reference types="node" />
export type InstructionSet = 'AVX' | 'AVX2' | 'AVX512'; // Add more as needed later
declare module "cpuinfo" {
declare const cpuInfo: {
cpuInfo: () => InstructionSet[];
}
}
1 change: 1 addition & 0 deletions cortex-js/cpuinfo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = exports = { cpuInfo: require('./build/Release/cpuinfo.node') }
38 changes: 38 additions & 0 deletions cortex-js/cpuinfo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "cpuinfo",
"version": "1.0.0",
"description": "Get CPU instructions",
"main": "index.js",
"types": "./index.d.ts",
"scripts": {
"install": "prebuild-install -r napi || node-gyp rebuild"
},
"author": "",
"license": "ISC",
"gypfile": true,
"binary": {
"napi_versions": [
3,
6
]
},
"dependencies": {
"bindings": "^1.5.0",
"node-addon-api": "^7.0.0",
"prebuild-install": "^7.1.1"
},
"devDependencies": {
"@types/node": "^20.14.9",
"typescript": "^5.5.3"
},
"peerDependencies": {
"node-gyp": "8.x"
},
"files": [
"binding.gyp",
"deps/",
"*.js",
"*.d.ts",
"src/"
]
}
Loading
Loading