Installing ruby gems in Sketchup

Hi,

I have looked everywhere but I could not find a definitive answer.

Two simple questions:

  • Is it possible to install ruby-gems with ruby Sketchup (pro, >2014)?
  • Is there a recommended way to use a parallel ruby installation so that they do not mess up one another?

Thanks!

Gem.install "rubyzip"

Having said that, under Windows not all gems will install because some of them need to compile binaries. Under OSX this works out of the box because there is a system compiler available. But for Windows it usually require DevKit from Windows Ruby Installer to be on the system - not something end users will have installed, only developers. So you will find it a bit hit and miss to which one you can use on both platforms.

Under Windows you have the Windows Ruby Installer: http://rubyinstaller.org/
They also host the DevKit to build Ruby yourself.

Under OSX it’s much harder, but you have RVM: https://rvm.io/

But getting Ruby 1.8 i386 working on Mavericks is a pain. I eventually gave up.

If you want to compile Ruby C/C++ Extensions to be used with SketchUp use our Hello World example at GitHub: GitHub - thomthom/ruby-c-extension-examples: Ruby C extension examples

It include the Ruby headers we use with SketchUp and set up with Visual Studio and XCode projects - matching what we use when building SketchUp.

2 Likes

Thanks a lot Thom. I will definitely give it a try.

Hi,

I managed to install Ruby 2.0 and Devkit from RubyInstaller.org. I also manage to install the gem that I need ‘rbclipper’.

In order to make it work I had to install the gem using the Ruby installation on Windows and then copy the rpclipper.so file in the SketchUp plugin folder.

I wasn’t able to use the suggestion from Thom: Gem.install “rbclipper” because i was getting the error

