This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-node.git


The following commit(s) were added to refs/heads/master by this push:
     new 25e8f27  [feat] Support windows build napi of static link c++ lib. 
(#238)
25e8f27 is described below

commit 25e8f27631bc8ec8318d63b4870548427eefa81f
Author: Baodi Shi <[email protected]>
AuthorDate: Tue Nov 1 12:02:09 2022 +0800

    [feat] Support windows build napi of static link c++ lib. (#238)
    
    ### Motivation
    
    #235
    
    Support windows build napi of static link c++ lib(x64 and x86).
    
    ### Modifications
    - Download the C++ static library directly instead of recompiling
    
    **Note**: Since there is no static library release for C++ yet, Use a 
[temporary 
release](https://github.com/BewareMyPower/pulsar-client-cpp/releases/tag/v3.1.0-rc-20221026-windows).
---
 .github/workflows/ci-build-release-napi.yml | 67 +++++++++++++++++++++++++++--
 .github/workflows/ci-pr-validation.yml      | 62 +++++++++++++++++++++++++-
 binding.gyp                                 | 30 ++-----------
 pkg/windows/download-cpp-client.bat         |  8 ++++
 tmp-pulsar-client-cpp-version.txt           |  1 +
 5 files changed, 136 insertions(+), 32 deletions(-)

diff --git a/.github/workflows/ci-build-release-napi.yml 
b/.github/workflows/ci-build-release-napi.yml
index 08348fa..9e702dd 100644
--- a/.github/workflows/ci-build-release-napi.yml
+++ b/.github/workflows/ci-build-release-napi.yml
@@ -22,7 +22,6 @@ jobs:
           - x86_64
 #          - arm64
         nodejs:
-          - 16
           - 18
     steps:
       - uses: actions/checkout@v3
@@ -67,7 +66,6 @@ jobs:
 
       - name: Upload artifacts
         uses: actions/upload-artifact@v3
-        if: matrix.nodejs == 16
         with:
           name: macos-${{matrix.nodejs}}-${{matrix.arch}}
           path: build/stage/*/*.tar.gz
@@ -84,7 +82,6 @@ jobs:
           - 'linux_glibc'
           - 'linux_musl'
         nodejs:
-          - 16
           - 18
         cpu:
           - {arch: 'x86_64', platform: 'x86_64'}
@@ -121,7 +118,69 @@ jobs:
 
       - name: Upload artifacts
         uses: actions/upload-artifact@v3
-        if: matrix.nodejs == 16
         with:
           name: ${{matrix.image}}-${{matrix.nodejs}}-${{matrix.cpu.platform}}
           path: build/stage/*/*.tar.gz
+
+  windows-napi:
+    name: Build NAPI windows - Node ${{matrix.nodejs}} - ${{matrix.arch}}
+    runs-on: windows-2022
+    timeout-minutes: 3000
+
+    strategy:
+      fail-fast: false
+      matrix:
+        arch:
+          - x64
+          - x86
+        nodejs:
+          - 18
+    steps:
+      - uses: actions/checkout@v3
+      - name: Use Node.js ${{ matrix.nodejs }}
+        uses: actions/setup-node@v3
+        with:
+          node-version: ${{ matrix.nodejs }}
+          architecture: ${{ matrix.arch }}
+          cache: 'npm'
+
+      - name: Cache CPP Client
+        id: cache-dependencies
+        uses: actions/cache@v3
+        with:
+          path: pkg/windows/
+          key: ${{ runner.os }}-${{ matrix.arch }}-${{ 
hashFiles('tmp-pulsar-client-cpp-version.txt') }}
+
+      - name: Add env vars
+        shell: bash
+        run: |
+          if [ "${{ matrix.arch }}" = "x86" ]; then
+            echo "TARGET=ia32" >> $GITHUB_ENV
+          else
+            echo "TARGET=${{ matrix.arch }}" >> $GITHUB_ENV
+          fi
+
+      - name: Download CPP Client
+        if: steps.cache-dependencies.outputs.cache-hit != 'true'
+        run: |
+          pkg/windows/download-cpp-client.bat ${{ matrix.arch }}
+
+      - name: Build Node binaries lib
+        run: |
+          npm install --ignore-scripts
+          npx node-pre-gyp configure --target_arch=${{ env.TARGET }}
+          npx node-pre-gyp build --target_arch=${{ env.TARGET }}
+
+      - name: Test loading Node binaries lib
+        run: |
+          node pkg/load_test.js
+
+      - name: Package Node binaries lib
+        run: |
+          npx node-pre-gyp package --target_arch=${{ env.TARGET }}
+
+      - name: Upload artifacts
+        uses: actions/upload-artifact@v3
+        with:
+          name: windows-${{matrix.nodejs}}-${{matrix.arch}}
+          path: build/stage/*/*.tar.gz
diff --git a/.github/workflows/ci-pr-validation.yml 
b/.github/workflows/ci-pr-validation.yml
index a1d6ec2..2b9c920 100644
--- a/.github/workflows/ci-pr-validation.yml
+++ b/.github/workflows/ci-pr-validation.yml
@@ -50,7 +50,7 @@ jobs:
         arch:
           - x86_64
         nodejs:
-          - 16
+          - 18
     steps:
       - uses: actions/checkout@v3
       - name: Use Node.js ${{ matrix.nodejs }}
@@ -113,9 +113,10 @@ jobs:
           - 'linux_glibc'
           - 'linux_musl'
         nodejs:
-          - 16
+          - 18
         cpu:
           - {arch: 'x86_64', platform: 'x86_64'}
+          - {arch: 'aarch64', platform: 'arm64'}
 
     steps:
       - name: checkout
@@ -145,3 +146,60 @@ jobs:
         run: |
           docker run -i -v $PWD:/pulsar-client-node build:latest \
               /pulsar-client-node/pkg/build-napi-inside-docker.sh
+
+  windows-napi:
+    name: Build NAPI windows - Node ${{matrix.nodejs}} - ${{matrix.arch}}
+    runs-on: windows-2022
+    timeout-minutes: 3000
+
+    strategy:
+      fail-fast: false
+      matrix:
+        arch:
+          - x64
+          - x86
+        nodejs:
+          - 18
+    steps:
+      - uses: actions/checkout@v3
+      - name: Use Node.js ${{ matrix.nodejs }}
+        uses: actions/setup-node@v3
+        with:
+          node-version: ${{ matrix.nodejs }}
+          architecture: ${{ matrix.arch }}
+          cache: 'npm'
+
+      - name: Cache CPP Client
+        id: cache-dependencies
+        uses: actions/cache@v3
+        with:
+          path: pkg/windows/
+          key: ${{ runner.os }}-${{ matrix.arch }}-${{ 
hashFiles('tmp-pulsar-client-cpp-version.txt') }}
+
+      - name: Add env vars
+        shell: bash
+        run: |
+          if [ "${{ matrix.arch }}" = "x86" ]; then
+            echo "TARGET=ia32" >> $GITHUB_ENV
+          else
+            echo "TARGET=${{ matrix.arch }}" >> $GITHUB_ENV
+          fi
+
+      - name: Download CPP Client
+        if: steps.cache-dependencies.outputs.cache-hit != 'true'
+        run: |
+          pkg/windows/download-cpp-client.bat ${{ matrix.arch }}
+
+      - name: Build Node binaries lib
+        run: |
+          npm install --ignore-scripts
+          npx node-pre-gyp configure --target_arch=${{ env.TARGET }}
+          npx node-pre-gyp build --target_arch=${{ env.TARGET }}
+
+      - name: Test loading Node binaries lib
+        run: |
+          node pkg/load_test.js
+
+      - name: Package Node binaries lib
+        run: |
+          npx node-pre-gyp package --target_arch=${{ env.TARGET }}
diff --git a/binding.gyp b/binding.gyp
index 64c7275..1ed901d 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -18,13 +18,6 @@
 #
 
 {
-  'conditions': [
-    ['OS=="win"', {
-      'variables': {
-        'os_arch%': '<!(echo %OS_ARCH%)',
-      }
-    }],
-  ],
   "targets": [
     {
       "target_name": "Pulsar",
@@ -70,7 +63,8 @@
         }],
         ['OS=="win"', {
           "defines": [
-            "_HAS_EXCEPTIONS=1"
+            "_HAS_EXCEPTIONS=1",
+            "PULSAR_STATIC"
           ],
           "msvs_settings": {
             "VCCLCompilerTool": {
@@ -78,29 +72,13 @@
             },
           },
           "include_dirs": [
-            "<(pulsar_cpp_dir)\include",
+            "pkg\\windows\\pulsar-cpp\\include",
           ],
           "libraries": [
-            "-l<(pulsar_cpp_dir)\\lib\Release\pulsar.lib"
+            "..\\pkg\\windows\\pulsar-cpp\\lib\\pulsarWithDeps.lib"
           ],
           "dependencies": [
             "<!(node -p \"require('node-addon-api').gyp\")"
-          ],
-          "copies": [
-            {
-              "destination": "<(PRODUCT_DIR)",
-              "files": [
-                "<(pulsar_cpp_dir)\\lib\Release\pulsar.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcurl.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libprotobuf.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libssl-1_1-x64.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcrypto-1_1-x64.dll",
-                "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\dl.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\snappy.dll",
-                
"<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zlib1.dll",
-                "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zstd.dll",
-              ]
-            }
           ]
         }, {  # 'OS!="win"'
           "dependencies": [
diff --git a/pkg/windows/download-cpp-client.bat 
b/pkg/windows/download-cpp-client.bat
new file mode 100644
index 0000000..825511b
--- /dev/null
+++ b/pkg/windows/download-cpp-client.bat
@@ -0,0 +1,8 @@
+cd %~dp0
+set arch=%1
+:: TODO: Fetch from official release, change to apache release version and 
path.
+set /P CPP_VERSION=<..\..\tmp-pulsar-client-cpp-version.txt
+curl -O -L 
https://github.com/BewareMyPower/pulsar-client-cpp/releases/download/%CPP_VERSION%/pulsar-client-cpp-%arch%-windows-static.zip
+7z x pulsar-client-cpp-%arch%-windows-static.zip -opulsar-cpp
+dir
+
diff --git a/tmp-pulsar-client-cpp-version.txt 
b/tmp-pulsar-client-cpp-version.txt
new file mode 100644
index 0000000..fb8ae7b
--- /dev/null
+++ b/tmp-pulsar-client-cpp-version.txt
@@ -0,0 +1 @@
+v3.1.0-rc-20221026-windows

Reply via email to