Permalink
Browse files

Add support for building binary gems for windows using rake-compiler …

…and fix some Ruby 1.9 bugs
  • Loading branch information...
1 parent 612d601 commit bfeaceb17f71a09d127609dc03e8332228257aad @warhammerkid warhammerkid committed Jun 30, 2011
View
@@ -2,9 +2,7 @@ pkg/*
.loadpath
.project
/rdoc/
-/ext/*.o
-/ext/Makefile
-/ext/*.bundle
-/ext/*.so
-/ext/*.dll
-/ext/*.log
+*.bundle
+*.so
+*.dll
+/tmp
View
@@ -3,6 +3,7 @@ require 'rake'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
+require 'rake/extensiontask'
desc 'Default: run the specs.'
task :default => :spec
@@ -34,6 +35,25 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
end
Rake::GemPackageTask.new(spec) do |pkg|
- pkg.need_tar = true
- pkg.need_zip = true
+ pkg.need_zip = false
+ pkg.need_tar = false
+end
+
+Rake::ExtensionTask.new('rocketamf_ext', spec) do |ext|
+ if RUBY_PLATFORM =~ /mswin|mingw/ then
+ # No cross-compile on win, so compile extension to lib/1.[89]
+ RUBY_VERSION =~ /(\d+\.\d+)/
+ ext.lib_dir = "lib/#{$1}"
+ else
+ ext.cross_compile = true
+ ext.cross_platform = 'x86-mingw32'
+ ext.cross_compiling do |gem_spec|
+ gem_spec.post_install_message = "You installed the binary version of this gem!"
+ end
+ end
+end
+
+desc "Build gem packages"
+task :gems do
+ sh "rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2"
end
View
@@ -3,20 +3,18 @@
Gem::Specification.new do |s|
s.name = 'RocketAMF'
s.version = '1.0.0'
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['Jacob Henry', 'Stephen Augenstein', "Joc O'Connor"]
+ s.email = ['perl.programmer@gmail.com']
+ s.homepage = 'http://github.com/rubyamf/rocketamf'
s.summary = 'Fast AMF serializer/deserializer with remoting request/response wrappers to simplify integration'
- s.files = Dir[*['README.rdoc', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.{rb,bin,opts}', 'ext/*.{c,h,rb}']]
- s.require_paths = ["lib", "ext"]
- s.extensions = ["ext/extconf.rb"]
+ s.files = Dir[*['README.rdoc', 'benchmark.rb', 'RocketAMF.gemspec', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.{rb,bin,opts}', 'ext/**/*.{c,h,rb}']]
s.test_files = Dir[*['spec/**/*_spec.rb']]
+ s.extensions = Dir[*["ext/**/extconf.rb"]]
+ s.require_paths = ["lib"]
s.has_rdoc = true
s.extra_rdoc_files = ['README.rdoc']
s.rdoc_options = ['--line-numbers', '--main', 'README.rdoc']
-
- s.authors = ['Jacob Henry', 'Stephen Augenstein', "Joc O'Connor"]
- s.email = 'perl.programmer@gmail.com'
- s.homepage = 'http://github.com/rubyamf/rocketamf'
-
- s.platform = Gem::Platform::RUBY
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,10 @@
-require 'rocketamf_ext'
+begin
+ # Fat binaries for Windows
+ RUBY_VERSION =~ /(\d+.\d+)/
+ require "#{$1}/rocketamf_ext"
+rescue LoadError
+ require "rocketamf_ext"
+end
module RocketAMF
# This module holds all the modules/classes that implement AMF's functionality
@@ -1,5 +1,4 @@
require "spec_helper.rb"
-require 'rocketamf_ext'
describe RocketAMF::Ext::FastClassMapping do
before :each do
@@ -85,6 +84,17 @@
end
describe "property extractor" do
+ # Use symbol keys for properties in Ruby >1.9
+ def prop_hash hash
+ out = {}
+ if RUBY_VERSION =~ /^1\.8/
+ hash.each {|k,v| out[k.to_s] = v}
+ else
+ hash.each {|k,v| out[k.to_sym] = v}
+ end
+ out
+ end
+
it "should return hash without modification" do
hash = {:a => 'test1', 'b' => 'test2'}
props = @mapper.props_for_serialization(hash)
@@ -96,7 +106,7 @@
obj.prop_a = 'Test A'
hash = @mapper.props_for_serialization obj
- hash.should == {'prop_a' => 'Test A', 'prop_b' => nil}
+ hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => nil})
end
it "should extract inherited object properties" do
@@ -105,7 +115,7 @@
obj.prop_c = 'Test C'
hash = @mapper.props_for_serialization obj
- hash.should == {'prop_a' => 'Test A', 'prop_b' => nil, 'prop_c' => 'Test C'}
+ hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => nil, 'prop_c' => 'Test C'})
end
it "should cache property lookups by instance" do
@@ -123,12 +133,12 @@ class ClassMappingTest3; attr_accessor :prop_b; end;
obj.prop_a = 'Test A'
obj.prop_b = 'Test B'
hash = @mapper.props_for_serialization obj
- hash.should == {'prop_a' => 'Test A'}
+ hash.should == prop_hash({'prop_a' => 'Test A'})
# Test that new class mapper *does* have new property (cache per instance)
@mapper = RocketAMF::Ext::FastClassMapping.new
hash = @mapper.props_for_serialization obj
- hash.should == {'prop_a' => 'Test A', 'prop_b' => 'Test B'}
+ hash.should == prop_hash({'prop_a' => 'Test A', 'prop_b' => 'Test B'})
end
end
end
@@ -319,7 +319,9 @@ class SimpleObj
it "should serialize a byte array" do
expected = object_fixture("amf3-byteArray.bin")
- input = StringIO.new "\000\003これtest\100"
+ str = "\000\003これtest\100"
+ str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
+ input = StringIO.new(str)
output = RocketAMF.serialize(input, 3)
output.should == expected
end
Binary file not shown.
View
@@ -7,19 +7,18 @@
end
require 'spec/autorun'
-$:.unshift(File.dirname(__FILE__) + '/../ext')
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'rocketamf'
require 'rocketamf/pure/io_helpers' # Just to make sure they get loaded
def request_fixture(binary_path)
- data = File.open(File.dirname(__FILE__) + '/fixtures/request/' + binary_path).read
+ data = File.open(File.dirname(__FILE__) + '/fixtures/request/' + binary_path, "rb").read
data.force_encoding("ASCII-8BIT") if data.respond_to?(:force_encoding)
data
end
def object_fixture(binary_path)
- data = File.open(File.dirname(__FILE__) + '/fixtures/objects/' + binary_path).read
+ data = File.open(File.dirname(__FILE__) + '/fixtures/objects/' + binary_path, "rb").read
data.force_encoding("ASCII-8BIT") if data.respond_to?(:force_encoding)
data
end

0 comments on commit bfeaceb

Please sign in to comment.