Skip to content

Loading…

Windows build #23

Merged
merged 6 commits into from

6 participants

@andreasbotsikas

I have modified the code a bit in order to build on windows.
I have also added a wintools folder that contains a script to generate the visual studio project and build it.

The provided script (node-gyp.bat) requires two environment variables in order to run properly:
NODE_ROOT: Points to the root of the Node's git repo. Download node from git (https://github.com/joyent/node) and build it using the vcbuild.bat script.
EXPAT_ROOT: The root installation folder of EXPAT so that the script can locate %EXPAT_ROOT%\Source\lib\expat.h.

To generate a visual studio 2010 project run
node-gyp.bat
If you want to generate the project and build it at once do:
node-gyp.bat make

@astro
node-XMPP member

Does the first commit mean we have to rename everything from node-expat to node_expat? Wouldn't it break less if node on Windows was fixed instead?

@andreasbotsikas

Yes, you are right, this is a node issue... I wanted to have it on windows to run an xmpp client and I couldn't wait for the node team to fix that...

@astro
node-XMPP member

Alright, at a second glimpse I can see that only the binary but not the package name has changed. That would work. But do we really need that tools/node-gyp* cruft? Isn't that included in node itself? Do you have any pointers regarding the GYP toolchain of 0.6?

@andreasbotsikas

Yes, it's only the binary name not the package. As for the gyp, I have created the #2337 pull request which was partially incorporated in node's main branch(the tools/node-gyp python script). The node-gyp tool I have added in this pull request is a variation of my original node-gyp tool. As mentioned in the node-gyp tool pull request, the node team is not willing to provide such a tool for the end users. This will be only for the module devs and the modules will be provided pre-build to the end-users.
As for my pull request on your module, I have added the node-gyp.bat only for windows since node-waf works just fine for the rest of the OSs.

@andreasbotsikas

If you read node's docs it says that "The module_name needs to match the filename of the final binary (minus the .node suffix).". So I guess this is the problem with the -.

@astro
node-XMPP member

Ok, good that I have waited merging. I'm not going to rename node-expat to node_expat as that would invalidate many package.json files.

@andreasbotsikas

Why is that? You package.json is right. the node-expat.js script in no problem. The module_name refers to the native code module loaded by your js script in :

var expat = require('../build/Release/node_expat.node');

The .node file name is at stake here. You can either implement a node_module_struct inside your module named node-expat_module (good luck with adding the - in your stuct name in windows) or you can use the old NODE_MODULE(node_expat, init) macro that is used by node for compatibility reasons(the one you have right now). Check node.cc and locate function Handle DLOpen(const v8::Arguments& args). You may read there the way node loads your native module (after loading the node-expat.js module).

Let me know if you need anything else prior merging.

@JohnRSim

Astro - Any plans to update and merge to get a windows build working for expat?

@andreasbotsikas

I can do a new pull request to incorporate the binding.gyp way of building modules if you plan to support windows. Check https://github.com/Worlize/WebSocket-Node that uses the new gyp method to see what I mean.

@JohnRSim

Sounds like a great idea to me.

@Sgt-Pepper

are there any plany on wether and when there will be a windows build?
BR , Florian

@astro
node-XMPP member

How has node.js' own support of Windows progressed in the meanwhile? Do we really need that .gyp stuff just for Windows?

@andreasbotsikas

Not anymore. Node is bundled with node-gyp so we only have to provide a binding.gyp which can run for *nix too... The "-" invalid character in the native module name, remains as a constrain... Do you want me to redo the pull request from the current master and add the binding.gyp in the root?

@astro
node-XMPP member

Sounds good. Only changing the module name is a no-go as it's a total compatibility breaker. Sorry. Are there any plans lifting this restriction someday?

@andreasbotsikas

The module name will not change. The only thing that will change is the name of the .node file. Nothing more. All depending scripts will run without any modification, at all... Even the current pull request does that.
Is there any other reason why you don't want this change?

@astro
node-XMPP member

Aw cool. No remaining objections, Sir!

@troyharvey

Thank you for this work! We're looking forward to this fix.

@dhruvbird

