Hello Steve,
> Congrats on the tremendous work towards a turn-key Ruby installer on
> Windows!
>
> I'm currently using the following components:
>
> * Ruby 1.9.2 - using latest rubyinstaller GitHub repo (needed
> "autocrlf=false" in my .gitconfig)
> * EventMachine - using latest GitHub repo (standard gem fails to
> install)
Yes, I believe there are some changes and previous conversations here
about 1.9.2
> * em-http-request - using standard gem
>
> The following code works great:
>
> require 'em-http-request'
>
> EventMachine.run {
> http = EventMachine::HttpRequest.new(
> 'http://www.google.com/'
> ).get
>
> http.callback {
> p http.response_header.status
> p http.response_header
> p http.response
>
> EventMachine.stop
> }
> }
>
> However, if the URL is changed to https, such as:
>
> 'https://www.53.com/wps/portal/personal'
>
> then, I see the following error:
>
> --
>
> terminate called after throwing an instance of 'std::runtime_error'
> what(): Encryption not available on this event-machine
>
The problem is that EventMachine for SSL is trying to link and use
OpenSSL, and is not there. It needs OpenSSL development headers and
such.
As a workaround, you can try building and installing EventMachine
against sandbox/openssl:
gem install eventmachine -- --with-openssl-dir=....
If you check extconf.rb of EM I believe that is supported, or should
be if not :-)
>
> After much fiddling, I was unable to get EventMachine to compile the
> SSL libraries. However, I see that openssl was already compiled when I
> originally compiled Ruby 1.9.2 using the rubyinstaller.
>
> Is there any way to simply use the already compiled DLL's and existing
> header files that are on my system from when I compiled Ruby 1.9.2?
Oops, need to read the full email before replying, see above :-)
> I'd be happy to ask on the EventMachine list also, but since the
> rubyinstaller compiled and/or copied these files, I figured I might
> ask here first.
>
> Given the importance of EventMachine and the putative rush of people
> wanting to explore 1.9.2, it seems fairly critical that there be out
> of the box support for https.
postgres ruby bindings developers decided to use rake-compiler
cross-compiling approach to build openssl statically and link against
it.
I believe EventMachine guys could take that and implement it to
distribute a native gem for Windows.
> Let me know if this question would be better taken elsewhere.
>
It is the right place to ask, and thank you for doing your homework
and investigating the issue. However, we might not have the control or
the manpower to change every gem out there to make it more easy to
support Windows.
Hope my answer somehow helps.
Cheers,
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Excellent.
>> The problem is that EventMachine for SSL is trying to link and use
>> OpenSSL, and is not there. It needs OpenSSL development headers and
>> such.
>
> Fortunately, when using rubyinstaller to build Ruby 1.9.2, these
> libraries and header files are either compiled or otherwise made
> available on the local machine. The question is how do we simply refer
> to them when compiling EventMachine?
>
You mean by gem installation?
The headers and libs are not available out of the sandbox, you need to
refer to them, that is the only way.
>> As a workaround, you can try building and installing EventMachine
>> against sandbox/openssl:
>>
>> gem install eventmachine -- --with-openssl-dir=....
>
> This is very close, but it actually wanted "--with-ssl-dir..." instead
> of "--with-openssl-dir=...".
>
Ah, ok, never checked what options it really used or provided.
[snip of instructions]
> Thanks Luis for all of your help!
>
Thanks to you for your patience and not giving up. This (SSL for EM)
has been asked before and we never agreed on a solution for it.
Thank you for documenting it. Feel free to add a link to your
individual message in the wiki:
http://wiki.github.com/oneclick/rubyinstaller/tutorials
Great info, thanks.
If you do decide to put a tutorial link to our wiki page as Luis mention, I suggest you include "--platform=ruby" to be more robust. This option is more robust as it forces the native gem to be compiled. This wasn't a problem in this case as neither eventmachine nor em-http-request has binary gems for the RubyInstaller (x86-mingw32). However, _if_ they did have a binary gem _and_ it only supported 1.8 rather than being a 1.8+1.9 "fat binary" gem, I would expect things to fail on 1.9.2. Luis may want to comment further.
> D:\Code\Gems\eventmachine>ruby bank.rb
> 200
> {"DATE"=>"Fri, 20 Aug 2010 17:09:03 GMT",
> "SERVER"=>"IBM_HTTP_Server", ... the rest of the request!
>
> The source for bank.rb is:
To confirm, this script ran successfully after you ran "rake clean" and removed the d:/Code/rubyinstaller/sandbox/openssl directory? I expect it should as I'm guessing your 1.9.2 Ruby "bin" dir is on PATH so eventmachine finds the libeay32-* and ssleay32-* DLLs at runtime.
Jon
I will not recommend that. There are scenarios you will like to use
the binary gems instead of custom build ones.
nokogiri is one example, depends on things like libxml2 which are not
easily available under Windows (compatible with the same CRT, there
are other binaries but links against CRT 8.0 or 9.0)
>> To confirm, this script ran successfully after you ran "rake clean" and removed the d:/Code/rubyinstaller/sandbox/openssl directory? I expect it should as I'm guessing your 1.9.2 Ruby "bin" dir is on PATH so eventmachine finds the libeay32-* and ssleay32-* DLLs at runtime.
>
> Sort of... I didn't run rake clean, but I did install two versions of
> the eventmachine gem, one with SSL and one without it. I then compared
> the gems directories to see what was different. I saw that the one
> without SSL support includes an ssl.o file shows as being 1KB in size.
> The one with SSL support shows as 79KB in size. I then deleted the
> rubyinstaller directory completely and verified that everything still
> works. As a result, I'm fairly certain that the ssl.o file in the gems
> directory is being used, and not a reference to the library from the
> sandbox.
>
Well, actually no. the ssl.o is the ssl.cpp compiled to object code
which is then linked along the other object files.
When there is no SSL headers, it generates the dummy .o (1KB) which is
still linked.
EventMachine requires to actually check for OpenSSL not just at
compilation but at execution, which is the one that generated the
segfault in the first place.
Anyhow, eventmachine.so will be linked against the shared objects
provided by RubyInstaller, which is safe.
Nice
> Given that EventMachine is required for many other libraries (eg -
> thin), it would be great to easily support it. What I have done in the
> repo above works, but there must be a clean/correct way to do it.
>
> Is there a better way to do this?
>
postgresql guys use rake-compiler to cross compile also support
libraries like openssl for their gem:
http://bitbucket.org/ged/ruby-pg/src/tip/Rakefile.local
It can be cleaned up, but I've been working on a more ruby-friendly
library for these cases. I wish I had more time for OSS :-(