|Building openssl for Ruby with Visual Studio
||[May. 11th, 2014|09:02 am]
Yet another "how to build" post mostly for my own reference, but you may find it useful.
Building the openssl lib for Ruby with Visual Studio is a bit of a pain. First, you'll need to install openssl itself (which you can build from source if you have Perl installed) or use their precompiled stuff. To build openssl itself from source, do this:
perl Configure VC-WIN32 --prefix=C:\usr\local
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
This assumes a 32-bit build, but you get the idea. Once that's done, you'll need to cd to the ext/openssl directory of wherever your Ruby source code is. Before you begin you will need to hand edit the extconf.rb file and change line 40 from "if $mingw" to "if File::ALT_SEPARATOR". This ensures that the gdi and wsock32 libs are linked properly.
This was reported at https://bugs.ruby-lang.org/issues/9817
With that done, run "ruby extconf.rb --with-openssl-dir=c:/usr/local", or wherever you installed openssl. Once that's complete you have to pause again and hand edit the generated Makefile because it's missing a declaration for $(top_srcdir). Look near the bottom and you'll see this line:
ossl.o: $(top_srcdir)/thread_native.h $(top_srcdir)/thread_$(THREAD_MODEL).h
Change that line to this:
ossl.o: ../../thread_native.h ../../thread_$(THREAD_MODEL).h
This was reported and inexplicably rejected at https://bugs.ruby-lang.org/issues/9824
EDIT: In Ruby 2.2 I just added "top_srcdir = ../.." to the top of the Makefile.
Then run "nmake" followed by "nmake install". Once that's done you can test it out by firing up irb and typing 'require "openssl"' to ensure you don't get an error.