forked from rubyjs/libv8-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
79 lines (60 loc) · 2.35 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
require 'bundler/setup'
Bundler::GemHelper.install_tasks
module Helpers
module_function
def binary_gemspec(platform: Gem::Platform.local, str: RUBY_PLATFORM)
# TODO: old rubygems and cross compile
platform.instance_eval { @version = 'musl' } if str =~ /-musl/ && platform.version.nil?
gemspec = eval(File.read('libv8-node.gemspec')) # rubocop:disable Security/Eval
gemspec.platform = platform
gemspec
end
def binary_gem_name(platform = Gem::Platform.local)
File.basename(binary_gemspec(platform).cache_file)
end
end
task :compile, [:platform] => [] do |_, args|
local_platform = Gem::Platform.local
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
if target_platform.os == 'darwin'
target_platform.instance_eval { @version = nil }
end
puts "local platform: #{local_platform}"
puts "target platform: #{target_platform}"
ENV['RUBY_TARGET_PLATFORM'] = target_platform.to_s
if (libs = Dir["vendor/v8/#{target_platform}/**/*.a"]).any?
puts "found: #{libs.inspect}"
next
end
Dir.chdir('ext/libv8-node') do # gem install behaves like that
sh 'ruby extconf.rb'
end
end
task :binary, [:platform] => [:compile] do |_, args|
local_platform = Gem::Platform.local.dup
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local)
if target_platform.os == 'darwin'
target_platform.instance_eval { @version = nil }
end
puts "local platform: #{local_platform}"
puts "target platform: #{target_platform}"
gemspec = Helpers.binary_gemspec(platform: target_platform)
gemspec.extensions.clear
# We don't need most things for the binary
gemspec.files = []
gemspec.files += ['lib/libv8-node.rb', 'lib/libv8/node.rb', 'lib/libv8/node/version.rb']
gemspec.files += ['ext/libv8-node/location.rb', 'ext/libv8-node/paths.rb']
gemspec.files += ['ext/libv8-node/.location.yml']
# V8
gemspec.files += Dir['vendor/v8/include/**/*.h']
gemspec.files += Dir["vendor/v8/#{target_platform}/**/*.a"]
FileUtils.chmod(0o0644, gemspec.files)
FileUtils.mkdir_p('pkg')
package = if Gem::VERSION < '2.0.0'
Gem::Builder.new(gemspec).build
else
require 'rubygems/package'
Gem::Package.build(gemspec)
end
FileUtils.mv(package, 'pkg')
end