diff --git a/.github/workflows/libtest-windows.yml b/.github/workflows/libtest-windows.yml index 55324df..3db56ab 100644 --- a/.github/workflows/libtest-windows.yml +++ b/.github/workflows/libtest-windows.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: Test on node 18 +name: Test on node 20.8.0 # Controls when the workflow will run on: @@ -31,15 +31,18 @@ jobs: - name: Set up NodeJS uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20.8.0 # updating this needs updating build-clang++.ps1 - name: Install dependencies run: npm install --ignore-scripts - name: Build library - run: npm run build + run: npm run build - - name: Run node unit tests + - name: Run test - clang++ run: | - $env:NODE_ENV="production" - npm start + node index.js ./build/test-clang++.node + + - name: Run test - clangcl + run: | + node index.js ./build/Release/test-clangcl.node diff --git a/.github/workflows/libtest-windows20.yml b/.github/workflows/libtest-windows20.yml deleted file mode 100644 index 9285cf9..0000000 --- a/.github/workflows/libtest-windows20.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Test on node20 - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: [ master ] - pull_request: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-windows: - # The type of runner that the job will run on - runs-on: windows-2022 - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Set up NodeJS - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install dependencies - run: npm install --ignore-scripts - - - name: Build library - run: npm run build - - - name: Run node unit tests - run: | - $env:NODE_ENV="production" - npm start diff --git a/.github/workflows/libtest-windows21.yml b/.github/workflows/libtest-windows21.yml deleted file mode 100644 index aa2e6d1..0000000 --- a/.github/workflows/libtest-windows21.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Test on node20 - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: [ master ] - pull_request: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-windows: - # The type of runner that the job will run on - runs-on: windows-2022 - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Set up NodeJS - uses: actions/setup-node@v3 - with: - node-version: 21 - - - name: Install dependencies - run: npm install --ignore-scripts - - - name: Build library - run: npm run build - - - name: Run node unit tests - run: | - $env:NODE_ENV="production" - npm start diff --git a/CMakeLists.txt b/CMakeLists.txt index 55f98e4..35f656f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,16 @@ cmake_minimum_required(VERSION 3.18) - -project (webtransport) - - +project (test-clangcl) if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) # Generate node.lib execute_process(COMMAND ${CMAKE_LINKER} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) endif() - - - -# google quiche build parameters end - -#include_directories(${CMAKE_JS_INC}) -file(GLOB SOURCE_FILES "*.cc" "*.h") +file(GLOB SOURCE_FILES "*.cc" "*.c" "*.h") add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") -target_include_directories(${PROJECT_NAME} +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_JS_INC}) target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ) set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) - -execute_process(COMMAND node -p "require('node-addon-api').include" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE NODE_ADDON_API_DIR - ) -string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) -string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) -target_include_directories(${PROJECT_NAME} - PRIVATE ${NODE_ADDON_API_DIR}) - - - - - - diff --git a/build-clang++.ps1 b/build-clang++.ps1 new file mode 100644 index 0000000..f9244af --- /dev/null +++ b/build-clang++.ps1 @@ -0,0 +1,19 @@ +Remove-Item build\test.node, build\main.o -ErrorAction Ignore + +$NodeVersion = "20.8.0" # updating this needs updating libtest-windows.yml +$NodeIncFolder = "$env:USERPROFILE\.cmake-js\node-x64\v$NodeVersion\include\node" + +$cxx = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin\clang++.exe" + +if (!(Test-Path $cxx)) { + $cxx = "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang++.exe" +} + +if (Test-Path -Path $NodeIncFolder) { + & $cxx -c -I"$NodeIncFolder" -O2 -fexceptions -fno-omit-frame-pointer -fno-rtti -o build\main.o main.cc + & $cxx -shared -v -o build\test-clang++.node "$env:USERPROFILE\.cmake-js\node-x64\v$NodeVersion\win-x64\node.lib" build\main.o +} else { + Write-Error "$NodeIncFolder does not exist; please run cmake build first" + $host.SetShouldExit(1) + exit +} diff --git a/index.js b/index.js index d457114..3057de3 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,14 @@ import { createRequire } from 'module' +import assert from 'assert'; + const require = createRequire(import.meta.url) -const lib = require('./build/Release/webtransport.node') -lib.initLib() \ No newline at end of file +const path = process.argv[2]; +if (!path) { + throw new Error('Pass native module as first argument.'); +} + +const expected = 200000; +const value = require(path); +console.log('Got value:', value); +assert.strictEqual(value, expected); + diff --git a/main.cc b/main.cc index 92057d5..6860dd4 100644 --- a/main.cc +++ b/main.cc @@ -1,32 +1,14 @@ +#include +#include -#include +static napi_value Init(napi_env env, napi_value /* exports */) { + napi_status status; + napi_value result; -using namespace Napi; + status = napi_create_double(env, 200000, &result); + assert(status == napi_ok); - -void initLib(const Napi::CallbackInfo &info) -{ - Napi::Env env = info.Env(); - double timedelay = 200000; - auto val = Napi::Value::From(env, timedelay); - printf("val %lg %lg\n", val.ToNumber().DoubleValue(), timedelay); - if (val.ToNumber().DoubleValue() != timedelay) { - Napi::Error::New(env, "Val does not match! " + - std::to_string(val.ToNumber().DoubleValue())) - .ThrowAsJavaScriptException(); - return; - } - return; -} - - -Napi::Object Init(Napi::Env env, Napi::Object exports) -{ - Napi::Function initna = Function::New(env); - exports.Set("initLib", initna); - - // env.SetInstanceData(constr); - return exports; + return result; } -NODE_API_MODULE(webtransport, Init) +NAPI_MODULE(test, Init) diff --git a/package-lock.json b/package-lock.json index e7dbd06..8ebecb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "cmake-js": "^7.3.0", - "node-addon-api": "^8.0.0" + "cmake-js": "^7.3.0" } }, "node_modules/ansi-regex": { @@ -439,14 +438,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "node_modules/node-addon-api": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.0.0.tgz", - "integrity": "sha512-ipO7rsHEBqa9STO5C5T10fj732ml+5kLN1cAG8/jdHd56ldQeGj3Q7+scUS+VHK/qy1zLEwC4wMK5+yM0btPvw==", - "engines": { - "node": "^18 || ^20 || >= 21" - } - }, "node_modules/node-api-headers": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/node-api-headers/-/node-api-headers-1.1.0.tgz", diff --git a/package.json b/package.json index 5022499..fd4ea7f 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,13 @@ "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1", - "build": "cmake-js --CDnapi_build_version=6 -t ClangCL -G \"Visual Studio 17 2022\" " + "build": "npm run build-clangcl && npm run build-clang++", + "build-clangcl": "cmake-js --CDnapi_build_version=6 -t ClangCL -G \"Visual Studio 17 2022\" rebuild", + "build-clang++": "pwsh -File build-clang++.ps1" }, "author": "Marten Richter", "license": "ISC", "dependencies": { - "cmake-js": "^7.3.0", - "node-addon-api": "^8.0.0" + "cmake-js": "^7.3.0" } }