@@ -40,25 +40,27 @@ from swift_build_support.swift_build_support.SwiftBuildSupport import (
40
40
)
41
41
from swift_build_support .swift_build_support .toolchain import host_toolchain
42
42
43
- isMac = platform .system () == 'Darwin'
43
+ isDarwin = platform .system () == 'Darwin'
44
44
45
45
class Builder (object ):
46
- def __init__ (self , toolchain , args ):
46
+ def __init__ (self , toolchain , args , profile_data = None , arch = None , native_build_dir = None ):
47
47
self .toolchain = toolchain
48
48
self .ninja_path = args .ninja_path
49
49
self .build_release = args .release
50
50
self .enable_assertions = not args .no_assertions
51
51
self .lto_type = args .lto_type
52
52
self .pgo_type = args .pgo_type
53
53
self .profile_input = args .profile_input
54
+ self .profile_data = profile_data
54
55
self .dry_run = args .dry_run
55
56
self .jobs = args .build_jobs
56
57
self .verbose = args .verbose
57
58
self .build_dir = args .build_dir
58
- self .install_symroot = args .install_symroot
59
59
self .install_destdir = args .install_destdir
60
60
self .install_prefix = args .install_prefix
61
61
self .version = args .version
62
+ self .arch = arch
63
+ self .native_build_dir = native_build_dir
62
64
63
65
def call (self , command , env = None , without_sleeping = False ):
64
66
if without_sleeping :
@@ -69,8 +71,25 @@ class Builder(object):
69
71
def configure (self , enable_debuginfo , instrumentation = None , profile_data = None ):
70
72
cmake_args = [self .toolchain .cmake , '-G' , 'Ninja' ]
71
73
cmake_args += ['-DCMAKE_MAKE_PROGRAM=' + self .ninja_path ]
72
- if isMac :
74
+ if isDarwin :
73
75
cmake_args += ['-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12' , '-DSWIFT_DARWIN_DEPLOYMENT_VERSION_OSX=10.12' ]
76
+ if self .arch is not None :
77
+ cmake_args += [
78
+ '-DLLVM_HOST_TRIPLE:STRING=' + self .arch + '-apple-darwin16.0' ,
79
+ '-DSWIFT_HOST_TRIPLE:STRING=' + self .arch + '-apple-darwin16.0' ,
80
+ '-DCMAKE_C_FLAGS=-arch ' + self .arch ,
81
+ '-DCMAKE_CXX_FLAGS=-arch ' + self .arch ,
82
+ '-DSWIFT_HOST_VARIANT_ARCH=' + self .arch ,
83
+ ]
84
+ if self .native_build_dir is not None :
85
+ cmake_args += [
86
+ '-DLLVM_TABLEGEN=' + os .path .join (self .native_build_dir , 'bin' , 'llvm-tblgen' ),
87
+ '-DCLANG_TABLEGEN=' + os .path .join (self .native_build_dir , 'bin' , 'clang-tblgen' ),
88
+ '-DLLVM_NATIVE_BUILD=' + self .native_build_dir ,
89
+ '-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING=' + os .path .join (self .native_build_dir , 'bin' ),
90
+ '-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING=' + os .path .join (self .native_build_dir , 'bin' ),
91
+ '-DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING=' + os .path .join (self .native_build_dir , 'bin' ),
92
+ ]
74
93
else :
75
94
dispatch_source_path = os .path .join (SWIFT_SOURCE_ROOT , 'swift-corelibs-libdispatch' )
76
95
cmake_args += ['-DSWIFT_HOST_VARIANT=linux' , '-DSWIFT_HOST_VARIANT_SDK=LINUX' , '-DSWIFT_HOST_VARIANT_ARCH=x86_64' ,
@@ -123,19 +142,7 @@ class Builder(object):
123
142
env = {'DESTDIR' : self .install_destdir }
124
143
self .build_target (self .build_dir , 'tools/swift/tools/libSwiftSyntaxParser/install' , env = env )
125
144
126
- def extract_symbols (self ):
127
- if not isMac :
128
- return
129
- extract_script = os .path .join (SWIFT_SOURCE_ROOT , "swift" , "utils" , "parser-lib" , "darwin-extract-symbols" )
130
- print ("--- Extracting symbols ---" , file = sys .stderr )
131
- env = {'INSTALL_DIR' : self .install_destdir ,
132
- 'INSTALL_PREFIX' : self .install_prefix ,
133
- 'INSTALL_SYMROOT' : self .install_symroot ,
134
- 'BUILD_JOBS' : str (self .jobs )}
135
- self .call ([extract_script ], env = env )
136
-
137
- def get_profile_data (self ):
138
- profile_dir = os .path .join (self .build_dir , 'profiling' )
145
+ def get_profile_data (self , profile_dir ):
139
146
shell .makedirs (profile_dir , dry_run = self .dry_run )
140
147
instrumentation = 'IR' if self .pgo_type == 'ir' else 'Frontend'
141
148
with shell .pushd (profile_dir , dry_run = self .dry_run ):
@@ -145,24 +152,29 @@ class Builder(object):
145
152
shell .rmtree ("profiles" , dry_run = self .dry_run )
146
153
self .call ([os .path .join ("bin" , "swift-syntax-parser-test" ), self .profile_input , '-time' ])
147
154
self .call ([self .toolchain .llvm_profdata , "merge" , "-output=profdata.prof" , "profiles" ])
148
- return os .path .join (profile_dir , "profdata.prof" )
149
155
150
156
def run (self ):
151
157
shell .makedirs (self .build_dir , dry_run = self .dry_run )
152
158
153
- profile_data = None
154
- if self .pgo_type :
155
- profile_data = self .get_profile_data ()
156
-
157
159
with shell .pushd (self .build_dir , dry_run = self .dry_run ):
158
- self .configure (enable_debuginfo = True , profile_data = profile_data )
160
+ self .configure (enable_debuginfo = True , profile_data = self . profile_data )
159
161
160
162
self .build_target (self .build_dir , 'swift-syntax-parser-test' )
161
163
162
164
if self .install_destdir :
163
165
self .install ()
164
- if self .install_symroot :
165
- self .extract_symbols ()
166
+
167
+
168
+ def extract_symbols (install_destdir , install_prefix , install_symroot , jobs ):
169
+ if not isDarwin :
170
+ return
171
+ extract_script = os .path .join (SWIFT_SOURCE_ROOT , "swift" , "utils" , "parser-lib" , "darwin-extract-symbols" )
172
+ print ("--- Extracting symbols ---" , file = sys .stderr )
173
+ env = {'INSTALL_DIR' : install_destdir ,
174
+ 'INSTALL_PREFIX' : install_prefix ,
175
+ 'INSTALL_SYMROOT' : install_symroot ,
176
+ 'BUILD_JOBS' : str (jobs )}
177
+ shell .call ([extract_script ], env = env )
166
178
167
179
168
180
def main ():
@@ -177,11 +189,12 @@ def main():
177
189
store_path = optbuilder .actions .store_path
178
190
179
191
toolchain = host_toolchain (xcrun_toolchain = 'default' )
192
+ default_architectures = platform .machine ()
180
193
181
194
default_profile_input = os .path .join (SWIFT_SOURCE_ROOT , "swift" , "utils" , "parser-lib" , "profile-input.swift" )
182
195
default_jobs = multiprocessing .cpu_count ()
183
196
default_build_dir = os .path .join (SWIFT_BUILD_ROOT , 'parser-lib' )
184
- default_install_prefix = defaults .DARWIN_INSTALL_PREFIX if isMac else UNIX_INSTALL_PREFIX
197
+ default_install_prefix = defaults .DARWIN_INSTALL_PREFIX if isDarwin else UNIX_INSTALL_PREFIX
185
198
default_ninja = toolchain .ninja
186
199
187
200
option ('--release' , store_true ,
@@ -215,6 +228,9 @@ def main():
215
228
option ('--build-dir' , store_path ,
216
229
default = default_build_dir ,
217
230
help = 'the path where the build products will be placed. (default = %s)' % default_build_dir )
231
+ option ('--architectures' , store ,
232
+ default = default_architectures ,
233
+ help = 'space-separated list of architectures to build for. (default = %s)' % default_architectures )
218
234
option ('--install-symroot' , store_path ,
219
235
help = 'the path to install debug symbols into' )
220
236
option ('--install-destdir' , store_path ,
@@ -231,6 +247,46 @@ def main():
231
247
parser = optbuilder .build ()
232
248
args = parser .parse_args ()
233
249
250
+ if isDarwin :
251
+ architectures = args .architectures .split (" " )
252
+ architectures = [arch for arch in architectures if arch != platform .machine () and arch != "" ]
253
+ if platform .machine () in architectures : architectures = [platform .machine ()] + architectures
254
+ architectures = [platform .machine ()] + architectures
255
+
256
+ objroot = args .build_dir
257
+ dstroot = args .install_destdir
258
+ symroot = args .install_symroot
259
+ prefix = args .install_prefix
260
+
261
+ for arch in architectures :
262
+ native = platform .machine () == arch
263
+
264
+ args .build_dir = os .path .join (objroot , arch , "obj" )
265
+ args .install_destdir = os .path .join (objroot , arch , "dst" )
266
+ args .install_prefix = "/"
267
+
268
+ native_build_dir = None if native else os .path .join (objroot , platform .machine (), "obj" )
269
+
270
+ profile_data = None
271
+ if args .pgo_type :
272
+ profile_dir = os .path .join (objroot , platform .machine ()+ '-profiling' )
273
+ if native :
274
+ builder = Builder (toolchain , args )
275
+ builder .get_profile_data (profile_dir )
276
+ profile_data = os .path .join (profile_dir , "profdata.prof" )
277
+
278
+ builder = Builder (toolchain , args , profile_data = profile_data , arch = arch , native_build_dir = native_build_dir )
279
+ builder .run ()
280
+
281
+ lipo = os .path .join (SWIFT_SOURCE_ROOT , "swift" , "utils" , "recursive-lipo" )
282
+ dst_dirs = [os .path .join (objroot , arch , "dst" ) for arch in architectures ]
283
+ shell .call ([lipo , "-v" , "--destination" , os .path .join (dstroot , "./" + prefix )] + dst_dirs )
284
+
285
+ if args .install_symroot :
286
+ extract_symbols (dstroot , prefix , symroot , args .build_jobs )
287
+
288
+ return 0
289
+
234
290
builder = Builder (toolchain , args )
235
291
builder .run ()
236
292
return 0
0 commit comments