Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support for Microsoft Windows #30

Closed
Mithgol opened this issue Dec 5, 2011 · 32 comments
Closed

Feature request: support for Microsoft Windows #30

Mithgol opened this issue Dec 5, 2011 · 32 comments

Comments

@Mithgol
Copy link
Contributor

Mithgol commented Dec 5, 2011

Several latest versions of Node.js support Microsoft Windows.

libffi homepage says the library can also work on Windows. (To be precise: atgreen/libffi says the project can be compiled by Microsoft's Visual C++ compiler since version 3.0.10 of libffi, which is dated Aug-23-11.)

Is it possible to hope that node-ffi would eventually be ported to Microsoft Windows as well? It would make writing numerous wrapper modules (around existing libraries) a whole lot easier, and in some cases that would also facilitate providing pre-compiled binaries to end users.

@ghost
Copy link

ghost commented Dec 5, 2011

I've looked into it a bit. if someone could update it to use all the correct new stuff for 0.6 (I think it's still utilizing some older things) I think I can get it done. I'm just had a bit of trouble trying to translate both old libev APIs at the same time as trying to get libffi integrated.

@TooTallNate
Copy link
Member

I have plans for this. I have an EIO shim for the old eio_custom() call: https://gist.github.com/1368935

The bigger problem (or rather, the unsolved problem) is that there's no node-waf on windows, meaning I believe that a gyp script will need to take it's place.

@ghost
Copy link

ghost commented Dec 5, 2011

Yeah I can handle either making a gyp for it or failing that providing the compiled binaries, as that is the usual mode of things for Windows. Most people don't have the tools the compile, but binaries work nearly universally between Windows installs anyway. I have libffi compiled using the the Visual C++ compiled path introduced not too long ago so it should be possible to use that with Node.

@Mithgol
Copy link
Contributor Author

Mithgol commented Dec 26, 2011

I have just read package.json and seen that node-ffi does not depend on any other npm-registered package. That means, @TooTallNate, if you still see the need of a gyp script as a big problem at installation time, then you (or some other dev) probably should follow @Benvie's idea and work around the problem by providing some pre-compiled Windows binary that won't need any npm install node-ffi at all.

You may have already seen how some other module devs already do that for some time and they seem successful. For example, since at least November 2011 node-firebird-libfbclient provides a pre-compiled (and zip-packed) Windows build:

Users unpack it, and it just works: there's no need to build anything on user's system by a script.

@ghost
Copy link

ghost commented Dec 26, 2011

Yeah I'm fairly sure the MSVC compiled lib-ffi target is portable between at least any of the same architecture version of Windows, so one for 32 bit and one for 64 bit. Possibly a single binary to cover them all but I'm not sure.

@TooTallNate
Copy link
Member

Ya I'll be looking into it shortly. It shouldn't be too bad, but it will require bundling libffi in this repo and adding a hand-crafted gyp file for libffi as well as this module. It should be relatively easy, I'll have a look into it soon.

Also, fwiw, I've been bundling a precompiled binary for windows in my node-weak module for a little while, and it's been working well.

Cheers guys!

Sent from my iPhone

On Dec 25, 2011, at 21:05, Brandon Benviereply@reply.github.com wrote:

Yeah I'm fairly sure the MSVC compiled lib-ffi target is portable between at least any of the same architecture version of Windows, so one for 32 bit and one for 64 bit. Possibly a single binary to cover them all but I'm not sure.


Reply to this email directly or view it on GitHub:
#30 (comment)

@TooTallNate
Copy link
Member

@Benvie @Mithgol So I've been trying to compile libffi on Windows today, and it's been a real pain. If either of you are knowledgeable Windows devs, I would be open to suggestions.

@ghost
Copy link

ghost commented Jan 5, 2012

When I compiled it I had MozillaBuild already from doing SpiderMonkey stuff which you can get here http://ftp.mozilla.org/pub/mozilla.org/mozilla/libraries/win32/MozillaBuildSetup-Latest.exe. The MSVC compile route for libffi compiles using the VC++ compiler and linker but still runs through the whole Mingw build system otherwise so it's kind of a Frankenstein thing. Ran the start-msvc10.bat in the base of mozilla-build, switch to libffi source directory, ./configure CC=./msvcc.sh LD=link CPP=\"cl -nologo -EP\" then make. Went pretty smooth.

@ghost
Copy link

ghost commented Jan 5, 2012

And yeah I already had mingw and whatnot setup but it wouldn't work. There has to be some magical dependencies that mozilla-build has that I couldn't figure out. Also don't try and build 64 bit.

@TooTallNate
Copy link
Member

Well node only builds as 32-bit on Windows anyways, so I wasn't too worried about 64-bit libffi :)
Thanks for the MozillaBuild link, I'll try that out a little later.

@ghost
Copy link

ghost commented Jan 5, 2012

Oh another thing I think I did when I compiled which might matter due to the whole MinGW different filesystem thing was specifying the whole path (make sure no spaces in it). My resulting config.log says that was the ultimate command used: .././configure --srcdir=.. --enable-builddir=i686-pc-mingw32 CC=/c/libs/libffi/msvcc.sh LD=link CPP=cl -nologo -EP

@TooTallNate
Copy link
Member

Yay! Seems like it compiled okay! Now to try to integrate with the node module...

@ghost
Copy link

ghost commented Jan 5, 2012

