mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Merge branch 'feature/fat_gem_support' into develop
This commit is contained in:
commit
7117303d48
6 changed files with 101 additions and 12 deletions
|
@ -14,7 +14,6 @@
|
|||
* [hoe](https://github.com/seattlerb/hoe)
|
||||
* [hoe-gemspec](https://github.com/flavorjones/hoe-gemspec)
|
||||
* [rake-compiler](https://github.com/luislavena/rake-compiler)
|
||||
* [gem-compile](https://github.com/frsyuki/gem-compile)
|
||||
|
||||
|
||||
## Create ruby-opencv gem
|
||||
|
@ -32,16 +31,34 @@ $ git ls-files > Manifest.txt
|
|||
$ rake gem:spec
|
||||
$ rake gem
|
||||
```
|
||||
**ruby-opencv-x.y.z.gem** will be created in pkg/ directory.
|
||||
**ruby-opencv-x.y.z.gem** will be created in **pkg** directory.
|
||||
|
||||
To create pre-build binaries, run the following commands in Windows.
|
||||
To create pre-build binaries, create a config file firstly:
|
||||
|
||||
```
|
||||
$ cd pkg
|
||||
$ gem compile ruby-opencv-*.gem
|
||||
```yml
|
||||
# config.yml
|
||||
platform: mingw32
|
||||
rubies:
|
||||
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
|
||||
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
|
||||
extopts:
|
||||
- --with-opencv-include=C:/opencv/build/include
|
||||
- --with-opencv-lib=C:/opencv/build/x86/mingw/lib
|
||||
```
|
||||
|
||||
**ruby-opencv-x.y.z-x86-mingw32.gem** will be created when you use mingw32, or
|
||||
Entries are below:
|
||||
|
||||
- **platform**: Target platform (e.g. mingw32, mswin32)
|
||||
- **rubies**: Array of target versions of ruby's paths (You can create fat gems if you specify multiple versions of ruby)
|
||||
- **extopts**: Array of options to be passed to **extconf.rb**
|
||||
|
||||
Then, run the following command:
|
||||
|
||||
```
|
||||
$ rake gem:precompile CONFIG=config.yml
|
||||
```
|
||||
|
||||
**ruby-opencv-x.y.z-mingw32.gem** will be created when you use mingw32, or
|
||||
**ruby-opencv-x.y.z-x86-mswin32.gem** when you use mswin32.
|
||||
|
||||
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -4,6 +4,5 @@ group :development do
|
|||
gem "hoe"
|
||||
gem "hoe-gemspec"
|
||||
gem "rake-compiler"
|
||||
gem "gem-compile"
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ License.txt
|
|||
Manifest.txt
|
||||
README.md
|
||||
Rakefile
|
||||
config.yml
|
||||
examples/alpha_blend.rb
|
||||
examples/box.png
|
||||
examples/box_in_scene.png
|
||||
|
|
60
Rakefile
60
Rakefile
|
@ -1,8 +1,13 @@
|
|||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
require 'rubygems'
|
||||
require './lib/opencv/psyched_yaml'
|
||||
require "rubygems/ext"
|
||||
require "rubygems/installer"
|
||||
require 'hoe'
|
||||
require 'rake/extensiontask'
|
||||
require 'fileutils'
|
||||
require './lib/opencv/psyched_yaml'
|
||||
|
||||
SO_FILE = 'opencv.so'
|
||||
|
||||
Hoe.plugin :gemspec
|
||||
|
||||
|
@ -16,14 +21,16 @@ hoespec = Hoe.spec 'ruby-opencv' do |s|
|
|||
|
||||
s.readme_file = 'README.md'
|
||||
s.history_file = 'History.txt'
|
||||
|
||||
s.spec_extras = { :extensions => ['ext/opencv/extconf.rb'] }
|
||||
|
||||
s.test_globs = ['test/test_*.rb']
|
||||
s.urls = ['https://github.com/ruby-opencv/ruby-opencv/']
|
||||
|
||||
s.extra_dev_deps << ['rake-compiler', '>= 0'] << ['hoe-gemspec']
|
||||
|
||||
Rake::ExtensionTask.new('opencv', spec) do |ext|
|
||||
ext.lib_dir = File.join('lib', 'opencv')
|
||||
ext.lib_dir = 'lib'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,4 +38,53 @@ hoespec.spec.files.delete('.gemtest')
|
|||
|
||||
Rake::Task[:test].prerequisites << :compile
|
||||
|
||||
desc 'Create a pre-compiled gem'
|
||||
task 'gem:precompile' => ['gem'] do
|
||||
tmp_dir = Dir.mktmpdir('tmp', '.')
|
||||
gemfile = Dir.glob("pkg/*.gem")[0]
|
||||
target_dir = File.join(tmp_dir, File.basename(gemfile, '.gem'))
|
||||
|
||||
installer = Gem::Installer.new(gemfile)
|
||||
installer.unpack(target_dir)
|
||||
|
||||
gemspec = installer.spec
|
||||
extension = gemspec.extensions[0]
|
||||
gemspec.extensions.clear
|
||||
|
||||
config = ENV['CONFIG'] ? YAML.load_file(ENV['CONFIG']) : {}
|
||||
rubies = config['rubies'] || [Gem.ruby]
|
||||
args = config['extopts'] || []
|
||||
gemspec.platform = config['platform'] || Gem::Platform::CURRENT
|
||||
|
||||
multi = rubies.size > 1
|
||||
rubies.each { |ruby|
|
||||
lib_dir = 'lib'
|
||||
if multi
|
||||
major, minor, _ = `#{ruby} -e "print RUBY_VERSION"`.chomp.split('.')
|
||||
lib_dir = File.join(lib_dir, [major, minor].join('.'))
|
||||
end
|
||||
|
||||
make_cmd = (`#{ruby} -e "print RUBY_PLATFORM"` =~ /mswin/) ? 'nmake' : 'make'
|
||||
Dir.chdir(target_dir) {
|
||||
cmd = [ruby, extension, *args].join(' ')
|
||||
results = []
|
||||
Gem::Ext::ExtConfBuilder.run(cmd, results)
|
||||
Gem::Ext::ExtConfBuilder.make('', results)
|
||||
|
||||
FileUtils.mkdir_p lib_dir
|
||||
FileUtils.mv SO_FILE, lib_dir
|
||||
sh "#{make_cmd} clean"
|
||||
}
|
||||
|
||||
gemspec.files << File.join(lib_dir, SO_FILE)
|
||||
}
|
||||
|
||||
Dir.chdir(target_dir) {
|
||||
gemfile = Gem::Package.build(gemspec)
|
||||
FileUtils.mv gemfile, File.dirname(__FILE__)
|
||||
}
|
||||
|
||||
FileUtils.rm_rf tmp_dir
|
||||
end
|
||||
|
||||
# vim: syntax=ruby
|
||||
|
|
7
config.yml
Normal file
7
config.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
platform: mingw32
|
||||
rubies:
|
||||
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
|
||||
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
|
||||
extopts:
|
||||
- --with-opencv-include=C:/opencv/build/include
|
||||
- --with-opencv-lib=C:/opencv/build/x86/mingw/lib
|
|
@ -1,3 +1,12 @@
|
|||
require (File.dirname(__FILE__) + '/opencv/version')
|
||||
require 'opencv.so'
|
||||
|
||||
if RUBY_PLATFORM =~ /mingw|mswin/
|
||||
major, minor, subminor = RUBY_VERSION.split('.')
|
||||
begin
|
||||
require "#{major}.#{minor}/opencv.so"
|
||||
rescue LoadError
|
||||
require 'opencv.so'
|
||||
end
|
||||
else
|
||||
require 'opencv.so'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue