blackwinter / ruby-filemagic

Ruby bindings to the magic(4) library, revised.
https://blackwinter.github.iom/ruby-filemagic
146 stars 34 forks source link

Compiling on Windows #10

Closed deployable closed 9 years ago

deployable commented 9 years ago

Compiling ruby-filemagic on Windows caused me some problems due to the dependencies. Ended up requiring the following:

Download file-5.21.tar.gz from ftp://ftp.astron.com/pub/file/ and extract somewhere.

Download libgnurx 2.5.1 bin + dev from sourceforge and extract somewhere

Build file

 LDFLAGS=-L/a/path/to/libgnurx-2.5.1/lib
 CFLAGS=-I/a/path/to/libgnurx-2.5.1/include
 ./configure --prefix=/a/path/to/file-2.21
 make install

From inside the DevKit msys shell

gem install ruby-filemagic -- --with-magic-dir=/a/path/to/file-2.21

It would be nice if there were precompiled libraries including the Magic for Windows platforms.

deployable commented 9 years ago

Actually this is only working in the 1.8.7/1.9.3 DevKit. Not so much in the 2/2.1 DevKit

blackwinter commented 9 years ago

I have actually no idea why I'm not providing fat binary gems for Windows. I'll look into it.

blackwinter commented 9 years ago

Finally got it to work! I still need to put some finishing touches on everything but could you try out the prerelease gem? It contains precompiled extensions for Ruby 1.9, 2.0, 2.1 and 2.2 on x86-mingw32/x86-mswin32-60 as well as a compiled magic database in case none is already present on the system (which it isn't unless you already have file installed).

deployable commented 9 years ago

Nice one! All the versions install OK.

In 1.9.3-p551 and 2.1.5-p273 the tests are failing in test_check. Running FileMagic#check causes Ruby to abort.

In 2.1.5-p273-x64 all I'm getting is LoadError: cannot load such file -- filemagic

blackwinter commented 9 years ago

Thanks for your thorough tests! I only tried it on Ruby 2.0-mingw32 myself.

Unfortunately, I wasn't able to wrap it up in time so I'll have to get back to it in the new year. I hope that works for you.

Cheers.

mscharley commented 9 years ago

Any chance of a x64 release of this? Or any way to help?

blackwinter commented 9 years ago

@mscharley Could you please open a new issue for this? I think Windows x64 support is a different matter and deserves a discussion of its own.

blackwinter commented 9 years ago

@deployable I've pushed another prerelease with only minor modifications. It would be great if you could give it a final check. I'm ignoring the test failure for "pyfile-compressed" for now since I don't know whether it's caused by Windows or by newer libmagic. I'm skipping test_check on Windows since I don't know why this one fails either; but I have added test_check_compiled which does work on Windows.

Regarding x64 support, please see my previous comment. (#11)

deployable commented 9 years ago

All good, just the 1 test failure for "pyfile-compressed" as you mentioned in 1.9.3 and 2.1.5.

I'd guess pyfile-compressed error is the lack of zlib.h as you define the FileMagic::MAGIC_COMPRESS flag. It appears libmagic has some fallback support to exec compression programs for systems with fork, which seems a bit horrible.

You could enforce the zlib requirement in extconf.rb. Then any chance of the exec stuff goes away but you might have to add zlib to your windows build?

blackwinter commented 9 years ago

Thanks for testing and also for investigating the failing test case. Unfortunately, zlib is not the issue here since Windows does not support fork. I'll just account for the fact that file won't look inside compressed files on Windows (efa43d6). So unless you have any objections, I'll probably release the new version later this week.

deployable commented 9 years ago

No objections, thanks for the updates!

It shouldn't need fork for zlib. There are two different defines in libmagic HAVE_FORK and BUILTIN_DECOMPRESS. fork for running the external gzip or other tools when zlib is not available.

blackwinter commented 9 years ago

Yes, that's what I thought too. But as you can see, all uses of BUILTIN_DECOMPRESS are wrapped by #if HAVE_FORK ;)

deployable commented 9 years ago

Ah I see!

blackwinter commented 9 years ago

I have released version 0.6.2 with precompiled extensions for Ruby 1.9, 2.0, 2.1 and 2.2 on x86-mingw32 and x86-mswin32-60. Thank you for your contribution.