Dear Lazyweb: Gem Platforms

As you may or may not have heard, RubyGems will be merged into Ruby
1.9 sometime in October. Before this can happen RubyGems needs to
automatically install dependencies based on platforms. Fortunately
I’ve got the automatic install part written. Unfortunately I don’t
know if I’ve got figuring out the platforms right. This is where you
come in.

Dear Lazyweb,

Here’s my proposal for how we recognize platforms. From
Config::CONFIG, take the target_os and run it through a case
statement to figure out OS and OS version (if any). Combine the
target_cpu, OS and OS version. This value is your platform.

(There will be a rubygems-platforms.gem much like sources.gem that can
be updated as necessary.)

Using the tattle data (http://tattle.rubygarden.org), the following
code recognizes 26 unique platforms:

def match(cpu, os)
cpu = case cpu
when /i\d86/ then ‘x86’
else cpu
end

os = case os
when /cygwin/ then [ ‘cygwin’, nil ]
when /darwin(\d+)?/ then [ ‘darwin’, $1 ]
when /freebsd(\d+)/ then [ ‘freebsd’, $1 ]
when /^java([\d.]*)/ then [ ‘java’, $1 ]
when /linux/ then [ ‘linux’, $1 ]
when /mingw32/ then [ ‘mingw32’, nil ]
when /mswin32/ then [ ‘mswin32’, nil ]
when /openbsd(\d+.\d+)/ then [ ‘openbsd’, $1 ]
when /solaris(\d+.\d+)/ then [ ‘solaris’, $1 ]
else [ ‘unknown’, nil ]
end

[cpu, os].flatten.compact.join(“-”)
end

require ‘rbconfig’

target_cpu = Config::CONFIG[‘target_cpu’]
target_os = Config::CONFIG[‘target_os’]

puts “Your target_cpu is: #{target_cpu.inspect}”
puts “Your target_os is: #{target_os.inspect}”
puts “Your platform is: #{match(target_cpu, target_os).inspect}”

Lazyweb, I have two major questions for you:

Did I get something wrong? Am I using autoconf’s target_os
correctly? Is Solaris 2.8 really incompatible with Solaris 2.9?
What is a 64-bit Windows’ target_os value?

Do I have all the platforms people run Ruby and RubyGems on? If the
answer to this one is no, do this: gem install tattle; tattle</
kbd>. (Yes, AIX users, I’m talking to you.)

On 8/20/07, Eric H. [email protected] wrote:

Here’s my proposal for how we recognize platforms. From
def match(cpu, os)
when /linux/ then [ ‘linux’, $1 ]
when /mingw32/ then [ ‘mingw32’, nil ]
when /mswin32/ then [ ‘mswin32’, nil ]
when /openbsd(\d+.\d+)/ then [ ‘openbsd’, $1 ]
when /solaris(\d+.\d+)/ then [ ‘solaris’, $1 ]
else [ ‘unknown’, nil ]
end

[cpu, os].flatten.compact.join(“-”)
end

“java” is actually not used in either CPU or OS strings in the config
hash
currently (this is reflected in the tattle data). JRuby uses “java”
either
in the ‘arch’ or ‘target’ strings:

irb(main):002:0> Config::CONFIG.select {|k,v| v =~ /java/}
=> [[“archdir”,
“/Users/nicksieger/Projects/jruby/trunk/jruby/lib/ruby/site_ruby/1.8/java”],
[“arch”, “i386-java1.5”], [“build”, “java1.5”], [“sitearchdir”,
“/Users/nicksieger/Projects/jruby/trunk/jruby/lib/ruby/site_ruby/1.8/java”],
[“target”, “java1.5”]]
irb(main):003:0> RUBY_PLATFORM
=> “java”

Can you work ‘arch’ into the logic somehow? Or suggest an alternative
way
to ensure that JRuby/java platform is possible for gems?

/Nick

On Aug 20, 2007, at 22:11, Nick S. wrote:

[“arch”, “i386-java1.5”], [“build”, “java1.5”], [“sitearchdir”,
“/Users/nicksieger/Projects/jruby/trunk/jruby/lib/ruby/site_ruby/
1.8/java”],
[“target”, “java1.5”]]
irb(main):003:0> RUBY_PLATFORM
=> “java”

