-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_config.rb
224 lines (176 loc) · 6.1 KB
/
build_config.rb
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
SSC_PLATFORM_TARGET = ENV['SSC_PLATFORM_TARGET']
ANDROID_HOME = ENV['ANDROID_HOME']
ANDROID_PLATFORM = "33"
ANDROID_NDK_VERSION = "25.0.8775105"
ANDROID_NDK = "#{ANDROID_HOME}/ndk/#{ANDROID_NDK_VERSION}"
ANDROID_NDK_BUILD = "#{ANDROID_NDK}/ndk-build"
HOST = %x[uname -s].strip.downcase
ARCH = %x[uname -m].strip.downcase
SOCKET_HOME = /SOCKET_HOME=(.*)/.match(%x[ssc env])[1].strip.gsub(/\/$/, '')
SOCKET_HOME_INCLUDE = "#{SOCKET_HOME}/include"
SOCKET_RUBY_GEMBOX = 'full-core'
CFLAGS = ENV['CFLAGS']
LDFLAGS = ENV['LDFLAGS']
def configure (conf, arch = ARCH, platform = 'desktop')
conf.bins = []
conf.disable_presym
cflags = []
ldflags = []
cflags << "-I#{SOCKET_HOME_INCLUDE}"
cflags << "-I#{SOCKET_HOME}"
ldflags << "-undefined dynamic_lookup"
ldflags << "-L#{SOCKET_HOME}/lib/#{arch}-#{platform}"
ldflags << "-lsocket-runtime"
if not CFLAGS.nil? and not CFLAGS.empty?
cflags << CFLAGS
end
if not LDFLAGS.nil? and not LDFLAGS.empty?
ldflags << LDFLAGS
end
puts cflags
case platform
when 'desktop'
if RUBY_PLATFORM =~ /darwin/i
cflags << '-Ibuild/mac/include'
elsif RUBY_PLATFORM =~ /linux/i
cflags << '-Ibuild/linux/include'
elsif RUBY_PLATFORM =~ /win/i
cflags << '-Ibuild/win/include'
end
when 'iPhoneOS'
cflags << '-Ibuild/ios/include'
when 'iPhoneSimulator'
cflags << '-Ibuild/ios-simulator/include'
end
if RUBY_PLATFORM =~ /darwin/i
if platform =~ /iphone|desktop/i
conf.cc.flags << '-ObjC'
conf.cxx.flags << '-std=c++2a -fvisibility=hidden -ObjC++'
ldflags << '-framework Foundation,Security,CoreFoundation,CoreBluetooth,ObjC'
end
end
puts ldflags
conf.cc.flags << cflags
conf.cxx.flags << cflags
conf.linker.flags << ldflags
if ENV['OS'] != 'Windows_NT' then
# needed for using bundled gems
conf.cc.flags << %w|-fPIC|
conf.cxx.flags << %w|-fPIC| # needed for using bundled gems
end
# enable full core library
conf.gembox 'full-core'
# socket runtime
conf.gem 'mrbgems/socket-runtime'
# user space
conf.gem :github => 'mattn/mruby-json'
# MUST be last
conf.gem :github => 'mattn/mruby-require'
end
if SSC_PLATFORM_TARGET == 'ios'
MRuby::CrossBuild.new('ios') do |conf|
sdk = %x[xcrun -sdk iphoneos -show-sdk-path].strip
cflags = []
ldflags = []
cflags << "-isysroot #{sdk}"
cflags << '-iframeworkwithsysroot /System/Library/Frameworks/'
cflags << '-arch arm64'
cflags << '-fembed-bitcode'
cflags << '-D_XOPEN_SOURCE'
cflags << "-miphoneos-version-min=#{ENV.fetch('IPHONEOS_VERSION_MIN', '14.0')}"
ldflags << "-isysroot #{sdk}"
ldflags << '-arch arm64'
ldflags << "-miphoneos-version-min=#{ENV.fetch('IPHONEOS_VERSION_MIN', '14.0')}"
# commands
conf.cc.command = 'xcrun -sdk iphoneos clang'
conf.cxx.command = 'xcrun -sdk iphoneos clang++'
conf.linker.command = 'xcrun -sdk iphoneos clang'
# flags
conf.cc.flags << cflags
conf.cxx.flags << cflags
conf.linker.flags << ldflags
configure(conf, 'arm64', 'iPhoneOS')
end
elsif SSC_PLATFORM_TARGET == 'ios-simulator'
MRuby::CrossBuild.new('ios-simulator') do |conf|
sdk = %x[xcrun -sdk iphonesimulator -show-sdk-path].strip
cflags = []
ldflags = []
cflags << "-isysroot #{sdk}"
cflags << '-iframeworkwithsysroot /System/Library/Frameworks/'
cflags << "-arch #{ARCH} -target #{ARCH}-apple-ios-simulator"
cflags << '-fembed-bitcode'
cflags << '-D_XOPEN_SOURCE'
cflags << "-mios-simulator-version-min=#{ENV.fetch('IPHONEOS_VERSION_MIN', '14.0')}"
ldflags << "-isysroot #{sdk}"
ldflags << "-arch #{ARCH} -target #{ARCH}-apple-ios-simulator"
ldflags << "-mios-simulator-version-min=#{ENV.fetch('IPHONEOS_VERSION_MIN', '14.0')}"
# commands
conf.cc.command = 'xcrun -sdk iphonesimulator clang'
conf.cxx.command = 'xcrun -sdk iphonesimulator clang++'
conf.linker.command = 'xcrun -sdk iphonesimulator clang'
# flags
conf.cc.flags << cflags
conf.cxx.flags << cflags
conf.linker.flags << ldflags
configure(conf, ARCH, 'iPhoneSimulator')
end
elsif SSC_PLATFORM_TARGET == 'android' or SSC_PLATFORM_TARGET == 'android-emulator'
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
case RUBY_PLATFORM
when /darwin/i
RUBY_PLATFORM = 'x86_64-darwin'
sdk = "#{ANDROID_HOME}/ndk/#{ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/#{HOST}-x86_64"
else
sdk = "#{ANDROID_HOME}/ndk/#{ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/#{HOST}-#{ARCH}"
end
params = { :arch => 'arm64-v8a', :sdk_version => 33, :toolchain => :clang }
cflags = []
ldflags = []
toolchain :android, params
cflags << "--sysroot=#{sdk}/sysroot"
ldflags << "--sysroot=#{sdk}/sysroot"
# commands
conf.cc.command = "#{sdk}/bin/clang"
conf.cxx.command = "#{sdk}/bin/clang++"
conf.linker.command = "#{sdk}/bin/clang"
# flags
conf.cc.flags << cflags
conf.cxx.flags << cflags
conf.linker.flags << ldflags
configure(conf, 'arm64-v8a', 'android')
end
MRuby::CrossBuild.new('android-x86_64') do |conf|
case RUBY_PLATFORM
when /darwin/i
RUBY_PLATFORM = 'x86_64-darwin'
sdk = "#{ANDROID_HOME}/ndk/#{ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/#{HOST}-x86_64"
else
sdk = "#{ANDROID_HOME}/ndk/#{ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/#{HOST}-#{ARCH}"
end
params = { :arch => 'x86_64', :sdk_version => 33, :toolchain => :clang }
cflags = []
ldflags = []
toolchain :android, params
ccflags << "--sysroot=#{sdk}/sysroot"
ldflags << "--sysroot=#{sdk}/sysroot"
conf.cc.command = "#{sdk}/bin/clang"
conf.cxx.command = "#{sdk}/bin/clang++"
conf.linker.command = "#{sdk}/bin/clang"
conf.cc.flags << cflags
conf.cxx.flags << cflags
conf.linker.flags << cflags
configure(conf, 'x86_64', 'android')
end
else
MRuby::Build.new do |conf|
#toolchain ENV.fetch('TOOLCHAIN', :clang)
conf.cc.command = "clang"
conf.cxx.command = "clang++"
conf.linker.command = "clang"
conf.toolchain
conf.enable_bintest
conf.enable_test
configure(conf, ARCH, 'desktop')
end
end