Compiling on Windows
deployable opened this issue · 14 comments
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.
Actually this is only working in the 1.8.7/1.9.3 DevKit. Not so much in the 2/2.1 DevKit
I have actually no idea why I'm not providing fat binary gems for Windows. I'll look into it.
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).
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
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.
Any chance of a x64 release of this? Or any way to help?
@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.
@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)
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?
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.
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.
Yes, that's what I thought too. But as you can see, all uses of BUILTIN_DECOMPRESS
are wrapped by #if HAVE_FORK
;)
Ah I see!
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.