Any idea when this will go in? It seems a bunch of people want to be able to install a tool that depends on node-expat!! If you have a timeline, I could let them know.

@astro astro added a commit that referenced this pull request
@astro astro Merge 'andreasbotsikas/windows-build'
Fixes Github pull request #23: Windows build
11be45e
@astro astro merged commit 9b7a994 into node-xmpp:master
@astro
node-XMPP member

Sorry that it has taken me so long.

@dhruvbird

No problem - was just wondering if you forgot about it - thought I'd bump up the issue. So does this fix the windows build?
Also, are there any special instructions for building on windows (since node-waf doesn't run on windows)?

@andreasbotsikas

Well, by now we can remove all these root_node staff and go for node-gyp which is fully automated... I might get the time to redo it and I will let you know... Basically, the module.gyp file should be renamed to binding.gyp and use node-gyp instead.

@astro
node-XMPP member

Andreas, I haven't caught up with recent node development yet. Your contributions are highly appreciated. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 217 additions and 13 deletions.
  1. +2 −5 lib/node-expat.js
  2. +8 −7 node-expat.cc
  3. +13 −0 tools/Readme.txt
  4. +75 −0 tools/module.gyp
  5. +33 −0 tools/node-gyp
  6. +85 −0 tools/node-gyp.bat
  7. +1 −1 wscript
View
7 lib/node-expat.js
@@ -1,10 +1,7 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
-try {
- var expat = require('../build/Release/node-expat');
-} catch(e) {
- var expat = require('../build/default/node-expat');
-}
+// Only support nodejs v0.6 and on so no need to look for older module location
+var expat = require('../build/Release/node_expat.node');
/**
* Simple wrapper because EventEmitter has turned pure-JS as of node
View
15 node-expat.cc
@@ -369,10 +369,11 @@ class Parser : public ObjectWrap {
}
};
-
-
-extern "C" void init(Handle<Object> target)
-{
- HandleScope scope;
- Parser::Initialize(target);
-}
+extern "C" {
+ static void init (Handle<Object> target)
+ {
+ Parser::Initialize(target);
+ }
+ //Changed the name cause I couldn't load the module with - in their names
+ NODE_MODULE(node_expat, init);
+};
View
13 tools/Readme.txt
@@ -0,0 +1,13 @@
+This modules requires the expat library. You may download installation files from:
+http://sourceforge.net/projects/expat/files/expat_win32/
+
+The provided script (node-gyp.bat) requires two environment variables in order to run properly:
+NODE_ROOT: Points to the root of the Node's git repo. Download node from git (https://github.com/joyent/node) and build it using the vcbuild.bat script.
+EXPAT_ROOT: The root installation folder of EXPAT so that the script can locate %EXPAT_ROOT%\Source\lib\expat.h.
+
+To generate a visual studio 2010 project run
+node-gyp.bat
+If you want to generate the project and build it at once do:
+node-gyp.bat make
+
+
View
75 tools/module.gyp
@@ -0,0 +1,75 @@
+{
+ 'variables': {
+ 'module_name': 'node_expat',#Specify the module name here
+ 'library': 'shared_library', #This gypi file is about modules so everything is shared_library
+ 'target_arch': 'ia32', #The architecture is hardcoded because of a i386 harcoded element in the gyp make.py file
+ 'output_directory': '../build/Release', #The output dir resembles the old node-waf output in order to keep the olde references
+ },
+ 'targets': [
+ {
+ #Needed declarations for the target
+ 'target_name': '<(module_name)',
+ 'type': '<(library)',
+ 'product_name':'<(module_name)',
+ 'product_extension':'node',
+ 'product_dir':'<(output_directory)',
+ 'product_prefix':'',#remove the default lib prefix on each library
+
+ 'sources': [
+ '../node-expat.cc',
+ ],
+
+ 'include_dirs': [
+ '<(NODE_ROOT)/src',
+ '<(NODE_ROOT)/deps/v8/include',
+ '<(NODE_ROOT)/deps/uv/include',
+ '<(expat_root)/Source/lib',
+ ],
+
+ 'defines': [
+ 'ARCH="<(target_arch)"',
+ 'PLATFORM="<(OS)"',
+ '_LARGEFILE_SOURCE',
+ '_FILE_OFFSET_BITS=64',
+ ],
+
+ 'conditions': [
+ [ 'OS=="win"', {
+ 'defines': [
+ 'uint=unsigned int', #Windows doesn't have uint defined
+ # we need to use node's preferred "win32" rather than gyp's preferred "win"
+ 'PLATFORM="win32"',
+ ],
+ #we need to link to the node.lib file
+ 'libraries': [ '-l<(NODE_ROOT)/<(node_lib_folder)/node.lib','-l<(expat_root)/bin/libexpat.lib' ],
+ 'msvs_configuration_attributes': {
+ 'OutputDirectory': '<(output_directory)',
+ 'IntermediateDirectory': '<(output_directory)/obj',
+ },
+ 'msvs-settings': {
+ 'VCLinkerTool': {
+ 'SubSystem': 3, # /subsystem:dll
+ },
+ },
+ }],
+ [ 'OS=="mac"', {
+ 'defines': [
+ 'uint=unsigned int', #Mac doesn't have uint either
+ ],
+ #MAC x64 users don't forget to comment out all line in
+ #gyp\pylib\gyp\generator\make.py that contain append('-arch i386') (2 instances)
+ 'libraries': [ #this is a hack to specify this linker option in make
+ '-undefined dynamic_lookup',
+ '-lexpat',
+ ],
+ }],
+ [ 'OS=="linux"', {
+ 'libraries': [
+ '-lexpat',
+ ],
+ }]
+ ],
+ },
+ ] # end targets
+}
+
View
33 tools/node-gyp
@@ -0,0 +1,33 @@
+#!/bin/bash
+if [ -z "$NODE_ROOT" ]
+then
+ echo "NODE_ROOT enviromnet variable is not set! It must point to the root of the node's git directory and contain folders src, deps/v8/include and deps/uv/include"
+ echo "Check https://help.ubuntu.com/community/EnvironmentVariables on how to setup persistent environment variables"
+ echo "Probably the easiest way is to add an 'export NODE_ROOT=$HOME/node' in your ~/.bashrc file"
+ exit 1
+else
+ Proper_Node_Dir=1
+ [ -f "${NODE_ROOT}src/node.h" ] || { Proper_Node_Dir=0 && echo "ERROR: node.h was not in ${NODE_ROOT}src/node.h"; }
+ [ -f "${NODE_ROOT}deps/v8/include/v8.h" ] || { Proper_Node_Dir=0 && echo "ERROR: v8.h was not in ${NODE_ROOT}deps/v8/include/v8.h"; }
+ [ -f "${NODE_ROOT}deps/uv/include/uv.h" ] || { Proper_Node_Dir=0 && echo "ERROR: uv.h was not in ${NODE_ROOT}deps/uv/include/uv.h"; }
+ if [ $Proper_Node_Dir -lt 1 ]
+ then
+ echo "The $NODE_ROOT doesn't seem to be correct"
+ exit 1
+ fi
+fi
+
+
+#Check if the user has specified an argument or use the default module.gyp
+module_filename=""
+if [ -z "$1" ]
+then
+ [ -f "module.gyp" ] && module_filename="module.gyp" || echo "File module.gyp doesn't exist"
+else
+ [ -f "$1" ] && module_filename="$1" || echo "File $1 doesn't exist"
+fi
+#if we haven't got a gyp file exit
+[ -z "$module_filename" ] && echo "Gyp file not found!" && exit 1
+echo "Generating project"
+${NODE_ROOT}tools/gyp/gyp -f make $module_filename --depth=. -DNODE_ROOT=$NODE_ROOT -Dexpat_root=""
+echo "Run make to compile the module"
View
85 tools/node-gyp.bat
@@ -0,0 +1,85 @@
+@echo off
+@rem Check for nodejs build location variable
+if not defined NODE_ROOT goto nodebuild-not-found
+if not exist "%NODE_ROOT%\src\node.h" goto nodebuild-not-found
+if not exist "%NODE_ROOT%\deps\v8\include\v8.h" goto nodebuild-not-found
+if not exist "%NODE_ROOT%\deps\uv\include\uv.h" goto nodebuild-not-found
+if not exist "%NODE_ROOT%\tools\gyp\gyp" goto gyp-not-found
+
+@rem detect the location of the node.lib file
+set node_lib_folder=
+if exist "%NODE_ROOT%\Release\node.lib" set node_lib_folder=Release
+if not defined node_lib_folder if exist "%NODE_ROOT%\Debug\node.lib" set node_lib_folder=Debug
+if not defined node_lib_folder goto nodebuild-not-found
+
+@rem Check for expat location
+if not defined EXPAT_ROOT goto expat-not-found
+if not exist "%EXPAT_ROOT%\Source\lib\expat.h" goto expat-not-found
+echo NOTE: Make sure that "%EXPAT_ROOT%\BIN\" is in your path or that libexpat.dll otherwise you won't be able to load the module!
+@rem Check if user has specified the build command
+set requestedBuild= 0
+@rem Check if the first argument is make
+if "%1" == "make" set requestedBuild= 1
+if %requestedBuild% == 0 echo Run "node-gyp make" if you want to generate the project and build it at once.
+@rem Try to locate the gyp file
+set gypfile=
+if exist "module.gyp" set gypfile=module.gyp
+if not defined gypfile goto gyp-file-missing
+@rem Generate visual studio solution
+python %NODE_ROOT%\tools\gyp\gyp -f msvs -G msvs_version=2010 %gypfile% --depth=. -DNODE_ROOT=%NODE_ROOT% -Dnode_lib_folder=%node_lib_folder% -Dexpat_root=%EXPAT_ROOT%
+if errorlevel 1 goto exit-error
+if %requestedBuild% == 0 goto Finished
+@rem Build the solution
+@rem Check for visual studio tools if not already loaded
+if defined VCINSTALLDIR goto BuildSolution
+@rem Ensure that visual studio is available
+if not defined VS100COMNTOOLS goto msbuild-not-found
+if not exist "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" goto msbuild-not-found
+call "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat"
+@rem Check that vs is properly loaded
+if not defined VCINSTALLDIR goto msbuild-not-found
+:BuildSolution
+call :BuildSolutionBasedOnGypFilename %gypfile%
+:Finished
+echo Finished
+goto exit
+:msbuild-not-found
+echo Visual studio tools were not found! Please check the VS100COMNTOOLS path variable
+goto exit
+:gyp-not-found
+echo GYP was not found. Please check that gyp is located in %NODE_ROOT%/tools/gyp/
+goto exit
+:nodebuild-not-found
+echo Node build path not found! Please check the NODE_ROOT environment variable exists and that it points to the root of the git repo where you have build node
+goto exit
+:gyp-file-missing
+echo Could not locate a gyp file. module.gyp file was not found.
+goto exit
+:msbuild-not-found
+echo Visual studio tools were not found! Please check the VS100COMNTOOLS path variable
+goto exit
+:solutions-file-not-found
+echo Generated solution file %generatedslnfile% was not found!
+goto exit
+:expat-not-found
+echo Expat root path not found! Please check the EXPAT_ROOT environment variable exists and that it points to the installation folder or expat
+goto exit
+:expat-not-in-path
+echo Expat library is not in your path environment variable. Even if it builds, the module will not load!
+goto exit
+:exit-error
+echo An error occured. Please check the above output
+:exit
+@rem clear local variables
+set node_lib_folder=
+set requestedBuild=
+set gypfile=
+goto :EOF
+@rem Internal procedures
+:BuildSolutionBasedOnGypFilename
+set generatedslnfile=%~n1.sln
+if not exist %generatedslnfile% goto solutions-file-not-found
+@rem call msbuild to build the sln file
+msbuild.exe %generatedslnfile%
+if errorlevel 1 goto exit-error
+goto :EOF
View
2 wscript
@@ -17,7 +17,7 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
- obj.target = 'node-expat'
+ obj.target = 'node_expat'
obj.source = 'node-expat.cc'
obj.lib = 'expat'
obj.uselib = 'EXPAT'
Something went wrong with that request. Please try again.