Getting Ruby to work on Mac
-
I have been successful getting an installation of Ruby to work with my plugins on the PC, and am now trying on the Mac without success.
On PC, I copied the lib folder of a 1.8.6 p287 release into my plugin folder, and added this path to $LOAD_PATH, and it works fine. The problem is that I'm using stringio and zlib, which are compiled .so files on PC and appear to be .bundle files on the Mac. On Mac, I was able to find these libraries in:
/usr/lib/ruby/1.8/universal-darwin10.0/
Unfortunately, requiring the stringio.bundle or zlib.bundle from this location is causing a bugsplat in SU. I'm assuming this is because of a version difference (ruby -v in a terminal gives version 1.8.7, but SketchUp is running RUBY_VERSION=1.8.5).
I need to find a reasonable way to work with Ruby on a Mac. I am reading that Lion is shipping with 1.8.7 and Leopard with 1.8.6 (although I'm running Leopard and it's 1.8.7). If SU8 Mac only plays nice with 1.8.5, then I have two options:
- Replace the SU Ruby interpreter with the 1.8.x version I like.
- Find versions of zlib and stringio that SU's interpreter will recognize and include them with my plugin.
I did #2 on PC by downloading 1.8.6 p287 and copying the libraries I needed into my plugin, but I don't know how to find these for the Mac (that is, 1.8.5 versions of zlib and stringio). #1 would be acceptable if it was only my machine, but I can't be replacing my users' SU Ruby interpreter when they install my plugin (that would be super selfish and could cause major conflicts with other plugins.)
Has anyone else solved this problem before? Anyone know where I can get 1.8.5 versions of zlib.bundle and stringio.bundle to try out with SU's Ruby?
-
Perhaps I'm mis-understanding, but why do you need to do any of this? SketchUp has its own version of ruby (in th 1.8.6 vein or something?). You shouldn't have to mess with a separate install of ruby, unless you're doing something extra-ordinary that I'm not considering.
-
Sorry, I thought people would recognize the issue, since there have been other posts about this:
http://forums.sketchucation.com/viewtopic.php?f=180&t=34219 (someone apparently trying to do the same thing as me, but there is little of use in this thread)
http://forums.sketchucation.com/viewtopic.php?t=29412 (Dan Rathbun's efforts to use an external ruby installation on PC. Apparently he doesn't own a Mac)
SketchUp comes with a Ruby interpreter and core libraries, which exists in a .dll in the sketchup directory on PC, and somewhere in the SketchUp package on Mac (/Applications/SketchUp/Contents/Frameworks/Ruby.framework/.....).
Unfortunately, SU's Ruby does NOT come with the standard libraries (basically, the /lib folder of a Ruby installation), which means it's missing the standard gems, StringIO, ZLib, and many many other useful extension libraries that I need for my plugin. The only way to get these libraries loaded into SketchUp is to append the $LOAD_PATH variable so that calls to Kernal.require will search in your own folders. However, the extension libraries are compiled C code, so I need separate versions for Mac and PC. I tried using libraries that come with the version of Ruby that my Leopard shipped with (1.8.7) (this can be tested by simply finding your native Mac's Ruby installation, in /usr/lib/ruby for me, and adding that path to $LOAD_PATH), but since SU is using a 1.8.5 interpreter on this Mac, I'm guessing this is what is crashing SU when I require these.
SO, I am trying to find versions of the extension libraries that won't crash sketchup.
-
forum member driven was messing around with this stuff...
http://forums.sketchucation.com/viewtopic.php?f=180&t=37127&p=327328
maybe contact him for some ideas?
[or fuggedaboutit ]
-
Just found this: http://forums.sketchucation.com/viewtopic.php?f=180&t=28673&start=0#p249370
Looks to be exactly my problem. I will try linking with a flat namespace tomorrow and see if that will compile a bundle that doesn't crash sketchup.
-
I tried compiling a 1.8.5 version of Ruby on the Mac, which works if you follow the directions in the previous post about changing that compiler flag.
Unfortunately I can't find a 1.8.5 Ruby that includes the thread.bundle C extension. Several of the other C extensions depend on thread.bundle, so I haven't been able to get this working.
As a workaround I may resort to using shell commands instead of the Ruby libraries I need. This is painful since Mac comes with some programs that Windows does not (tar, gzip), so I'll have to do different things for each platform.
-
See this post for more info (and a link to a StackOverflow post that gives instructions on Mac for changing your symbolic links to force Sketchup to use a System Ruby.)
http://forums.sketchucation.com/viewtopic.php?f=180&t=31545&start=15#p326274 -
Thanks Dan.
Unfortunately since I'm distributing my plugin to other people, I don't see a way to replace the interpreter such that other plugins will be guaranteed not to break. Upgrading SU's Ruby is really only a reasonable solution if you're doing it to YOUR SketchUp and not others'.
Unless you have something in mind... But otherwise I am still looking for a way to get 1.8.5 standard libraries and extensions into my Mac SU.
-
Isn't it possible to just copy the files you need and require them in your own script? How many standard library files is it?
-
@chris fullmer said:
Isn't it possible to just copy the files you need and require them in your own script? How many standard library files is it?
I really need a full Ruby installation, including all the C extensions (zlib, stringio, thread, bigdecimal, etc... about 10-15 in total). I achieved this on the PC by copying a 1.8.6 installation into my plugin files.
So yes, I could copy files, but my Mac comes with 1.8.7, and the existing extensions in that installation do not work in SketchUp (I get a version difference error). I'm therefore trying to compile a version that will work in SketchUp, but all the 1.8.5 sources I find are missing the thread C extension.
-
Well.. probably beatin' a dead horse here, but
Ruby v1.8.5 (the entire branch,) is obsolete, and no longer being patched. (Not to mention that the initial release distro'd with Mac Sketchup is superceded by all the later patches.)
If I was a Mac only user, I'd be raisin' hell... getting a petition going, or similar to get the Mac Sketchup Ruby updated (at least equal to that of the PC.)
It would be nicer if both platforms were updated to the latest patch in the 1.8.7 trunk.
-
@draftomatic said:
So yes, I could copy files, ...
You can't on the Mac. The extensions need to be linked against the core that Sketchup is going to load.
It would be beneficial if you could figure out a way, to install an additional frameworkized v1.8.7 Ruby beneath (alongside) the Sketchup obsolete Ruby, and then have a "switching" utility that allowed the user to change the symbolic links, to load the newer Ruby.
-
@dan rathbun said:
If I was a Mac only user, I'd be raisin' hell... getting a petition going, or similar to get the Mac Sketchup Ruby updated (at least equal to that of the PC.)
It would be nicer if both platforms were updated to the latest patch in the 1.8.7 trunk.
I am in the process of raising hell to Google...
@dan rathbun said:
It would be beneficial if you could figure out a way, to install an additional frameworkized v1.8.7 Ruby beneath (alongside) the Sketchup obsolete Ruby, and then have a "switching" utility that allowed the user to change the symbolic links, to load the newer Ruby.
Sigh... these convoluted workarounds are getting old. I think it will be resort to using shell commands instead of the Ruby libraries I need. Mac comes with curl and gzip, and I believe this will eliminate my need for stringio as well.
Thank you for your input Dan. I will pass this on to Google.
Advertisement