Skip to content

Commit 232e272

Browse files
committed
some settings required to work in this project
1 parent 792ac2e commit 232e272

File tree

8 files changed

+132
-14
lines changed

8 files changed

+132
-14
lines changed

.github/workflows/build.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ jobs:
2828
runs-on: ${{ matrix.os }}
2929
strategy:
3030
matrix:
31-
os: [ macos-10.15, macos-11, macos-12, ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022 ]
32-
node: [ 14, 16, 18 ]
33-
exclude:
34-
- os: ubuntu-18.04
35-
node: 18
31+
os: [ macos-12, macos-13, macos-14, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022 ] # ubuntu-24.04 does not bring LLVM 14
32+
node: [ 18, 20, 22 ]
3633
steps:
3734
- name: Fetch Codebase
38-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3936
- name: Setup Node.js
40-
uses: actions/setup-node@v3
37+
uses: actions/setup-node@v4
4138
with:
4239
node-version: ${{ matrix.node }}
4340
check-latest: true
@@ -46,6 +43,7 @@ jobs:
4643
run: |
4744
brew update
4845
brew install llvm@${{ env.LLVM_VERSION_MAJOR }} ninja
46+
echo "cmake_LLVM_DIR=$($(brew --prefix llvm@${{ env.LLVM_VERSION_MAJOR }})/bin/llvm-config --cmakedir)" > .npmrc
4947
- name: Install LLVM and Ninja on Ubuntu
5048
if: startsWith(matrix.os, 'ubuntu')
5149
run: |
@@ -61,7 +59,7 @@ jobs:
6159
curl -sLO https://github.com/ApsarasX/llvm-windows/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PREBUILT_FILE
6260
Expand-Archive -Path $LLVM_PREBUILT_FILE -DestinationPath .
6361
$LLVM_CMAKE_DIR = "$pwd\\LLVM-$LLVM_VERSION-win64\\lib\\cmake\\llvm"
64-
npm config set cmake_LLVM_DIR $LLVM_CMAKE_DIR
62+
echo "cmake_LLVM_DIR=$LLVM_CMAKE_DIR"> .npmrc
6563
- name: Install Dependencies
6664
run: npm install --ignore-scripts
6765
- name: CMake Build Debug and Test
@@ -74,4 +72,4 @@ jobs:
7472
run: |
7573
npm run clear
7674
npm run build:release
77-
npm test
75+
npm test

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
.npmrc
2+
13
.idea/
2-
.vscode/
4+
.vscode/*
5+
!.vscode/launch.json
6+
!.vscode/settings.json
37

48
cmake-build-*/
59

.npmrc.template

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmake_LLVM_DIR=/opt/homebrew/opt/llvm@14/lib/cmake/llvm/

.vscode/launch.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Jest: Run tests in current file",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeExecutable": "npx",
12+
"program": "jest",
13+
"args": [
14+
"${relativeFile}",
15+
],
16+
"console": "integratedTerminal",
17+
"skipFiles": [
18+
"<node_internals>/**"
19+
],
20+
"outFiles": [
21+
"${workspaceFolder}/**/*.js"
22+
]
23+
},
24+
{
25+
"name": "Vitest: Run tests in current file",
26+
"type": "node",
27+
"request": "launch",
28+
"runtimeExecutable": "npx",
29+
"program": "vitest",
30+
"args": [
31+
"run",
32+
"${relativeFile}",
33+
],
34+
"console": "integratedTerminal",
35+
"skipFiles": [
36+
"<node_internals>/**"
37+
],
38+
"outFiles": [
39+
"${workspaceFolder}/**/*.js"
40+
]
41+
},
42+
{
43+
/* execute npm build:debug before running this! */
44+
"name": "LLDB: Debug LLVM-binding native parts during Vitest execution",
45+
"type": "lldb",
46+
"request": "launch",
47+
"program": "node",
48+
"sourceLanguages": ["cpp", "javascript"],
49+
"args": [
50+
"${workspaceFolder}/node_modules/vitest/dist/cli-wrapper.js",
51+
"run",
52+
"${relativeFile}",
53+
],
54+
},
55+
]
56+
}

.vscode/settings.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"C_Cpp.default.cStandard": "c17",
3+
"C_Cpp.default.cppStandard": "c++17",
4+
"C_Cpp.default.includePath": [
5+
"/opt/homebrew/opt/llvm@14/include",
6+
"${userHome}/.cmake-js/node-*/v*/include/node",
7+
"${workspaceFolder}/node_modules/node-addon-api",
8+
"${workspaceFolder}/include",
9+
],
10+
"clangd.fallbackFlags": [
11+
"-std=c++17",
12+
"-xc++-header",
13+
"-I/opt/homebrew/opt/llvm@14/include",
14+
"-I${userHome}/.cmake-js/node-arm64/v18.18.2/include/node/", /* switch to your arch & version here! */
15+
"-I${workspaceFolder}/node_modules/node-addon-api",
16+
"-I${workspaceFolder}/include",
17+
]
18+
}

