From 4a1efb2b9c02dd5acbf9c0bb3f41267b5acaab11 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 28 Oct 2011 11:31:34 +0200 Subject: [PATCH] Support native extension loading on Windows --- common.gypi | 2 ++ src/node.h | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/common.gypi b/common.gypi index 8725fbf363..0a4183b1c9 100644 --- a/common.gypi +++ b/common.gypi @@ -106,6 +106,8 @@ # ... or that C implementations shouldn't use # POSIX names '_CRT_NONSTDC_NO_DEPRECATE', + 'BUILDING_V8_SHARED=1', + 'BUILDING_UV_SHARED=1', ], }], [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { diff --git a/src/node.h b/src/node.h index 8be8c3a196..a398f05956 100644 --- a/src/node.h +++ b/src/node.h @@ -22,6 +22,23 @@ #ifndef SRC_NODE_H_ #define SRC_NODE_H_ +#ifdef _WIN32 +# ifndef BUILDING_NODE_EXTENSION +# define NODE_EXTERN __declspec(dllexport) +# else +# define NODE_EXTERN __declspec(dllimport) +# endif +#else +# define NODE_EXTERN /* nothing */ +#endif + +#ifdef BUILDING_NODE_EXTENSION +# undef BUILDING_V8_SHARED +# undef BUILDING_UV_SHARED +# define USING_V8_SHARED 1 +# define USING_UV_SHARED 1 +#endif + // This should be defined in make system. // See issue https://github.com/joyent/node/issues/1236 #if defined(__MINGW32__) || defined(_MSC_VER) @@ -196,16 +213,24 @@ node_module_struct* get_builtin_module(const char *name); NULL, \ __FILE__ -#define NODE_MODULE(modname, regfunc) \ - node::node_module_struct modname ## _module = \ - { \ - NODE_STANDARD_MODULE_STUFF, \ - regfunc, \ - NODE_STRINGIFY(modname) \ - }; +#ifdef _WIN32 +# define NODE_MODULE_EXPORT __declspec(dllexport) +#else +# define NODE_MODULE_EXPORT /* empty */ +#endif + +#define NODE_MODULE(modname, regfunc) \ + extern "C" { \ + NODE_MODULE_EXPORT node::node_module_struct modname ## _module = \ + { \ + NODE_STANDARD_MODULE_STUFF, \ + regfunc, \ + NODE_STRINGIFY(modname) \ + }; \ + } #define NODE_MODULE_DECL(modname) \ - extern node::node_module_struct modname ## _module; + extern "C" node::node_module_struct modname ## _module; void SetErrno(uv_err_t err); void MakeCallback(v8::Handle object,