cross compilation for win32 with rake compiler

Issue #13 resolved
Michael Granger repo owner created an issue

Via Lars Kanis in [[http://rubyforge.org/tracker/index.php?func=detail&aid=27570&group_id=3214&atid=12398|Rubyforge Patch 27570]]:

I like ruby-pg very much, because it is the only driver with reliable working COPY support. But there is one annoyance: Installing on win32 is a pain. Even if there is a precompiled version it conflicts with the older openssl-dlls of the OneClickInstaller and it needs installed MS-runtime msvcr71.dll.

Attached you can find the solution I use since a while. Using rake-compiler a cross compiled pg-gem can be build on a linux host for the win32 platform. The generated gem is statically linked against libpq and libssl. OpenSSL and PostgreSQL are downloaded and compiled from the sources. There are no runtime dependencies to any but the standard Windows DLLs.

Install mingw32. On a debian based system this should work: {{{ apt-get install mingw32 }}}

Install the rake-compiler:

{{{ gem install rake-compiler }}}

Download and cross compile ruby for win32:

{{{ rake-compiler cross-ruby VERSION=1.8.6-p287 }}}

Download and cross compile pg for win32:

{{{ rake cross native gem RUBY_CC_VERSION=1.8.6 }}}

If everything works, there should be {{{pg-VERSION-x86-mswin32.gem}}} in the pkg directory.

Based on rake-compiler one can even build a source gem:

{{{ rake gem }}}

or a native gem:

{{{ rake native gem }}}

Comments (11)

  1. Michael Granger reporter
    • changed status to open

    Coincidentally, I converted the library to use rake-compiler this morning (see 4cbcf197cb82 ), but I'll look at integrating the static compilation portions of your patch.

  2. Michael Granger reporter

    Ah, excellent! That'll make things much easier.

    I have yet to get rake-compiler's cross-compilation system to successfully compile Ruby, but I'll hopefully figure it out in the next couple of days. I'm pretty sure it's something particular to my shell environment. Once I have that working and have things peer-reviewed, I'll release.

  3. Lars Kanis
    • changed status to new

    For me (Ubuntu 8.04LTS) it just worked with the above commands. But cross compiling Ruby 1.8.7 failed, at least with rake-compiler 0.6.0.

  4. Michael Granger reporter
    • changed status to open

    I'm confused, does Ubuntu 8.04 have Ruby 1.8.6, or did you not have to cross-compile Ruby to make it work?

  5. Lars Kanis

    You're right. Ubuntu 8.04 has ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux], but the host version doesn't matter for cross compilation. You always need a cross compiled ruby in order to compile extensions.

    I just retried to cross compile ruby 1.8.7 with rake-compiler 0.7.0. It currently does not work out of the box. But any versions of 1.8.6-series should compile quite fine: rake-compiler cross-ruby VERSION=1.8.6-p383

    Attached you can find one more update of the patch based on current default-branch.

  6. Lars Kanis

    The problem with ruby 1.8.7 described above, was a bug in the ruby build process, that was fixed with ruby-1.8.7-p248. So this should work as usual: rake-compiler cross-ruby VERSION=1.8.7-p248

  7. Michael Granger reporter

    I know you need a cross-compiled Ruby for compiled extensions; hence my confusion when you said it worked and then said cross-compiling Ruby 1.8.7 failed. I missed that those were different versions. :)

    Thanks for updating your patch again; I'll try to get it applied today so you can stop chasing the tip!

    I guess since the RubyInstaller only installs 1.8.6 or 1.9.1 (which I'd forgotten since I last used it), it doesn't make sense to distribute a cross-compiled version against 1.8.7, right? I've switched all my development machines to 1.8.7, but I guess I'll keep testing everything with a binary extension under 1.8.6 for the time being.

  8. Michael Granger reporter

    Applied patch for static cross-compilation of win32 gem from Lars Kanis with a few changes to support MacOS X as a host as well. Closes #13. Thanks Lars!

    38a0d2a90664

  9. Log in to comment