ruby-on-railsrubyubuntumongrel

Errors installing Mongrel 1.2.0_pre2 on Ruby 2.1.x installed via PPA from Brightbox


I have inherited a Ruby on Rails application codebase as part of a new gig. The code is currently live in production but I have been charged with assessing and cleaning up. As such the code includes Mongrel dependencies; specifically Mogrel 1.2.0_pre2 which might have last been updated in 2010 but that is what this code uses.

The local development environment is running in Ubuntu 12.04 and have successfully installed all Ruby GEMs via bundle install when I install Ruby 2.1.x from source code.

But I recently learned about the Ubuntu ready packages from Brightbox I was thrilled! I don’t mind installing form source but would rather deal with the cleanliness of a package install. So, on a completely clean Ubuntu 12.04 system I started to rebuild my Ruby development box I added the PPA to my repo:

sudo add-apt-repository ppa:brightbox/ruby-ng

Updated the local sources list:

sudo aptitude update

And installed their Ruby 2.1 package like so:

sudo aptitude install ruby2.1 ruby2.1-dev

And things went well until during bundle install up until Mogrel died with compilation errors:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb 
checking for main() in -lc... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling http11.c
http11.c: In function ‘http_field’:
http11.c:193:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c:194:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c: In function ‘request_uri’:
http11.c:235:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c: In function ‘fragment’:
http11.c:246:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c: In function ‘request_path’:
http11.c:257:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c: In function ‘query_string’:
http11.c:268:3: error: format not a string literal and no format arguments [-Werror=format-security]
http11.c: In function ‘HttpParser_execute’:
http11.c:439:5: error: format not a string literal and no format arguments [-Werror=format-security]
cc1: some warnings being treated as errors
make: *** [http11.o] Error 1

make failed, exit code 2

Gem files will remain installed in /tmp/bundler20141208-21746-1qez12a/mongrel-1.2.0.pre2/gems/mongrel-1.2.0.pre2 for inspection.
Results logged to /tmp/bundler20141208-21746-1qez12a/mongrel-1.2.0.pre2/extensions/x86_64-linux/2.1.0/mongrel-1.2.0.pre2/gem_make.out
An error occurred while installing mongrel (1.2.0.pre2), and Bundler cannot
continue.
Make sure that `gem install mongrel -v '1.2.0.pre2'` succeeds before bundling.

But running gem install mongrel -v '1.2.0.pre2' doesn’t seem to help; it goes through the expected motions and then fails with the exact same http11.c errors as when doing it via bundle install.

I have read a few threads Stack Overflow related to issues folks have had installing any version of Mongrel in Ruby 1.9.2 onwards such as in this thread and in this thread.

All of the solutions that are not focusing on “You should just use Thin instead.” talk about manually patching http11.c. But the references—like this page—are to Ruby 1.9.1 and Mongrel 1.1.5 and the line numbers referenced definitely don’t correspond to equivalents in Mogrel_1.2.0pre2.

And ironically some solutions actually direct a user to install Mogrel version 1.2.0pre2 instead of 1.1.5 to get around the issue; but I am trying to install version 1.2.0pre2 and can’t seem to get that done.

Of course I would like to know how to get past this Mongrel error, so help on that would be appreciated. But why is it that when I install Ruby 2.1.x via the Brightbox PPA this error pops up while if I compile Ruby 2.1.x directly from source this error just doesn’t appear at all?


Solution

  • Okay, so after some hunting around I stumbled across a solution which allows me to cleanly—without a need for manual patching—install Mogrel 1.2.0_pre2 on Ruby 2.1.x. The solution is to do a direct Ruby install of the GEM with --with-cflags like this:

    sudo gem install mongrel -v 1.2.0.pre2 -- --with-cflags=\"-O2 -pipe -march=native -w\"
    

    Once I did that compilation was completed without issue and the GEM was successfully installed:

    Building native extensions with: '--with-cflags="-O2 -pipe -march=native -w"'
    This could take a while...
    Successfully installed mongrel-1.2.0.pre2
    Parsing documentation for mongrel-1.2.0.pre2
    Installing ri documentation for mongrel-1.2.0.pre2
    Done installing documentation for mongrel after 1 seconds
    1 gem installed
    

    But I am still wondering why a Ruby 2.1.x install via the Brightbox PPA causes an issue when a pure source code install of Ruby 2.1.x has no problems at all.

    And not 100% clear on how --with-cflags=\"-O2 -pipe -march=native -w\" factors into this, but it seems to be a common --with-cflags option used to get some stubborn (perhaps outdated?) Ruby GEMs installed on versions of Ruby higher than 1.9.2.