README.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ listed in the [TypeScript definition file](./llvm-bindings.d.ts).
2929

3030
### Install on macOS
3131

32+
Make sure `llvm@14` as well as `cmake` are available, e.g. via
3233
```shell
3334
# install cmake and llvm by homebrew
3435
brew install cmake llvm@14
36+
```
37+
38+
Tell the extra build tool used here (`cmake-js`) where to find some cmake-specific integration setup of LLVM 14, then `npm install` the package.
39+
1. First create the required new file named `.npmrc`
40+
* alternatively, copy `.npmrc.template` to `.npmrc` and adapt the configured path if needed, `brew --prefix llvm@14` gives you the install dir of LLVM14.
41+
2. Then run `npm install llvm-bindings`
42+
43+
```shell
44+
# specify the LLVM cmake directory for cmake-js
45+
# also see '.npmrc.template' for reference
46+
echo "cmake_LLVM_DIR=$($(brew --prefix llvm@14)/bin/llvm-config --cmakedir)" > .npmrc
3547

3648
# install llvm-bindings by npm
3749
npm install llvm-bindings
@@ -54,15 +66,18 @@ npm install llvm-bindings
5466

5567
### Install on Windows
5668

69+
_Update:_ Use LLVM in version `14.0.6` sequently.
70+
5771
First, please refer to [Build LLVM from sources on Windows 10](https://github.com/ApsarasX/llvm-bindings/wiki/Build-LLVM-from-source-code-on-Windows-10) to build LLVM. An alternative is to download [prebuilt LLVM binary](https://github.com/ApsarasX/llvm-windows/releases).
5872

59-
Then, find the `llvm-config` command in your LLVM build directory and execute `llvm-config --cmakedir` to get LLVM cmake directory, assuming `C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm`.
73+
Then, find the `llvm-config` command in your LLVM build directory and execute `llvm-config --cmakedir` to get LLVM cmake directory, assuming `C:\Users\dev\llvm-14.0.6.src\build\lib\cmake\llvm`.
6074

6175
Finally, execute the following commands.
6276

6377
```shell
6478
# specify the LLVM cmake directory for cmake-js
65-
npm config set cmake_LLVM_DIR C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm
79+
# also see '.npmrc.template' for reference
80+
echo "cmake_LLVM_DIR=C:\Users\dev\llvm-13.0.1.src\build\lib\cmake\llvm" > .npmrc
6681

6782
# install llvm-bindings by npm
6883
npm install llvm-bindings
@@ -72,10 +87,14 @@ npm install llvm-bindings
7287
7388
### Custom LLVM Installation
7489
You can use the npm configuration options to set the path to the LLVM cmake directory. This is needed if you don't want to use the system default LLVM installation.
90+
(Formerly, `npm config` was used here. Meanwhile npm validates the config keys for being known and valid, and rejects custom keys.)
91+
7592

7693
```shell
7794
# specify the llvm cmake directory by npm and cmake-js
78-
npm config set cmake_LLVM_DIR $(path-to-llvm/bin/llvm-config --cmakedir)
95+
# also see '.npmrc.template' for reference
96+
# on macos `path-to-llvm` can be obtained via `brew --prefix llvm@14`
97+
echo "cmake_LLVM_DIR=$(path-to-llvm/bin/llvm-config --cmakedir)" > .npmrc
7998

8099
# install llvm-bindings by npm
81100
npm install llvm-bindings

tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"tests/**/*.ts",
66
],
77
"compilerOptions": {
8+
"noEmit": true,
89
"target": "ES5",
910
"module": "commonjs",
1011
"strict": true,
1112
"moduleResolution": "node",
1213
"esModuleInterop": true,
13-
"forceConsistentCasingInFileNames": true
14+
"forceConsistentCasingInFileNames": true,
15+
"skipLibCheck": true
1416
}
1517
}

vitest.config.mts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//import { defineConfig } from "vitest/config"
2+
3+
export default /*defineConfig*/({
4+
test: {
5+
deps: {
6+
interopDefault: true
7+
},
8+
include: ['**/*.{test,spec}.ts'],
9+
exclude: ['**/node_modules/**', '**/dist/**'],
10+
globals: true,
11+
typecheck: {
12+
//enabled: false
13+
},
14+
poolOptions: {
15+
threads: {
16+
singleThread: true
17+
}
18+
}
19+
}
20+
});

0 commit comments

Comments
 (0)