Can you work ‘arch’ into the logic somehow? Or suggest an
alternative way
to ensure that JRuby/java platform is possible for gems?

How’s this? It now uses Config::CONFIG[‘arch’]:

def match(arch)
cpu, os = arch.split ‘-’, 2
cpu, os = nil, cpu if os.nil? # java

cpu = case cpu
when /i\d86/ then ‘x86’
else cpu
end

os = case os
when /cygwin/ then [ ‘cygwin’, nil ]
when /darwin(\d+)?/ then [ ‘darwin’, $1 ]
when /freebsd(\d+)/ then [ ‘freebsd’, $1 ]
when /^java$/ then [ ‘java’, nil ]
when /^java([\d.]*)/ then [ ‘java’, $1 ]
when /linux/ then [ ‘linux’, $1 ]
when /mingw32/ then [ ‘mingw32’, nil ]
when /mswin32/ then [ ‘mswin32’, nil ]
when /openbsd(\d+.\d+)/ then [ ‘openbsd’, $1 ]
when /solaris(\d+.\d+)/ then [ ‘solaris’, $1 ]
else [ ‘unknown’, nil ]
end

[cpu, os].flatten.compact.join("-")
end

require ‘rbconfig’

arch = Config::CONFIG[‘arch’]
cpu, os = arch.split ‘-’, 2

puts “Your cpu is: #{cpu.inspect}”
puts “Your os is: #{os.inspect}”
puts “Your platform is: #{match(arch).inspect}”

raise “need a tattle arch dump yaml file!” if ARGV.empty?

puts “loading archs…”

require ‘yaml’
archs = YAML.load(ARGF.read)[‘arch’].keys

def recognize(*archs)
unmatched = {}
seen = {}

archs.each do |arch|
platform = match arch

 seen[platform] = true
 unmatched[arch] = true if platform =~ /-unknown$/

end

return unmatched.keys, seen.keys
end

unmatched, unique = recognize(*archs)

puts “found #{unique.length} unique platforms”
puts
puts unique.sort.join("\n")

unless unmatched.empty? then
puts
puts “unmatched”
puts
puts unmatched.join("\n")
end

On Aug 20, 9:10 pm, Eric H. [email protected] wrote:

statement to figure out OS and OS version (if any). Combine the
target_cpu, OS and OS version. This value is your platform.

Do I have all the platforms people run Ruby and RubyGems on? If the
answer to this one is no, do this: gem install tattle; tattle</
kbd>. (Yes, AIX users, I’m talking to you.)

I wasn’t able to use tattle (because I couldn’t get rubygems to
install, because I couldn’t get zlib to build), but here’s all the
rbconfig info I have:

djberge@td191> uname -a
HP-UX td191 B.11.31 U 9000/800 3397116299 unlimited-user license

