[Rubygems-developers] Building native gems for deployment

Patrick Hurley phurley at gmail.com
Wed Apr 18 00:14:01 EDT 2007


On 4/13/07, Graham Miller <gmiller at marketcetera.com> wrote:
> So I guess my question would be: what is the best way to install a gem onto
> a machine without having to do the native compilation step?

I had a similar problem, with very little testing (so far), try this
script, if you have any problems let me know.

pth

---------------------------------------------
#!/usr/bin/env ruby -w

require "rbconfig"
require "rubygems"
require "pp"
require "tmpdir"
require "find"
require "fileutils"

Gem.manage_gems
unless gem = ARGV.first
  puts "You must provide the name of a gem on the command line."
  exit 1
end

gi = Gem::Installer.new(gem)
format = Gem::Format.from_file_by_path(gem)

dir = File.join(Dir.tmpdir, "gembuilder")
FileUtils.rm_r(dir) rescue nil

puts "Unpacking gem"
gi.unpack(dir)

gi.build_extensions(dir, format.spec)
files = []
Find.find(dir) do |fname|
  next if fname == dir
  files << fname.sub(Regexp.quote(dir+"/"),'')
end

spec = format.spec
spec.extensions = []
spec.files += (files - format.spec.files)
spec.platform = Config::CONFIG['arch'].sub(/[\.0-9]*$/, '')

puts "Building gem in #{dir}"
start_dir = Dir.pwd
Dir.chdir(dir) do
  gb = Gem::Builder.new(spec)
  gb.build
  FileUtils.mv Dir.glob("*.gem"), start_dir
end

puts "Cleaning up #{dir}"
FileUtils.rm_rf(dir)


More information about the Rubygems-developers mailing list