What's your take on it? I thought it might not be too bad once node-ffi was
updated to work with node 0.6 (like it seems you've done) since I don't
think there's any usage differences on lib-ffi's end right? Mostly just if
there's some bugs or something that manifest when using it in Windows.

On Wed, Jan 4, 2012 at 9:22 PM, Nathan Rajlich <
reply@reply.github.com

wrote:

Yay! Seems like it compiled okay! Now to try to integrate with the node
module...


Reply to this email directly or view it on GitHub:
#30 (comment)

@TooTallNate
Copy link
Member

So 2 problems so far:

  • dlfcn.h isn't available on Windows. Windows has it's own API for dynamically loading object files. We may be able to use this.
  • pthread.h isn't available on Windows. Windows has it's own API for threads and mutexes (node-ffi only uses the mutexes). Perhaps libuv has a mutex API.

There's some other more minor ones as well. But these are the bigger stopping points at the moment (though nothing impossible, just need some time). If you guys wanna help on that note I'd be happy :)

The Windows-compatible branch is being worked on in the gyp branch:
https://github.com/rbranson/node-ffi/compare/gyp

@ghost
Copy link

ghost commented Jan 5, 2012

So for pthreads I can help a bit there having looked into it initially when I was trying to port some modules to windows. First, libuv has had mutxes type support added for 0.7 because it'd be impossible to do things like isolates without it. For a more direct (and not requiring node 0.7) solution, there's a some good but simple wrapper header files that supply pthread functionality via Windows API with zero modification to original code for most things.

The simplest (if I recall) was this http://locklessinc.com/articles/pthreads_on_windows/ http://locklessinc.com/downloads/winpthreads.h

@TooTallNate
Copy link
Member

Ok so looks like there's uv_mutex_t, uv_lib_t, uv_dlopen(), uv_dlclose(). So it looks like we're covered :)
Looks like I just need to port over to the libuv APIs, which should be simple.

@TooTallNate
Copy link
Member

Shoot, you're right, looks like the uv_mutex_t type was recently added, and isn't available with the libuv that ships with node 0.6.x. So we're gonna need to use a Windows mutex API. A full blown pthread implementation is overkill IMO, since we just use the mutex.

@TooTallNate
Copy link
Member

lol, the windows mutex API is like a 1-1 mapping, just different names :\ CRITICAL_SECTION.

@ghost
Copy link

ghost commented Jan 5, 2012

Yeah that header is good there as well. It starts with the simplest and works up, so you can grab a subsection of it starting from the top and going down. At basic it implements mutexes and rwlocks with like 50 lines of simple wrapper code.

@TooTallNate
Copy link
Member

So I've started to work in the winpthreads.h and dlfcn-win32 libraries. They both needed some fixing in some places where explicit casting was needed.

New stumbling block is the mmap() function. Anyone know of a good polyfil for that?

@TooTallNate
Copy link
Member

Also, the "winpthreads.h" file seems to need a lot more fixes. It currently spits out like 50 errors when trying to compile :\

@ghost
Copy link

ghost commented Jan 6, 2012

I would be helping more on this but managed to myself in a serious car wreck last night hopefully will be home from the hospital tomorrow and will work on this.

@TooTallNate
Copy link
Member

@Mithgol @Benvie So in the gyp branch, there is a precompiled Windows binary and node-ffi should be 100% usable with it (the test cases pass 100%). I'll be releasing v0.5.0 soon, which will remove node-waf and node 0.4.x compatibility, in favor of gyp and precompiled binaries (of course, advanced users can still compile the bindings on their own if they desire). Please let me know if you have any problems when using it! Cheers!

@ghost
Copy link

ghost commented Jan 11, 2012

So far so good playing with the pre-compiled version on Windows 7, working right out of the box. Going to go through the whole compile process...once I'm finished making dialogs popup using the win32 API and giggling. Awesome job!

@cretz
Copy link

cretz commented Jan 12, 2012

I just want to say awesome work fellas. I am looking forward to this feature to perform Windows domain authentication in SQL Server as the local, logged-in user via SSPI (basically just a couple calls in security.dll).

@TooTallNate
Copy link
Member

@cretz Thanks for the compliment :) Everything should be good to go if you try out the gyp branch. Please let me know if you run into any problems in the process.

@TooTallNate
Copy link
Member

Ok guys so v0.5.0 is tagged in the repo. Just waiting for @rbranson to publish it on npm now. Gonna close this one.

@Mithgol
Copy link
Contributor Author

Mithgol commented Jan 13, 2012

@Benvie:

Going to go through the whole compile process...once I'm finished making dialogs popup using the win32 API and giggling.

I've also tried making dialogs popup using the win32 API, but run into some problem (unreadable dialog text) which (as far as I guess) is a result of some ABI mismatch (#34). However, if you've been making dialogs popup successfully, I may be wrong in my supposition. Please have a look at #34 for some time.

@Mithgol
Copy link
Contributor Author

Mithgol commented Jan 13, 2012

Forget it, I've already found where I was wrong.

@AndreKR
Copy link

AndreKR commented Jan 10, 2016

This looks great and gave me hope, but... where is it?

@AndreKR
Copy link

AndreKR commented Jan 10, 2016

Ah, found it... in 0.5.7, but for Node 0.6. Seems like since then no one took the trouble to build a new release and maybe add a binary section to package.json for node-pre-gyp? Or am I missing something?

@TooTallNate
Copy link
Member

@AndreKR There is no precompiled binary of node-ffi at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants