Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pnpm install -g @offckb/cli

_Require Node version `>= v20.0.0`. We recommend using latest [LTS](https://nodejs.org/en/download/package-manager) version of Node to run `offckb`_

**Note for Windows users:** If installation fails due to native module compilation issues, the CLI will still work but may use portable binaries instead of optimized ones. For better performance, consider installing Visual Studio Build Tools.

## Usage

```sh
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"pnpm": {
"onlyBuiltDependencies": [
"cpu-features",
"secp256k1"
]
},
Expand Down Expand Up @@ -55,7 +54,6 @@
},
"devDependencies": {
"@types/adm-zip": "^0.5.5",
"@types/cpu-features": "^0.0.3",
"@types/node": "^20.17.24",
"@types/node-fetch": "^2.6.11",
"@types/semver": "^7.5.7",
Expand All @@ -80,12 +78,14 @@
"child_process": "^1.0.2",
"ckb-transaction-dumper": "^0.4.2",
"commander": "^12.0.0",
"cpu-features": "^0.0.10",
"http-proxy": "^1.18.1",
"https-proxy-agent": "^7.0.5",
"node-fetch": "2",
"semver": "^7.6.0",
"tar": "^6.2.1",
"winston": "^3.17.0"
},
"optionalDependencies": {
"cpu-features": "^0.0.10"
}
}
19 changes: 7 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions src/node/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { getCKBBinaryInstallPath, getCKBBinaryPath, readSettings } from '../cfg/setting';
import { encodeBinPathForTerminal } from '../util/encoding';
import { logger } from '../util/logger';
import CPUFeatures from 'cpu-features';

export async function installCKBBinary(version: string) {
const ckbBinPath = getCKBBinaryPath(version);
Expand Down Expand Up @@ -149,14 +148,30 @@
return 'zip';
}

let cachedIsPortable: boolean | undefined = undefined;

function isPortable(): boolean {
const features = CPUFeatures();
if (features.arch === 'x86') {
const flags = features.flags as CPUFeatures.X86CpuFlags;
// if lacks any of the following instruction, use portable binary
return !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq);
if (cachedIsPortable !== undefined) {
return cachedIsPortable;
}

try {
const CPUFeatures = require('cpu-features');
const features = CPUFeatures();
if (features.arch === 'x86') {
const flags = features.flags as any; // CPUFeatures.X86CpuFlags

Check warning on line 162 in src/node/install.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 162 in src/node/install.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
// if lacks any of the following instruction, use portable binary
cachedIsPortable = !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq);
} else {
cachedIsPortable = false;
}
} catch (error) {
// If cpu-features fails to load (e.g., on Windows without build tools), use portable binary
logger.warn('Failed to detect CPU features, using portable binary', error);
cachedIsPortable = true;
}
return false;

return cachedIsPortable;
}

function buildCKBGithubReleasePackageName(version: string, opt: { os?: string; arch?: string } = {}) {
Expand Down
Loading