brianmario/mysql2 — Issue #240: extconf.rb assumes use of gcc on Solaris
Author: GarthSnyder
Created: 2012-01-16 23:25:15+00:00
State: open

Most CFLAGS flow through from mysql_config, but there are a couple of lines in extconf.rb that stuff in some extra, gcc-specific command line options. Specifically, this passage:

unless RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /sparc/
$CFLAGS << ' -Wall -funroll-loops'
end
# $CFLAGS << ' -O0 -ggdb3 -Wextra'

if hard_mysql_path = $libs[%r{-L(/[^ ]+)}, 1]
$LDFLAGS << " -Wl,-rpath,#{hard_mysql_path}"
end

Solaris 11's default binary package for MySQL assumes that you're using the (free) Solaris Studio compiler, which seems to be the path of least resistance. Both cc and ldd choke on the gcc-flavored flags shown above.

You can force CC to gcc in the environment when installing the mysql2 gem, but then you'll pick up a bunch of Solaris-Studio-specific CFLAGS from mysql_config and gcc will barf.

The situation is complicated by the fact that if you build MySQL from source, you can use either Solaris Studio compiler or gcc (see [notes here](http://dev.mysql.com/doc/refman/5.1/en/solaris-installation-source.html)). Presumably, if you build with gcc, then appropriate gcc options will flow through to mysql_config and then you'll want mysql2 to have exactly its current behavior.

I'm not familiar enough with the code to suggest a specific solution, but if there's a straightforward "Am I using gcc?" test available, that should probably added to both the conditionals above. It's available in RbConfig::CONFIG['GCC'] under Ruby 1.9 ("yes" if so, "" if not), but I'm not sure what you'd do in older versions of Ruby.

mysql2 seems to work fine without the gcc options when compiled with cc.