-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathRakefile
79 lines (67 loc) · 2.24 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
# -*- ruby -*-
require 'bundler/gem_helper'
require 'rubygems/package_task'
require 'pathname'
require 'uri'
require 'ostruct'
require 'rake/clean'
require_relative 'lib/libusb/libusb_recipe'
require_relative 'lib/libusb/gem_helper'
CLOBBER.include 'pkg'
CLEAN.include 'ports'
CLEAN.include 'tmp'
CLEAN.include 'ext/tmp'
CLEAN.include 'lib/*.a'
CLEAN.include 'lib/*.so*'
CLEAN.include 'lib/*.dll*'
task :build do
require_relative 'lib/libusb/libusb_recipe'
recipe = LIBUSB::LibusbRecipe.new
recipe.download
end
task :gem => :build
task :compile do
sh "ruby -C ext extconf.rb --disable-system-libusb"
sh "make -C ext install RUBYARCHDIR=../lib"
end
task :gemfile_libusb_gem do
gf = File.read("Gemfile")
gf.gsub!(/^(gemspec)$/, "# \\1")
gf << "\ngem 'libusb'\n"
File.write("Gemfile_libusb_gem", gf)
puts "Gemfile_libusb_gem written"
end
task :test do
sh "ruby -w -W2 -I.:lib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
end
task :default => :test
ci_tests = %w[test_libusb.rb test_libusb_structs.rb]
task :ci do
sh "ruby -w -W2 -I. -e \"#{ci_tests.map{|f| "require 'test/#{f}';"}.join}\" -- -v"
end
CrossLibraries = [
['x86-mingw32', 'i686-w64-mingw32', 'bin/libusb-1.0.dll'],
['x64-mingw32', 'x86_64-w64-mingw32', 'bin/libusb-1.0.dll'],
['x64-mingw-ucrt', 'x86_64-w64-mingw32', 'bin/libusb-1.0.dll'],
# ['x86-linux', 'i686-linux-gnu', 'lib/libusb-1.0.so'],
# ['x86_64-linux', 'x86_64-linux-gnu', 'lib/libusb-1.0.so'],
].map do |ruby_platform, host_platform, libusb_dll|
LIBUSB::CrossLibrary.new ruby_platform, host_platform, libusb_dll
end
LIBUSB::GemHelper.install_tasks
Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:ruby_platform)
CrossLibraries.map(&:ruby_platform).each do |platform|
desc "Build windows and linux fat binary gems"
multitask 'gem:native' => "gem:native:#{platform}"
task "gem:native:#{platform}" do
require 'rake_compiler_dock'
sh "bundle package"
RakeCompilerDock.sh <<-EOT, platform: platform
bundle --local &&
#{ "sudo yum install -y libudev-devel &&" if platform=~/linux/ }
bundle exec rake --trace cross:#{platform} gem "MAKE=make V=1 -j`nproc`" || cat tmp/*/ports/libusb/*/*.log
EOT
end
end
# vim: syntax=ruby