From: Mauricio Fernandez Date: 2006-05-24T05:35:23+09:00 Subject: Re: [ANN] rcov 0.4.0 (code coverage) - scriptability, accuracy, unrotten internals On Tue, May 23, 2006 at 07:32:41AM +0900, John-Mason P. Shackelford wrote: > I was recently faced with the issue of packaging a library that needed > to execute cross platform but for which a windows binary was required > and wondered why, when a win32 library is required, we don't just > package it in a win32 directory inside the gem and require it when the > platform is win32. These binaries take up very little disk space > (which is cheap anyway) and I'd rather have a little unused windows > dll on my Linux systems than to bother with installing (and > maintaining) different gems for different platforms. > > Okay, Jim, tell me I am crazy. (Or ignorant--that would be much worse.) I got to generate the platform-independent package and the cross-compiled binary one as follows: PKG_REVISION = ".1" PKG_FILES = FileList[ # sources, docs and Rakefile # this is a modified rbconfig.rb based on that generated by a cross-compiled # ruby targetting mingw32 "mingw-rbconfig.rb" ] require 'rake/gempackagetask' Spec = Gem::Specification.new do |s| # ... s.files = PKG_FILES.to_a s.extensions << "ext/rcovrt/extconf.rb" # ... end task :gem => [:test] Rake::GemPackageTask.new(Spec) do |p| p.need_tar = true end # {{{ Cross-compilation and building of a binary RubyGems package for mswin32 require 'rake/clean' WIN32_PKG_DIR = "rcov-" + Rcov::VERSION + PKG_REVISION file "#{WIN32_PKG_DIR}" => [:package] do sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz" end # this overrides the normal rbconfig.rb, in order to generate a Makefile # suitable for cross-compilation desc "Cross-compile the rcovrt.so extension for win32" file "rcovrt_win32" => ["#{WIN32_PKG_DIR}"] do cp "mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/rcovrt/rbconfig.rb" sh "cd #{WIN32_PKG_DIR}/ext/rcovrt/ && ruby -I. extconf.rb && make" mv "#{WIN32_PKG_DIR}/ext/rcovrt/rcovrt.so", "#{WIN32_PKG_DIR}/lib" end # New spec, essentially like the first one, modulo: # * the platform, set to WIN32, # * the removal of the extensions attribute, so that no compilation is # attempted at install time # * the addition of the desired .so to the list of files to be included Win32Spec = Spec.clone Win32Spec.platform = Gem::Platform::WIN32 Win32Spec.extensions = [] Win32Spec.files += ["lib/rcovrt.so"] desc "Build the binary RubyGems package for win32" task :rubygems_win32 => ["rcovrt_win32"] do Dir.chdir("#{WIN32_PKG_DIR}") do Gem::Builder.new(Win32Spec).build verbose(true) { mv Dir["*.gem"].first, "../pkg/rcov-#{Rcov::VERSION + PKG_REVISION}-mswin32.gem" } end end CLEAN.include "#{WIN32_PKG_DIR}" -- Mauricio Fernandez - http://eigenclass.org - singular Ruby