-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
74 lines (62 loc) · 2.16 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
# frozen_string_literal: true
require "rbconfig"
require "rake/clean"
require "rubygems/package_task"
require_relative "lib/ffi-libarchive-binary/libarchive_recipe"
require "rspec/core/rake_task"
require "rubocop/rake_task"
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new
task default: %i[spec rubocop]
task spec: :compile
desc "Build install-compilation gem"
task "gem:native:any" do
sh "rake platform:any gem"
end
desc "Define the gem task to build on any platform (compile on install)"
task "platform:any" do
spec = Gem::Specification::load("ffi-libarchive-binary.gemspec").dup
task = Gem::PackageTask.new(spec)
task.define
end
platforms = [
["x64-mingw32", "x86_64-w64-mingw32"],
["x64-mingw-ucrt", "x86_64-w64-mingw32"],
["x86_64-linux", "x86_64-linux-gnu"],
["aarch64-linux", "aarch64-linux-gnu"],
["x86_64-darwin", "x86_64-apple-darwin"],
["arm64-darwin", "arm64-apple-darwin"],
]
platforms.each do |platform, host|
desc "Build pre-compiled gem for the #{platform} platform"
task "gem:native:#{platform}" do
sh "rake compile[#{host}] platform:#{platform} gem"
end
desc "Define the gem task to build on the #{platform} platform (binary gem)"
task "platform:#{platform}" do
spec = Gem::Specification::load("ffi-libarchive-binary.gemspec").dup
spec.platform = Gem::Platform.new(platform)
spec.files += Dir.glob("lib/ffi-libarchive-binary/*.{dll,so,dylib}")
spec.extensions = []
spec.dependencies.reject! { |d| d.name == "mini_portile2" }
task = Gem::PackageTask.new(spec)
task.define
end
end
desc "Compile binary for the target host"
task :compile, [:host] do |_t, args|
recipe = LibarchiveBinary::LibarchiveRecipe.new
if args[:host]
recipe.host = args[:host]
else
recipe.host = "x86_64-apple-darwin" if /x86_64-apple-darwin*/.match?(recipe.host)
recipe.host = "arm64-apple-darwin" if /arm64-apple-darwin*/.match?(recipe.host)
end
recipe.cook_if_not
end
CLOBBER.include("pkg")
CLEAN.include("ports",
"tmp",
"lib/ffi-libarchive-binary/libarchive-13.dll",
"lib/ffi-libarchive-binary/libarchive.dylib",
"lib/ffi-libarchive-binary/libarchive.so")