Error: #<Gem::InstallError: The 'clipper' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
>
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/defaults/operating_system.rb:12:in `rescue in block in <top (required)>'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/defaults/operating_system.rb:4:in `block in <top (required)>'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/installer.rb:244:in `call'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/installer.rb:244:in `block in run_pre_install_hooks'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/installer.rb:243:in `each'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/installer.rb:243:in `run_pre_install_hooks'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/installer.rb:209:in `install'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/dependency_installer.rb:372:in `block in install'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/dependency_installer.rb:332:in `each'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/dependency_installer.rb:332:in `each_with_index'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/dependency_installer.rb:332:in `install'
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems.rb:526:in `install'
<main>:in `<main>'
SketchUp:1:in `eval'

This works, but it looks more a workaround.

To me the problem seems to be that the Ruby Sketchup environment does not know where Devkit is, but I am not sure how to add the SU Ruby to DevKit in the config.yml file. There is no equivalent directory to C:\Ruby200-x64.

Am I missing something or this is just not possible and the work around is the way to go?

Thanks

1 Like

Hi,

I am having same issue with ruby clipper.

@anon77361920 team: kindly let us know how to resolve this.

Thanks,
Mallikarjuna.

I don’t think SketchUp officially supports (or can support) Ruby gems. (And if, more problems would arise since developers would start publishing extensions which require gems which require build tools which are unfortunately not naturally shipped by the user’s OS if you target Windows.)

When you search the forum you find: If a gem works, it is fine to use. But you must not use Gem.install (slow, freezes SketchUp) in your extension, and wrap the copied gem into your namespace.

Regarding the error The 'clipper' native gem requires installed build tools, does your PATH environment variable contain the correct path to devkit? If not, you must add it. If it is, is it correct? Does Ruby see that environment variable (in SketchUp: ENV["PATH"])?

1 Like

Question I’ve never asked. Given that recent SU versions have used Ruby 2.0, 2.2, & 2.5, can one compile extension gems (for all three versions) on MacOS as is, or does one need to install matching stand-alone Ruby versions for each?

This really isn’t about what the Sketchup team can do. There are all sorts of potential problems when using gems with SU. These problems can exist with both ‘plain Ruby’ gems and especially with extension gems.

There are work arounds, but they are very dependent upon the use case.

Re the clipper gem, there have been two releases, one in Dec-2010, the other in Jan-2014. The gem includes ‘Clipper’ 6.2.1, the current version is 6.4.2. If you can build & verify that it works in a stand-alone Ruby that matches the Ruby version used in the SU version you want to target, then people here may be able to help.

I believe the ‘Sketchup team’ should be responsible for their own API, and verifying that the Ruby installation works. Past that, add-ons to Ruby are the user/developers responsibility…

Hi @MSP_Greg,

Thanks for your reply.

The latest Clipper version 6.4.2 is working in stand-alone Ruby version 2.5.1(Same as SU 2019 Ruby version). So, I can’t understand why the gem is not working in same Ruby version ?

And the error message(the specified module not found) is generic and very high level, not enough to debug further deep into it. So, I am requesting SU team to look into this.

@tt_su, @anon77361920 team: kindly look into this and let me know the workaround for this.

Thanks,
Mallikarjuna.

  • Do you mean: It installs in stand-alone Ruby (with gem install), and the gem installer sees the build tools path and finds the build tools.
    Some of this is probably not working in SketchUp with Gem.install('clipper') .

  • Or do you mean you transfered the gem’s built code into your extension and wrapped it into your namespace (because of: “clipper: Builds a native ruby extension for Clipper”) and it is not loading in SketchUp?

See my reply in this thread: Install Prawn gem in SketchUp 2016 - #2 by tt_su

TL;DR: Gems are not something we support. If you want to use them for extension you distribute, please fork it and wrap it under your own namespace.

1 Like

This tends to be due to incompatible binary. Often its related to linking to an incompatible Ruby builds (version or bitness). You might want to inspect the symbols being export. And check what Ruby DLL it links with.

Well, since you bolded it, please explain where you see version 6.4.2?

The current gem is 2.9.1, and the repo for it has been updated to 6.2.1.1, but it has not been released.

And the error message( the specified module not found ) is generic

Normally, this refers to a dll that can’t be found. clipper.so links to libgcc_s_seh-1.dll & libstdc++-6.dll, which should both be included with SketchUp 2019, which I do not have loaded.

You might try adding your msys64/mingw64/bin path to ENV['PATH'] in the SU ruby console, then requiring the clipper file.

I decided to install the SU2019 trial version and see if anything has changed. IMO:

  1. There are dll’s missing that should be included.
  2. There are duplicate dll’s.
  3. Re gems, a handy thing to do is install gems from stand-alone using --user-install, then the gems should be available in SU. They are not.
  4. The ridk runtime has been removed.
  5. It seems all bundled gems have been removed. Several are cli based and don’t really have a use in an embedded Ruby. But the test gems and XMLRPC could have been included. I’ve never tried using rake from script…
  6. RbConfig isn’t set up correctly.

There’s probably more, I haven’t really gone thru it. For one thing, why didn’t it ship with 2.5.3? The ABI is the same, and nothing is ever removed within a minor release, and, since the patch jumped from 57 to 105, that’s quite a few bug fixes. On windows, 2.5.1 shipped with OpenSSL 1.1.0, 2.5.3 shipped with 1.1.1, which is a LTS version…

I try to look at SU from the perspective of a Ruby coder brought into a small business that wants to integrate SU with their other software. If I was that coder, I’d be irritated.

So, there are things that the ‘Sketchup team’ could improve on. FWIW, I built clipper and it’s loading in SU…

Which DLLS are missing?

What are the bundled gems missing?

We had to strip out some extra modules in 2.5 as we found some of them was under licenses we could not redistribute. But majority of those appeared to be related to CLI so it didn’t look to have much of an impact.

Testing - every change require more testing. 2.5.1 was the latest one when we made the upgrade.

Thomas,

Which DLLS are missing?

Took more work than I thought:

libgcc_s_seh-1.dll
libgdbm_compat-4.dll
libgdbm-4.dll
libiconv-2.dll
libintl-8.dll
libreadline7.dll
libstdc++-6.dll
libtermcap-0.dll

What are the bundled gems missing?

The test gems would be helpful. Also, there is not a single gemspec file that I can find. These should be included.

Testing - every change require more testing.

Being pretty familiar with Ruby testing, Ruby 2.5 was the first version fully tested on Windows.

The two main test suites were added in this commit on 2017-Jun-07, which was an mswin build. At the time, I was doing full MinGW testing in ruby-loco.

Full testing on MinGW builds was added with this commit on 2018-Aug-18. Granted, this doesn’t mean that issues can’t arise in SU, but I think it’s a pretty good indication that they’re unlikely, especially within a minor version. There are tests that specifically test the ABI. And finally, Ruby Core is starting to add testing on MacOS (previously it was just Ubuntu). As mentioned above, a teeny release (2.5.x) is bug fixes, so 2.5.3 should present fewer issues than 2.5.1, and due to updates in MSYS2/MinGW, there are several updated ‘dependency packages’ used in MinGW builds.

Finally, I’ve attached them before, but attached is zip file that includes two files, su_info.rb shows info about the Ruby installation, similar to code I’ve got running on Appveyor & Travis. su_gem.rb is a utility that allows one to use gem commands from the SU console (see comments in file). Two in particular are SUGem.env & SUGem.list. There are additional files, they are used for the SSL testing. I could make them a GH repo…

su_utils.zip (12.3 KB)

Hi @MSP_Greg:

Since I have tried many ways to bundle clipper, but not succeeded. Can you share the clipper file, which is loading in SU 2019 ?

The version 6.4.2 is the source version (from: Download Clipper from SourceForge.net).

Thanks,
Mallikarjuna

There’s a couple of ways I can do this, let me think about the best way. A couple of things:

  1. The link above is to the c source, the gem ‘clipper’ is a wrapper around it. The current gem is on a very old version of the c source.

  2. You do have a working stand-alone Ruby 2.5.1? Do you have the ‘DevKit’ installed? If your system responds to ridk version, it is installed. I will need you to post the output of that to get clipper working on your system. Change names if you want…

  3. The ‘clipper’ gem wrapper code/repository is using the c source v 6.2.1, but as mentioned above, it hasn’t been released as a gem. There are no tests in the GitHub repository, so I can’t easily tell if the build works with the newer versions of the c source…

I’m going to see if I can build it with 6.4.2 or 6.2.1, which may take a little while, but then others can use it. I’ll probably do that on Appveyor.

I may also throw together a GitHub repo with code & docs for how to set up SketchUp to correctly work with gems.

Well, I ended up finding a gem called ‘polygon_clipper’, which did seem to have the participation of the 'rbclipper` author. So, I’ve compiled a clipper gem that is using Clipper 6.4.2. It can be used with Ruby 2.2.x thru 2.6.x. Below are the steps to install it:

