Permalink
Browse files

Allow targeting multiple versions for cross compiling.

This change automatically append MAJOR.MINOR Ruby version
of the compiled extension in the target directory.

A better picture:

  rake cross compile RUBY_CC_VERSION=1.8.6:1.9.1

Will generate the following files:

  lib/1.8/extension_name.so
  lib/1.9/extension_name.so
  • Loading branch information...
1 parent 687d115 commit 56fdb8b0669b879c237a06c23e09f8bce9ce2cf2 @luislavena luislavena committed May 31, 2009
Showing with 31 additions and 0 deletions.
  1. +9 −0 features/cross-compile.feature
  2. +8 −0 features/step_definitions/cross_compilation.rb
  3. +14 −0 lib/rake/extensiontask.rb
@@ -11,3 +11,12 @@ Feature: Cross-compile C extensions
When rake task 'cross compile' is invoked
Then rake task 'cross compile' succeeded
And binaries for platform 'i386-mingw32' get generated
+
+ Scenario: compile single extension to multiple versions
+ Given that all my source files are in place
+ And I'm running a POSIX operating system
+ And I've installed cross compile toolchain
+ When rake task 'cross compile RUBY_CC_VERSION=1.8.6:1.9.1' is invoked
+ Then rake task 'cross compile RUBY_CC_VERSION=1.8.6:1.9.1' succeeded
+ And binaries for platform 'i386-mingw32' version '1.8' get copied
+ And binaries for platform 'i386-mingw32' version '1.9' get copied
@@ -22,3 +22,11 @@
ext_for_platform = Dir.glob("tmp/#{platform}/**/*.#{ext}")
ext_for_platform.should_not be_empty
end
+
+Then /^binaries for platform '(.*)' version '(.*)' get copied$/ do |platform, version|
+ lib_path = "lib/#{version}"
+ ext = binary_extension(platform)
+
+ ext_for_platform = Dir.glob("#{lib_path}/*.#{ext}")
+ ext_for_platform.should_not be_empty
+end
View
@@ -236,8 +236,22 @@ def define_cross_platform_tasks(for_platform)
ruby_vers = [RUBY_VERSION]
end
+ multi = (ruby_vers.size > 1) ? true : false
+
ruby_vers.each do |version|
+ # save original lib_dir
+ orig_lib_dir = @lib_dir
+
+ # tweak lib directory only when targeting multiple versions
+ if multi then
+ version =~ /(\d+.\d+)/
+ @lib_dir = "#{@lib_dir}/#{$1}"
+ end
+
define_cross_platform_tasks_with_version(for_platform, version)
+
+ # restore lib_dir
+ @lib_dir = orig_lib_dir
end
end

0 comments on commit 56fdb8b

Please sign in to comment.