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

penghui 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 b6d2917  [Build] Add windows building configurations (#169)
b6d2917 is described below

commit b6d2917bc0f2fc8592d047de7d107bfe7911617c
Author: ran <[email protected]>
AuthorDate: Fri Aug 27 12:20:05 2021 +0800

    [Build] Add windows building configurations (#169)
---
 .gitignore  |  1 +
 README.md   | 17 ++++++++++++++++-
 binding.gyp | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index 7a744e8..d89b6b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,4 @@
 build/
 node_modules/
 report/
+.idea
diff --git a/README.md b/README.md
index adeae3d..e0744ad 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,18 @@ If an incompatible version of the C++ client is installed, 
you may fail to build
 
 ## How to install
 
-### Please install pulsar-client in your project:
+### Install on windows
+
+1. [Build the Pulsar C++ client on 
windows](https://pulsar.apache.org/docs/en/next/client-libraries-cpp/).
+
+2. Set the variable `PULSAR_CPP_DIR` with the `pulsar-client-cpp` path in a 
Windows command tool.
+
+```shell
+# for example
+set PULSAR_CPP_DIR=C:\pulsar\pulsar-client-cpp
+```
+
+### Install pulsar-client to your project
 
 ```shell
 $ npm install pulsar-client
@@ -72,6 +83,10 @@ $ cd pulsar-client-node
 $ npm install
 ```
 
+> **Note**
+>
+> If you build `pulsar-client-node on` windows, you need to set the variable 
`PULSAR_CPP_DIR` first, then install npm (run the command `npm install`) in a 
Windows command-line tool.
+
 ### Rebuild Pulsar client library:
 
 ```shell
diff --git a/binding.gyp b/binding.gyp
index 4b7b2f4..a21a45f 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -18,14 +18,22 @@
 #
 
 {
+  'conditions': [
+    ['OS=="win"', {
+      'variables': {
+       'pulsar_cpp_dir%': '<!(echo %PULSAR_CPP_DIR%)',
+      },
+    }]
+  ],
   "targets": [
     {
       "target_name": "Pulsar",
       "cflags!": ["-fno-exceptions"],
       "cflags_cc!": ["-fno-exceptions"],
-      "include_dirs": ["<!@(node -p \"require('node-addon-api').include\")"],
-      "dependencies": ["<!@(node -p \"require('node-addon-api').gyp\")"],
-      "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
+      "include_dirs": [
+        "<!@(node -p \"require('node-addon-api').include\")",
+      ],
+      "defines": ["NAPI_VERSION=4", "NAPI_DISABLE_CPP_EXCEPTIONS=1"],
       "sources": [
         "src/addon.cc",
         "src/Message.cc",
@@ -39,7 +47,42 @@
         "src/Reader.cc",
         "src/ReaderConfig.cc",
       ],
-      "libraries": ["-lpulsar"],
+      'conditions': [
+        ['OS=="win"', {
+          "include_dirs": [
+            "<(pulsar_cpp_dir)\include",
+          ],
+          "libraries": [
+            "-l<(pulsar_cpp_dir)\\build\lib\Release\pulsar.lib"
+          ],
+          "dependencies": [
+            "<!(node -p \"require('node-addon-api').gyp\")"
+          ],
+          "copies": [
+            {
+              "destination": "<(PRODUCT_DIR)",
+              "files": [
+                "<(pulsar_cpp_dir)\\build\lib\Release\pulsar.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\libcurl.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\libprotobuf.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\libssl-1_1-x64.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\libcrypto-1_1-x64.dll",
+                "<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\dl.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\snappy.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\zlib1.dll",
+                
"<(pulsar_cpp_dir)\\vcpkg_installed\\x64-windows\\bin\zstd.dll",
+              ]
+            }
+          ]
+        }, {  # 'OS!="win"'
+          "libraries": [
+            "-lpulsar",
+          ],
+          "dependencies": [
+            "<!@(node -p \"require('node-addon-api').gyp\")"
+          ],
+        }]
+      ]
     }
   ]
 }

Reply via email to