ruby-opengl-0.60.1 under RubyInstaller 1.9.2

930 views
Skip to first unread message

TPReal

unread,
Feb 18, 2011, 10:41:04 AM2/18/11
to rubyin...@googlegroups.com
Hello guys,

After two days' battle I succeeded in building and installing the ruby-opengl gem on Ruby 1.9.2 installed from RubyInstaller, on Windows 7. This involved making a number of fixes to the gem, to mkrf, and various other things.

I can post more detailed info here, just let me know if anybody is interested.

TPReal.

Luis Lavena

unread,
Feb 18, 2011, 10:45:31 AM2/18/11
to rubyin...@googlegroups.com, TPReal
On Fri, Feb 18, 2011 at 12:41 PM, TPReal <tpr...@gmail.com> wrote:
> Hello guys,
>
> After two days' battle I succeeded in building and installing the
> ruby-opengl gem on Ruby 1.9.2 installed from RubyInstaller, on Windows 7.
> This involved making a number of fixes to the gem, to mkrf, and various
> other things.

Have you send these changes to the gem author?

Why mkmf modifications were required? all the mkmf modifications
should be avoided, if not, an update of Ruby will erase them.

> I can post more detailed info here, just let me know if anybody is
> interested.

Please do, but most important, get in touch with gem author and help
him get a gem working so others can use and we reduce the manual
"hacking" around them.

Thank you.
--
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

Jon

unread,
Feb 18, 2011, 10:47:34 AM2/18/11
to rubyin...@googlegroups.com

Sounds interesting. How about putting it in a blog and putting a link in https://github.com/oneclick/rubyinstaller/wiki/Tutorials

Jon

---
blog: http://jonforums.github.com/
twitter: @jonforums

TPReal

unread,
Feb 18, 2011, 12:04:46 PM2/18/11
to rubyin...@googlegroups.com, TPReal
The problem with the gem is that it was last released two years ago. I wrote an email to the dev but I don't think they will be interested in making the changes.

 
As for mkrf, when I call gem install with the gem, mkrf 0.2.3 gets installed first, I don't know where it comes from, and it does not work because it assumes mswin and not mingw - so maybe a corrected version of mkrf should come with RubyInstaller? Probably RubyInstaller devs should think about it.

So for now installing ruby-opengl is this (in short):
 
  • Install the DevKit
  • Install the mkrf gem if not installed, and then apply the mingw patch to it
  • Download the ruby-opengl, using gem fetch for instance, unpack it, modify one c file and three mkrf_conf.rb
  • Build the gem from the unpacked source. There is a bug in gem build, it needs adding a require yaml (to rubygems.rb for instance) for the build to succeed
  • Add glut.h and glut32.dll in the right place, I put it in DevKit/mingw
  • Finally gem install the rebuilt gem
 
I hope I didn't forget any of the steps.

So now - is there a better way to achieve some of the steps? Especially modifying mkrf and rubygems does not seem pretty, so maybe they should be changed already inside the RubyInstaller, especially mkrf? And also - why there is no glut in the DevKit, but there is gl and glu? Is this some licensing problem?

I can post the details either here or I don't know where, maybe on an obscure blog I had once.

Luis Lavena

unread,
Feb 18, 2011, 12:16:42 PM2/18/11
to rubyin...@googlegroups.com, TPReal
On Fri, Feb 18, 2011 at 2:04 PM, TPReal <tpr...@gmail.com> wrote:
> The problem with the gem is that it was last released two years ago. I wrote
> an email to the dev but I don't think they will be interested in making the
> changes.
>
> As for mkrf, when I call gem install with the gem, mkrf 0.2.3 gets installed
> first, I don't know where it comes from, and it does not work because it
> assumes mswin and not mingw - so maybe a corrected version of mkrf should
> come with RubyInstaller? Probably RubyInstaller devs should think about it.

Sorry, I read incorrectly, you said mkrf, not mkmf.

I think mkrf is actively maintained and you should address the mkrf
patches to the gem author.