ALLOCA =>
AR => ar
ARCHFILE =>
ARCH_FLAG =>
AS => as
ASFLAGS =>
CC => cc -Ae -s
CCDLFLAGS => +Z
CFLAGS => -g
COMMON_HEADERS =>
COMMON_LIBS =>
COMMON_MACROS =>
CP => cp
CPP => cc -Ae -s -E
CPPFLAGS =>
CPPOUTFILE => -o conftest.i
DESTDIR =>
DLDFLAGS => -E
DLDLIBS => -lc
DLEXT => sl
DLEXT2 =>
DLLWRAP =>
ECHO_C => \c
ECHO_N =>
ECHO_T =>
EGREP => grep -E
ENABLE_SHARED => no
EXEEXT =>
EXPORT_PREFIX =>
EXTOUT => .ext
EXTSTATIC =>
GNU_LD => no
INSTALL => /opt/imake/bin/install -c
INSTALL_DATA => /opt/imake/bin/install -c -m 644
INSTALL_PROGRAM => /opt/imake/bin/install -c
INSTALL_SCRIPT => /opt/imake/bin/install -c
LDFLAGS => -L.
LDSHARED => ld -b
LIBEXT => a
LIBPATHENV => SHLIB_PATH
LIBPATHFLAG => -L%s
LIBRUBY => libruby-static.a
LIBRUBYARG => -lruby-static
LIBRUBYARG_SHARED =>
LIBRUBYARG_STATIC => -lruby-static
LIBRUBY_A => libruby-static.a
LIBRUBY_ALIASES => libruby.so
LIBRUBY_DLDFLAGS => -E
LIBRUBY_LDSHARED => ld -b
LIBRUBY_SO => libruby.so.1.8.6
LIBS => -ldld -lcrypt -lm
LINK_SO =>
LN_S => ln -s
MAINLIBS =>
MAJOR => 1
MAKEDIRS => mkdir -p
MAKEFILES => Makefile
MANTYPE => man
MINIRUBY => ./miniruby
MINOR => 8
NM =>
NROFF => /usr/bin/nroff
OBJDUMP =>
OBJEXT => o
OUTFLAG => -o
PACKAGE_BUGREPORT =>
PACKAGE_NAME =>
PACKAGE_STRING =>
PACKAGE_TARNAME =>
PACKAGE_VERSION =>
PATH_SEPARATOR => :
PREP => miniruby
RANLIB => ranlib
RDOCTARGET =>
RM => rm -f
RPATHFLAG =>
RUBYW_INSTALL_NAME =>
RUBY_INSTALL_NAME => ruby
RUBY_SO_NAME => ruby
RUNRUBY => ./miniruby $(srcdir)/runruby.rb --extout=.ext –
SET_MAKE =>
SHELL => /bin/sh
SOLIBS =>
STATIC =>
STRIP => strip
TEENY => 6
TRY_LINK =>
WINDRES =>
XCFLAGS => -DRUBY_EXPORT -DYYMAXDEPTH=300
XLDFLAGS => -Wl,-E
YACC => yacc -Nl40000 -Nm40000
arch => hppa2.0w-hpux11.31
archdir => /house/djberge/lib/ruby/1.8/hppa2.0w-hpux11.31
bindir => /house/djberge/bin
build => hppa2.0w-hp-hpux11.31
build_alias =>
build_cpu => hppa2.0w
build_os => hpux11.31
build_vendor => hp
configure_args => ‘–prefix=/house/djberge’ ‘CC=cc -Ae -s’
datadir => /house/djberge/share
exec_prefix => /house/djberge
host => hppa2.0w-hp-hpux11.31
host_alias =>
host_cpu => hppa2.0w
host_os => hpux11.31
host_vendor => hp
includedir => /house/djberge/include
infodir => /house/djberge/info
libdir => /house/djberge/lib
libexecdir => /house/djberge/libexec
localstatedir => /house/djberge/var
mandir => /house/djberge/man
oldincludedir => /usr/include
prefix => /house/djberge
ruby_install_name => ruby
ruby_version => 1.8
rubylibdir => /house/djberge/lib/ruby/1.8
rubyw_install_name =>
sbindir => /house/djberge/sbin
setup => Setup
sharedstatedir => /house/djberge/com
sitearch => hppa2.0w-hpux11.31
sitearchdir => /house/djberge/lib/ruby/site_ruby/1.8/hppa2.0w-
hpux11.31
sitedir => /house/djberge/lib/ruby/site_ruby
sitelibdir => /house/djberge/lib/ruby/site_ruby/1.8
sysconfdir => /house/djberge/etc
target => hppa2.0w-hp-hpux11.31
target_alias =>
target_cpu => hppa2.0w
target_os => hpux11.31
target_vendor => hp
topdir => /house/djberge/lib/ruby/1.8/hppa2.0w-hpux11.31

