This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Rakefile
61 lines (51 loc) · 1.91 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
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rake/extensiontask"
RSpec::Core::RakeTask.new
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %w[libsodium spec rubocop]
MAKE = ENV["MAKE"] || ENV["make"] || "make"
RUBY_CC_VERSION = ENV["RUBY_CC_VERSION"] || "2.3.0"
desc "Build Windows binary packages"
task "gem:windows" do
require "rake_compiler_dock"
RakeCompilerDock.sh "cd vendor/libsodium && #{MAKE} clean" if File.exist? "vendor/libsodium/Makefile"
sh "bundle package" # Avoid repeated downloads of gems by using gem files from the host.
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake cross native gem"
end
desc "Run autogen"
task :autogen do
cd("vendor/libsodium") { sh "./autogen.sh" }
end
desc "Compile libsodium"
task libsodium: :autogen do
cd("ext/rbnacl") { load "extconf.rb" }
end
spec = Gem::Specification.load("rbnacl-libsodium.gemspec")
PLATFORMS = ["x86-mingw32", "x64-mingw32"].freeze
Rake::ExtensionTask.new("fake_ext", spec) do |ext|
ext.ext_dir = "ext/rbnacl"
ext.cross_compile = true
ext.cross_platform = PLATFORMS
ext.cross_config_options << {
"x86-mingw32" => "--with-host=i686-w64-mingw32",
"x64-mingw32" => "--with-host=x86_64-w64-mingw32"
}
ext.cross_compiling do |gem_spec|
gem_spec.files.reject! { |f| %r{lib\/fake_ext\.so\Z} =~ f }
stage_path = "#{ext.tmp_dir}/#{gem_spec.platform}/stage"
gem_spec.files += Dir["#{stage_path}/vendor/libsodium/dist/**/*"].map do |stage|
gem_path = stage.sub(stage_path + "/", "")
# define empty task to skip copy from vendor/libsodium/dist/*
task stage
task gem_path
gem_path
end
gem_spec.post_install_message = "You installed the binary version of this gem!"
end
end
PLATFORMS.each do |platf|
copy_task = "copy:fake_ext:#{platf}:#{RUBY_CC_VERSION}"
Rake::Task[copy_task].clear_actions if Rake::Task.task_defined?(copy_task)
end