>
> I hope I didn't forget any of the steps.
> So now - is there a better way to achieve some of the steps? Especially
> modifying mkrf and rubygems does not seem pretty, so maybe they should be
> changed already inside the RubyInstaller, especially mkrf? And also - why
> there is no glut in the DevKit, but there is gl and glu? Is this some
> licensing problem?

What problems are in RubyGems? What version of RubyGems are you using?
what is the command and the output? Will be good to know so we can
point you to the right tools.

As for the mkrf, mentioned above.

If the gem author of ruby-opengl doesn't want to maintain it anymore,
perhaps you can fork the repository and put your changes in.

TPReal

unread,
Feb 18, 2011, 12:42:30 PM2/18/11
to rubyin...@googlegroups.com, TPReal
On Friday, February 18, 2011 6:16:42 PM UTC+1, Luis Lavena wrote:

I think mkrf is actively maintained and you should address the mkrf
patches to the gem author.

 
Unfortunately not - the latest release, 0.2.3, is three years old. And the problem stems from using mingw - probably nobody used mingw for Ruby before RubyInstaller? I don't know but again I don't feel like contacting them makes sense, and also I don't want it very much to fork the project just to add two lines and make the impression that it's alive. And the same with ruby-opengl.

What problems are in RubyGems? What version of RubyGems are you using?
what is the command and the output? Will be good to know so we can
point you to the right tools.

 
I used the rubygems bundled in RubyInstaller, it seems to be 1.3.7 judging from the constant in the source. When I called gem build metadata, it complained about YAML constant missing from inside Gem::Specification. But I see they already fixed it, if I call gem update --system first, it installs rubygems 1.5.2 and the gem builds. So one less suspicious manual edit needed.

Jon

unread,
Feb 18, 2011, 1:03:41 PM2/18/11
to rubyin...@googlegroups.com
> - Build the gem from the unpacked source. There is a bug in gem build, it
> needs adding a require yaml (to rubygems.rb for instance) for the build to
> succeed

If you're using RubyGems 1.5.2+ double check whether you need to "prefer" psych on 1.9.x due to RubyGems preferring psych. This bit me when a dependency I was using did the expected "require 'yaml'" (which pulled in the deprecated syck engine) which then conflicted with RubyGems. Luis may want to say more on this or whether he thinks it's a non-issue for your case.


> And also - why there is no glut in the DevKit, but there is gl and glu? Is this some
> licensing problem?

We build up the DevKit by using other artifacts. For example, the default 4.5.1 DevKit integrates these artifacts for the mingw/ dir https://github.com/oneclick/rubyinstaller/blob/master/config/compilers/tdm_mingw.rb#L3-32 I don't want to maintain patch sets against these standard downloads for multiple reasons.

I think what you're doing re: glut is similar to what others are doing http://www.mingw.org/category/wiki/glut

That said, if more work goes on cleaning up the source gem it probably makes sense to update the extconf.rb (via dir_config('glut')) so that the when installed one can give the standard --with-glut-include, --with-glut-lib, --with-glut-dir to "gem install"


> I can post the details either here or I don't know where, maybe on an obscure blog I had once.

While I personally dislike tutorial doco being buried in mailing lists (usually gets overlooked even though you can search the list) if it's easier to document your final solution in a post to this list rather than a blog post linked to our tutorials, do it. I'd rather have the info documented than not...and you could always put a link to the mailing list topic in the tutorial page :)

Luis Lavena

unread,
Feb 18, 2011, 2:01:13 PM2/18/11
to rubyin...@googlegroups.com, Jon
On Fri, Feb 18, 2011 at 3:03 PM, Jon <jon.f...@gmail.com> wrote:
>>    - Build the gem from the unpacked source. There is a bug in gem build, it
>>    needs adding a require yaml (to rubygems.rb for instance) for the build to
>>    succeed
>
> If you're using RubyGems 1.5.2+ double check whether you need to "prefer" psych on 1.9.x due to RubyGems preferring psych. This bit me when a dependency I was using did the expected "require 'yaml'" (which pulled in the deprecated syck engine) which then conflicted with RubyGems.  Luis may want to say more on this or whether he thinks it's a non-issue for your case.
>
>

