Is there any gem for Linux FIFOs in JRuby? - jruby

Seeing as how C extensions are out in recent releases of JRuby, is there a gem that supports FIFOs in JRuby? The 'mkfifo' gem depends on C extensions.

there's likely no such thing but maybe you can use FFI to get to the native stuff. also on JRuby you should be still able to read named pipes just fine.

Related

Unable to install Ruby MySQL Gem on Mac OS X

When attempting to install the Ruby MySQL Gem on Mac OS X:
# ~/.rvm/gems/ruby-2.1.4/extensions/x86_64-darwin-14/2.1.0-static/mysql-2.9.1/mkmf.log
find_library: checking for mysql_query() in -lmysqlclient... -------------------- no
Similar messages about the same missing function throughout mkmf.log.
I assume missing dependencies but I don't know what they would be or where this would be documented. Google doesn't seem to help. And the project is unmaintained.
Tried Ruby 2.1.4, 2.2.7, 2.4.1.
You don't have the mysqlclient library installed. The easiest way to get it on your machine is to use Homebrew and do brew install mysql.
The mysql gem has native extensions - that is, when the gem is installed, native parts of it are compiled. You will need a C/C++ toolchain as well on your Mac for this to work. If you have XCode installed, you should be good to go as it provides clang.

How to enable C extensions error in Jruby?

I am getting the following error and dont know how to solve this. Can someone simplify this process?
My Jruby is installed in
C:/jruby-1.7.13/bin
my project is in
C:/Users/myname/downloads/projectdirectory
The error is when I do
bundle install
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
c:/jruby-1.7.13/bin/jruby.exe extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.
(root) at c:/jruby-1.7.13/lib/ruby/shared/mkmf.rb:8
require at org/jruby/RubyKernel.java:1065
(root) at c:/jruby-1.7.13/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
(root) at extconf.rb:2
Gem files will remain installed in c:/jruby-1.7.13/lib/ruby/gems/shared/gems/pg-0.17.0 for inspection.
Results logged to c:/jruby-1.7.13/lib/ruby/gems/shared/gems/pg-0.17.0/ext/gem_make.out
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.0'` succeeds before bundling.
C- extensions are not really supported in JRuby and were actually dropped in the 1.7.x line ...
thus despite the message mentioning -Xcext.enabled=true won't help you!
since it's pg you're trying, there's a jruby alternative that uses a Java API instead of C pg_jruby, alternatively if you're using active-record look for activerecord-jdbc-adapter + jdbc-postgres

Porting a Ruby/Rails/MRI app to JRuby

I have a Ruby/Rails devvelopment environment using rbenv, MRI Ruby (1.9.2-p290), rails 3.0.9, and SQLite3. I would like to port it to JRuby, but do it such that I don't have to do anything more than run "rbenv local jruby-1.6.4" and "rails server" in the root directory of the Rails application to use it with JRuby, and "rbenv local 1.9.2-p290" and "rails serer" to use it with MRI Ruby.
I am aware that the gems to access SQLite are different for Ruby versus JRuby, but how do you write the Gemfile such that the MRI-relevant gems are picked up when the Ruby is MRI, and the JRuby-relevant gems are picked up when the Ruby is JRuby?
I will also need to port it to MySQL instead of SQLite. Which gems do I need to use here for Ruby and JRuby?
For the record, I'm using Ubuntu 11.04, Ruby 1.9.2-p290, JRuby 1.6.4, and Rails 3.0.9 or 3.0.10.
We ported a large Rails application to JRuby last year and it was a surprising amount of work. Granted, part of it had to do with the app being rather badly written and having lots of legacy code, but still. In case you wonder: most of our problems came from gems we used, which then sometimes depended on e.g. FFI that didn't properly work with JRuby at that time. A port to Rubinius I did a little later seemed a lot less painful, but was abandoned in favor of staying with MRI.
For the Gemfile, there's a platform option you can use. Here's an example from the Bundler docs:
gem "weakling", :platforms => :jruby
gem "ruby-debug", :platforms => :mri_18
gem "nokogiri", :platforms => [:mri_18, :jruby]
It also has a block form:
platforms :jruby do
gem "foo"
end
Either form works well, since
All operations involving groups (bundle install, Bundler.setup,
Bundler.require) behave exactly the same as if any groups not matching
the current platform were explicitly excluded.
As a gem for MySQL I'd use the aptly named mysql, there seems to be a jdbc-mysql for JRuby.

Problem with Rails 3 and MySQL related to JSON dependency in ActiveSupport