Regards,

Dan

On Aug 21, 2007, at 12:14, Daniel B. wrote:

Here’s my proposal for how we recognize platforms. From
I wasn’t able to use tattle (because I couldn’t get rubygems to
install, because I couldn’t get zlib to build), but here’s all the
rbconfig info I have:

[…]
arch => hppa2.0w-hpux11.31
[…]

Beautiful, awesome, thanks!

On Aug 20, 2007, at 9:10 PM, Eric H. wrote:

As you may or may not have heard, RubyGems will be merged into Ruby
1.9 sometime in October. Before this can happen RubyGems needs to
automatically install dependencies based on platforms. Fortunately
I’ve got the automatic install part written.

you will be a hero if this happens: honestly!

a @ http://drawohara.com/

Hi Eric

On Tue, 2007-08-21 at 12:10 +0900, Eric H. wrote:

Do I have all the platforms people run Ruby and RubyGems on? If the
answer to this one is no, do this: gem install tattle; tattle</
kbd>. (Yes, AIX users, I’m talking to you.)

NetBSD and DragonFly seem to be missing. Unfortunately I don’t have any
machines running those to run tattle on (I suspect the arch strings
would be “netbsd” and “dragonfly” though). Maybe someone can confirm.

Andre

Hi

I’m not sure if there were any AIX-aware gems ;-), but

Do I have all the platforms people run Ruby and RubyGems on? If the
answer to this one is no, do this: gem install tattle; tattle</
kbd>. (Yes, AIX users, I’m talking to you.)
done.

On 8/20/07, Eric H. [email protected] wrote:

=> [[“archdir”,
alternative way
to ensure that JRuby/java platform is possible for gems?

How’s this? It now uses Config::CONFIG[‘arch’]:

Looks good, thanks.

/Nick

On Aug 22, 2007, at 07:57, Jeremy McAnally wrote:

Can you hack in developer/user dependencies while you’re in there? :wink:

There’s no such feature request in the tracker, so nobody actually
wants them.

On Aug 22, 2007, at 07:48, Yutaka K. wrote:

I’m not sure if there were any AIX-aware gems ;-), but

There aren’t any platform-aware gems for much more than win32. I
still want to get the best coverage possible.

Do I have all the platforms people run Ruby and RubyGems on? If the
answer to this one is no, do this: gem install tattle; tattle</
kbd>. (Yes, AIX users, I’m talking to you.)
done.

Thanks much!

Can you hack in developer/user dependencies while you’re in there? :wink:

–Jeremy

On 8/20/07, Eric H. [email protected] wrote:

Config::CONFIG, take the target_os and run it through a case
cpu = case cpu
when /mingw32/ then [ ‘mingw32’, nil ]

correctly? Is Solaris 2.8 really incompatible with Solaris 2.9?


http://www.jeremymcanally.com/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:

http://www.rubyinpractice.com/

On Wed, 2007-08-22 at 09:40 +0900, Andre N. wrote:

NetBSD and DragonFly seem to be missing. Unfortunately I don’t have any
machines running those to run tattle on (I suspect the arch strings
would be “netbsd” and “dragonfly” though). Maybe someone can confirm.

Sent one for NetBSD. It’s “netbsdelf” actually.

Andre

On Aug 23, 2007, at 06:54, Andre N. wrote:

On Wed, 2007-08-22 at 09:40 +0900, Andre N. wrote:

NetBSD and DragonFly seem to be missing. Unfortunately I don’t
have any
machines running those to run tattle on (I suspect the arch strings
would be “netbsd” and “dragonfly” though). Maybe someone can confirm.

Sent one for NetBSD. It’s “netbsdelf” actually.

Thanks!