"gem build" on RubyGems 1.5.2 should work properly

RubyGems 1.6.0 will iron the other details.

>> And also - why there is no glut in the DevKit, but there is gl and glu? Is this some
>> licensing problem?
>
> We build up the DevKit by using other artifacts. For example, the default 4.5.1 DevKit integrates these artifacts for the mingw/ dir https://github.com/oneclick/rubyinstaller/blob/master/config/compilers/tdm_mingw.rb#L3-32  I don't want to maintain patch sets against these standard downloads for multiple reasons.
>

GLU/GL fall into the "3rd party" category and similar to MySQL and
others, if you want to compile a gem that uses it, you need to provide
the compilation options.

>
>> I can post the details either here or I don't know where, maybe on an obscure blog I had once.
>
> While I personally dislike tutorial doco being buried in mailing lists (usually gets overlooked even though you can search the list) if it's easier to document your final solution in a post to this list rather than a blog post linked to our tutorials, do it.  I'd rather have the info documented than not...and you could always put a link to the mailing list topic in the tutorial page :)
>

Agreed.

TPReal

unread,
Feb 18, 2011, 2:19:37 PM2/18/11
to rubyin...@googlegroups.com
On Friday, February 18, 2011 7:03:41 PM UTC+1, Jon wrote:

If you're using RubyGems 1.5.2+ double check whether you need to "prefer" psych on 1.9.x due to RubyGems preferring psych. This bit me when a dependency I was using did the expected "require 'yaml'" (which pulled in the deprecated syck engine) which then conflicted with RubyGems.  Luis may want to say more on this or whether he thinks it's a non-issue for your case.

That said, if more work goes on cleaning up the source gem it probably makes sense to update the extconf.rb (via dir_config('glut')) so that the when installed one can give the standard --with-glut-include, --with-glut-lib, --with-glut-dir to "gem install" 

 
I must say I don't know much about the gems system and don't want to know too much now, I only wanted ruby-opengl to work. So I'll simply assume that things are what they are now, and describe what needs to be done, without going into too much details.

While I personally dislike tutorial doco being buried in mailing lists (usually gets overlooked even though you can search the list) if it's easier to document your final solution in a post to this list rather than a blog post linked to our tutorials, do it.  I'd rather have the info documented than not...and you could always put a link to the mailing list topic in the tutorial page :)

OK, I'll write it in this topic then, I don't have any better place for this. And with link on the tutorials page hopefully it will not get lost.
Message has been deleted

TPReal

unread,
Feb 18, 2011, 5:41:11 PM2/18/11
to rubyin...@googlegroups.com
Let me describe a way to use Ruby 1.9.2 from RubyInstaller with the ruby-openglgem - binding for OpenGL, with last version released two years ago. Not surprisingly, the two things do not go together well out of the box.

I don't know if many people use ruby-openg, but I relied on it heavily, so I decided to get it working, no matter what. I normally use Windows and diving in the linux world is not my favourite way of spending time, but this time it was the necessity. As they say, to use linux you must like to spend all day playing with a problem that stems from another problem, to finally find out that you have one other problem. So let me not describe the whole process of finding the answer - I'll just show the answer itself.

Here are the steps I used to get ruby-opengl working under Ruby 1.9.2 from RubyInstaller, on Windows 7:
  • I assume you have Ruby from RubyInstaller installed under some path we will call rubyinstaller from now on. So, Ruby is installed there.
  • Now you need the DevKit - we will need it to compile ruby-opengl. Download it from the RubyInstaller download page and install it as described here. I'll sum up what you need to do with it:
    • Unpack it to some directory that we will call devkit.
    • Open windows console (cmd), go into the directory, and call dk.rb init (I assume your Ruby is automatically used to run .rb files).
    • Now call dk.rb install and you have the DevKit installed.
  • Now you need the glut header and glut library (dll). You can find them easily, either in the internet or on your hard drive, as some games sometimes come with it.
    • You should put glut.h file in devkit/mingw/include/GL (you remember what devkit is? we defined it just a moment ago), next to gl.h and glu.h.
    • You should put glut32.dll in devkit/mingw/lib, next to some .a and .o files.
  • Now we must make sure that mkrf is installed. For this execute in the console: gem install mkrf unless you are sure you have it already.
  • The latest version of mkrf is 0.2.3 and it is 3 years old... so it needs some lifting: go into rubyinstaller/lib/ruby/gems/1.9.1/gems/mkrf-0.2.3/lib/mkrf. We need to patch two files there. I found the patch here and if you prefer, you can get them from there and apply them automatically.
    • Open availability.rb in some good text editor, go to line 84 and change it from:
return true if RUBY_PLATFORM =~ /mswin/ # TODO: find a way on windows
to
return true if RUBY_PLATFORM =~ /mswin|mingw/ # TODO: find a way on windows
    • Still in the same file, go to line 169 which says else, and add two lines just before it:
elsif RUBY_PLATFORM =~ /mingw/
  "gcc -shared "
    • Now open generator.rb, go to line 197 and change it from
RUBYARCHDIR = "\#{ENV["RUBYARCHDIR"]}"
to
RUBYARCHDIR = "#{CONFIG["sitearchdir"]}" 
  • Now we need to update rubygems. Do it by executing gem update --system in the console. You can ignore the message about broken update mechanism - it is irrelevant here.
  • Now we can start with the gem itself. We cannot install it directly - it needs some patching too:
    • Execute gem fetch ruby-opengl which will download the gem to the current directory. We will call the downloaded file ruby-opengl.gem, although it has some version number in the name.
    • Create an empty directory that we will call opengl and unpack there two things: one is the metadata file located in ruby-opengl.gem/metadata.gz/metadata, and the other is the whole content ofruby-opengl.gem/data.tar.gz/data.tar - some directories and Rakefile. To extract this data from the gem, best use some archive explorer, like 7-Zip.
    • Now we will modify the mkrf_conf.rb files. Again the patches are here, only without the patch for glut, for some reason. So: open the file opengl/ext/glut/mkrf_conf.rb and do this:
      • Copy the whole when /mswin32/ section (5 lines) and paste it directly under itself.
      • Modify the pasted section: change /mswin32/ to /mingw/ in the first line, and remove the .lib file extensions in the three lines below. As the result, your file has now additional when section, which looks like this:
when /mingw/
  g.cflags << ' -DWIN32' + RUBYVER
  g.include_library( 'glut32', 'glutSolidTeapot' )
  g.include_library( 'glu32', 'gluLookAt' )
  g.include_library( 'opengl32', 'glVertex3d' )
 
 
    • Now repeat the same procedure with two more files: opengl/ext/glu/mkrf_conf.rb and opengl/ext/gl/mkrf.conf.rb. The file content is slightly different (sections are shorter), but the rules are exactly the same.
    • Finally, modify opengl/ext/glut/glut.c file - find the only occurrence of the string STR2CSTR in it and replace it with StringValuePtr. I found this info here (only Google cache, the original page does not work).
  • OK, now it's time to rebuild the gem. For this, go into the opengl directory with a console and execute gem build metadata to build the new gem file in this directory. Name it something like ruby-opengl-0.60.1-ruby-1.9.2.gem and save it well - if you update Ruby in the future, having it will save you part of the work done today (namely updating rubygems, tampering with the gem source and building it).
  • Finally, install it by gem install ruby-opengl-0.60.1-ruby-1.9.2.gem and wait for the native extension to build - it might take a long time so don't be impatient.
  • Check whether all is in place by executing require 'opengl' in irb. If it won't fail, it is probably OK.
Thanks for reading!

(This was posted again because I made a mistake in edited line number the first time. Sorry for that.)

TPReal.
 

TPReal

unread,
Feb 18, 2011, 6:27:29 PM2/18/11
to rubyin...@googlegroups.com
I attached a package with a much shorter instruction and some things already built, like the modified gem. Read the instructions inside.
ruby-opengl-ruby-1.9.2.zip
Reply all
Reply to author
Forward
0 new messages