Solaris, Ruby and iconv.
January 30th, 2009
Solaris 10 has a native C library version of iconv. Unfortunately it lacks various features people might want to use, such as transliteration. You can see an example of this here:
# ruby -e "require 'iconv'; p Iconv.iconv('ascii//ignore//translit', 'utf-8', 'Tést')"
-e:1:in `iconv': invalid encoding ("ascii//ignore//translit", "utf-8") (Iconv::InvalidEncoding)
from -e:1
Other people have commented on the problem, for example on this blog here. One suggestion is to install SUNWgnu-libiconv and utilise LD_PRELOAD. The SUNWgnu-libiconv package isn’t around on Solaris 10 (that I know of), so we need to compile up our own libiconv. And LD_PRELOAD is an inelegant, somewhat difficult to implement and potentially dangerous environment variable.
This sadly means we need to recompile things from source. But hey, it’s Solaris! I’m sure you’re used to this by now. So it’s time to get your recompiling hat on and build libiconv and Ruby. A fairly generic build would go something along these lines (feel free to alter all the “/opt/local” paths to suit your own requirements:
# mkdir -p /opt/src
# cd /opt/src
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz
# gtar -zxf libiconv-1.12.tar.gz
# cd libiconv-1.12
# ./configure --prefix=/opt/local
# gmake
# gmake install
# cd /opt/src
# cat <<EOF > /tmp/ruby.patch
--- ruby-1.8.6-p287.good/ext/iconv/extconf.rb Mon Feb 12 23:01:19 2007
+++ ruby-1.8.6-p287/ext/iconv/extconf.rb Thu Jan 29 19:07:45 2009
@@ -22,6 +22,7 @@
end
end
$defs.push('-DICONV_INPTR_CONST')
+ $DLDFLAGS += ' -L/opt/local/lib -R/opt/local/lib -liconv'
end
if conf
prefix = '$(srcdir)'
--- ruby-1.8.6-p287.good/ext/iconv/iconv.c Thu Jan 29 19:10:58 2009
+++ ruby-1.8.6-p287/ext/iconv/iconv.c Thu Jan 29 18:20:56 2009
@@ -16,7 +16,7 @@
#include "ruby.h"
#include <errno.h>
-#include <iconv.h>
+#include </opt/local/include/iconv.h>
#include <assert.h>
#include "st.h"
#include "intern.h"
EOF
# wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
# gtar -zxf ruby-1.8.7-p72.tar.gz
# cd ruby-1.8.7-p72
# patch -p1
# export LDFLAGS="-L/usr/sfw/lib -R/usr/sfw/lib -L/opt/local/lib -R/opt/local/lib"
# export CFLAGS="-I/usr/sfw/include -I/opt/local/include"
# export CPPFLAGS=$CFLAGS
# ./configure --prefix=/opt/ruby
# gmake
# gmake install
The above patch basically overrides the iconv that’s used. If you’re feeling fruity, you could grab the source to Sun Web Stack and modify their Ruby, which includes DTrace patches.
Entry Filed under: General

1 Comment Add your own
1. Ben Summers | February 1st, 2009 at 9:44 pm
It is easier to patch activesupport/lib/active_support/inflector.rb than doing a recompile of ruby!
See the final patch here: http://rails.lighthouseapp.com/projects/8994/tickets/1396-framework-crashes-on-launch-on-solaris-with-invalid-encoding-asciiignoretranslit-utf-8
Basically there’s a minor bug which means that the code to recover from unsupported iconv doesn’t actually recover from this particular unsupported encoding. Rails 2.2.2 on WebStack 1.4 works with these lines of code added to that one file, no other recompilation required.
Ben
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed