-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
89 lines (77 loc) · 3.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
RVM_RUBY = "ruby-3.0.0"
INTERNAL_VERSION = "3.0.0"
RUBY_DYLIB = "libruby.3.0.dylib"
RUBY_DYLIB_ID = "@executable_path/../Frameworks/#{RUBY_DYLIB}"
TARGET_ROOT = "UniversalRuby"
SOURCE_ROOT = "#{ENV["HOME"]}/.rvm/rubies/#{RVM_RUBY}"
GEM_ROOT = "#{ENV["HOME"]}/.rvm/gems/#{RVM_RUBY}/gems"
LIB_KILLLIST = %w(README irb rake* rdoc* *ubygems* readline* tcltk* tk* tcltklib* rss* *-darwin*)
GEMS = %w(gosu chipmunk opengl msgpack)
GEMS_WITH_FLAGS = "#{GEMS.join(" ")}"
CURRENT_PLATFORM = `uname -m`.chomp
def merge_lib(source_file, target_file)
sh "install_name_tool -change #{SOURCE_ROOT}/lib/#{RUBY_DYLIB} #{RUBY_DYLIB_ID} #{source_file}"
if File.exist? target_file
sh "lipo #{source_file} #{target_file} -create -output #{target_file}"
else
sh "cp #{source_file} #{target_file}"
end
end
task :rebuild_ruby_for_current_platform do
mkdir_p "#{TARGET_ROOT}/include"
mkdir_p "#{TARGET_ROOT}/lib"
# Let RVM install the correct Ruby
sh "env RVM_RUBY=#{RVM_RUBY} RVM_GEMS='#{GEMS_WITH_FLAGS}' " +
" bash #{TARGET_ROOT}/install_rvm_ruby_#{CURRENT_PLATFORM}.sh"
end
task :merge_current_platform_into_universal_ruby => :rebuild_ruby_for_current_platform do
# Copy headers
sh "cp -R #{SOURCE_ROOT}/include/ruby*/* #{TARGET_ROOT}/include/"
# Copy rbconfig
sh "cp #{TARGET_ROOT}/rbconfig.rb #{TARGET_ROOT}/lib/rbconfig.rb"
# Rename platform-specific folder so the Xcode project will find it
sh "mv #{TARGET_ROOT}/include/*-darwin* #{TARGET_ROOT}/include/#{CURRENT_PLATFORM}"
# Copy Ruby libraries
sh "cp -R #{SOURCE_ROOT}/lib/ruby/#{INTERNAL_VERSION}/* #{TARGET_ROOT}/lib"
# Merge libruby with existing platforms
# (This will bork the Ruby installation in rvm. No issue, we'll throw it away anyway.)
source_file = "#{SOURCE_ROOT}/lib/#{RUBY_DYLIB}"
target_file = "#{TARGET_ROOT}/#{RUBY_DYLIB}"
sh "install_name_tool -id #{RUBY_DYLIB_ID} #{source_file}"
merge_lib source_file, target_file
# Merge binary libraries
Dir["#{SOURCE_ROOT}/lib/ruby/#{INTERNAL_VERSION}/*-darwin*/**/*.bundle"].each do |source_file|
target_file = source_file.dup
target_file["#{SOURCE_ROOT}/lib/ruby/#{INTERNAL_VERSION}/"] = ""
target_file[/^[^\/]*\//] = ""
target_file = "#{TARGET_ROOT}/lib/#{target_file}"
mkdir_p File.dirname(target_file)
merge_lib source_file, target_file
end
# Merge gems
GEMS.each do |gem_name|
gem_name = gem_name.split(" ").first # strip --pre flag
gem_lib = Dir["#{GEM_ROOT}/#{gem_name}-*/lib"].last
Dir["#{gem_lib}/**/*.{rb,frag}"].each do |ruby_file|
target_file = ruby_file.dup
target_file[gem_lib] = "#{TARGET_ROOT}/lib"
mkdir_p File.dirname(target_file)
sh "cp #{ruby_file} #{target_file}"
end
Dir["#{gem_lib}/**/*.bundle"].each do |ext_file|
target_file = ext_file.dup
target_file[gem_lib] = "#{TARGET_ROOT}/lib"
mkdir_p File.dirname(target_file)
merge_lib ext_file, target_file
end
end
LIB_KILLLIST.each do |item|
sh "rm -rf #{TARGET_ROOT}/lib/#{item}"
end
end
task :default => :merge_current_platform_into_universal_ruby
task :clean do
sh "rm -rf #{TARGET_ROOT}/#{RUBY_DYLIB}"
sh "rm -rf #{TARGET_ROOT}/lib/*"
sh "rm -rf #{TARGET_ROOT}/include/*"
end