Setup
# should use mingw32 packages, not gcc-mingw32
% sudo apt-get install mingw32-runtime mingw32 mingw32-binutils libssl-dev
% git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
% git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
% echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
% echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
% exec $SHELL -l
Install 2.0.0-p451 to rake-compiler
% CC=/usr/bin/i586-mingw32msvc-gcc rake-compiler cross-ruby VERSION=2.0.0-p451
Install 1.9.3-p545 to rake-compiler
% CC=/usr/bin/i586-mingw32msvc-gcc rake-compiler cross-ruby VERSION=1.9.3-p545
Install 1.8.7-p375 for rake-compilation
Require for cross compilation because 1.9.x or later can't do cross compilation.
See: https://github.com/luislavena/rake-compiler/issues/59
% rbenv install 1.8.7-p375
% rbenv shell 1.8.7-p375
% gem install bundler
NOTE
If you use another Ruby version like 1.9.3, you will get following error:
/home/repeatedly/cool.io/tmp/i386-mingw32/iobuffer_ext/2.0.0/rbconfig.rb:7:in `<module:RbConfig>': ruby lib version (2.0.0) doesn't match executable version (1.9.3) (RuntimeError)
Cool.io example
Rakefile
See cool.io: https://github.com/tarcieri/cool.io/blob/master/Rakefile#L23
Build
% cd /path/to/cool.io
$ rbenv shell 1.8.7-p375
% bundle install
% rake cross native gem RUBY_CC_VERSION=1.9.3:2.0.0
% ls pkg/
cool.io-1.2.0-x86-mingw32 cool.io-1.2.0-x86-mingw32.gem cool.io-1.2.0-x86-mswin32-60 cool.io-1.2.0-x86-mswin32-60.gem cool.io-1.2.0.gem