I built my Rails 3 app using sqlite and now I'm trying to switch over to MySQL.
I created a new MySQL db, changed database.yml accordingly, and I added an older version of the mysql2 gem to my gemfile (gem 'mysql2', '< 0.3') which is supposed to play nicer with Rails 3.
I can start the dev server fine. When I visit a page, I get a Mysql2::Error (Table 'twitter_quiz_development.users' doesn't exist). Which is fine--I still need to add the schema to the new db. This is where I run into trouble:
rake db:schema:load returns this nasty error.
The solution found here did not work for me. gem pristine --all return this.
I'm running Ubuntu 11 if that helps.
It appears that the error has to do with JSON but I have no idea how to solve this. Thanks.
The issue(s) you are experiencing could be due to 3 things:
The version of Ruby you are using
The use of the SystemTimer gem with Ruby 1.9
The JSON gem
I've elaborated below...
The first thing I would suggest is to upgrade your version of Ruby 1.9. The latest stable is:
ruby 1.9.2p180 (2011-02-18 revision 30909)
I would highly recommend using Ruby Version Manager (RVM) to install and manage Rubies.
In terms of using the JSON gem, have a look at:
http://ruby.about.com/od/tasks/a/The-Json-Gem.htm
To quote:
On Ruby 1.8.7, you'll need to install a gem. However, in Ruby 1.9.2, the json gem is bundled with the core Ruby distribution. So, if you're using 1.9.2, you're probably all set. If you're on 1.8.7, you'll need to install a gem.
Before you install the JSON gem, first realize that this gem is distrubuted in two variants. Simply installing this gem with gem install json will install the C extension variant. This requires a C compiler to install, and may not be available or appropriate on all systems. Though if you can install this version, you should.
If you can't install the C extension version, you should gem install json_pure instead. This is the same gem implemented in pure Ruby. It should run everywhere that Ruby code runs, on all platforms and on a variety of interpreters. However, it's considerably slower than the C extension version.
Edit:
Looks like you should avoid using the SystemTimer gem with Ruby 1.9. See this for more info: http://isitruby19.com/systemtimer
To quote a comment made on that page by Phillipe:
I am the (co)-author of this gem. Short story : Using this gem in Ruby 1.9 is useless and does not make any sense!
System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details.
It is then irrelevant in a Ruby 1.9 which abandoned the green thread model and embraced native threads (kind of since there is still a global interpreter lock).
Cheers,
- Philippe
Your gem pristine --all looks like it errored out with the SystemTimer gem before it got to the json gem. Is that gem used in the Rails app in question?
Are you using RVM? If so, I'd manually remove the SystemTimer and json gems and their binaries (if any) from ~/.rvm/gems/ruby-whatever-version/ (in the gem and bin subdirectories).
Try to update to the latest version of the JSON gem (1.5.1) by adding this to your Gemfile:
gem "json", "1.5.1"
And then run bundle install to install SystemTimer and the later version of the json gem.

Ruby mysql2 gem, cannot build on Windows 7

I come from OSX where Ruby runs super flawlessly 90% of the time. I haven't touched it in awhile though and happen to be working on a Windows 7 machine right now. I'm trying to run a simple Ruby on Rails project but I can't seem to get past any of my database setup.
I want to run on mysql but when I try to install the mysql2 gem (via bundle install or gem install mysql2) I get these errors:
Installing mysql2 (0.2.9) with native
extensions
C:/Ruby192/lib/ruby/site_ruby/1
.9.1/rubygems/installer.rb:533:in
`rescue in block in build_extensions':
ERROR: Failed to build gem native
extension.
(Gem::Installer::ExtensionBuildError)
C:/Ruby192/bin/ruby.exe extconf.rb checking for
rb_thread_blocking_region()... *
extconf.rb failed * Could not create
Makefile due to some reason, probably
lack of necessary libraries and/or
headers. Check the mkmf.log file for
more details. You may need
configuration options.
I'm pretty much a complete newb when it comes to this kind of thing so if anyone has any advice, please help!
To install and compile extensions sometimes you need libraries and headers of the dependencies. In this case, you need MySQL headers and libraries to properly compile.
Assuming you downloaded Ruby from RubyInstaller and also installed the Development Kit and followed it's installation instructions, to successfuly install mysql2 gem I recommend you read this answer in our Troubleshooting page:
Download MySQL Connector/C
Extract into a path without spaces
When installing mysql2 gem, provide the additional options (gem install mysql2 -v 0.2.10 -- --with-mysql-include=... --with-mysql-lib...)
Provide for --with-mysql-include option the path to the include directory of MySQL Connector/C. The same for --with-mysql-lib but this time point to lib directory.
Don't forget to copy libmysql.dll to your Ruby bin directory.
Hope this helps.
The problem with native extensions on Windows is that there are two different compiler infrastructures: one based on MS VC and its Visual Studio and one based on MinGW (Minimalist GCC for Windows).
There are Ruby native extensions that can be compiled with any of them and other, that only support one. And since most of them come from some kind of Unix, chances are that mingw works better that MSVC.
So you may try to install mingw and use it to compile mysql gem - there is a special package called devkit, which contains a minimal necessary mingw installation which you just put inside your ruby installation.
I had a success compiling several native extensions using devkit: eventmachine, linecache, bson-ext to name a few. And within devkit you will feel much more are home :-) (coming from OSX)
If you have the devkit setup correct as #Tomasz mentions, please make sure you check the compatibility of mysql2 gem version with windows, I have experienced in the past for it to cause issues and had to go and install a previous version to get it working. Last I remember v0.2.6 was the version that supported windows.