1. From stand-alone Ruby 2.5.1, enter ridk version in a command or PowerShell window. You’ll see:

msys2:
  path: C:\msys64

Add mingw64\bin to that path, and find two files there:

libgcc_s_seh-1.dll
libstdc++-6.dll

These files need to be added to:

C:\Program Files\SketchUp\SketchUp 2019

A complete list of the missing dll’s is above, but just these two are needed for clipper.

2. Also above is a file in a message of mine called su_utils.zip. You need to download it and extract it somewhere. The file you’ll need is su_gem.rb.

3. The pre-compiled gem needs to be downloaded, the file is:

clipper-6.4.2.1-x64-mingw32.gem

available at:
https://ci.appveyor.com/project/MSP-Greg/rbclipper/builds/22774852/artifacts

4. Now, you’re ready to do something in SketchUp. The following are the steps I did in the SketchUp console (prefixed by >) and the output from them. Anywhere I’ve shown <path>, you need to substitute the correct location:

> require '<path>/su_gem.rb'
true

> SUGem.install '-lN <path>/clipper-6.4.2.1-x64-mingw32.gem'
Successfully installed clipper-6.4.2.1-x64-mingw32
1 gem installed

> require 'clipper'
true

> Clipper::VERSION
6.4.2.1

> Clipper::Clipper.instance_methods(false).sort.join "\r\n"
add_clip_polygon
add_clip_polygons
add_subject_polygon
add_subject_polygons
clear!
difference
intersection
multiplier
union
xor

None of the ‘clipper’ repositories have tests, and I haven’t checked to see if it works. The methods that it should be defining are showing up, so that’s as far as I went…

3 Likes

Hi @MSP_Greg,

Thank you so much for your help and support.

I tried these steps and got the following error while requiring clipper

The installation is successful, but require ‘clipper’ giving the following error.

require ‘clipper’
Error: #<LoadError: 193: %1 is not a valid Win32 application. - C:/Users/Arjun/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Gems64/gems/clipper-6.4.2.1-x64-mingw32/lib/2.5/clipper.so>
C:/Users/Arjun/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Gems64/gems/clipper-6.4.2.1-x64-mingw32/lib/clipper.rb:1:in require_relative' C:/Users/Arjun/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Gems64/gems/clipper-6.4.2.1-x64-mingw32/lib/clipper.rb:1:in <top (required)>’
C:/Program Files/SketchUp/SketchUp 2019/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:59:in require' C:/Program Files/SketchUp/SketchUp 2019/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:59:in require’

:in `' SketchUp:1:in `eval'

Kindly help me on this.

Thanks,
Mallikarjuna.