25
25
import sys
26
26
import errno
27
27
28
+ g_macos_deployment_target = '10.10'
29
+
28
30
def note (message ):
29
31
print ("--- %s: note: %s" % (os .path .basename (sys .argv [0 ]), message ))
30
32
sys .stdout .flush ()
@@ -71,6 +73,11 @@ def main():
71
73
""" )
72
74
subparsers = parser .add_subparsers (dest = 'command' )
73
75
76
+ # clean
77
+ parser_clean = subparsers .add_parser ("clean" , help = "cleans build artifacts" )
78
+ parser_clean .set_defaults (func = clean )
79
+ add_global_args (parser_clean )
80
+
74
81
# build
75
82
parser_build = subparsers .add_parser ("build" , help = "builds TSC using CMake" )
76
83
parser_build .set_defaults (func = build )
@@ -120,6 +127,7 @@ def parse_global_args(args):
120
127
"""Parses and cleans arguments necessary for all actions."""
121
128
args .build_dir = os .path .abspath (args .build_dir )
122
129
args .project_root = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
130
+ args .swift_collections_source_dir = os .path .join (args .project_root , ".." , "swift-collections" )
123
131
124
132
if platform .system () == 'Darwin' :
125
133
args .sysroot = call_output (["xcrun" , "--sdk" , "macosx" , "--show-sdk-path" ], verbose = args .verbose )
@@ -133,6 +141,7 @@ def parse_build_args(args):
133
141
args .swiftc_path = get_swiftc_path (args )
134
142
args .cmake_path = get_cmake_path (args )
135
143
args .ninja_path = get_ninja_path (args )
144
+ args .target_dir = os .path .join (args .build_dir , get_build_target (args ))
136
145
137
146
def get_swiftc_path (args ):
138
147
"""Returns the path to the Swift compiler."""
@@ -180,14 +189,38 @@ def get_ninja_path(args):
180
189
else :
181
190
return call_output (["which" , "ninja" ], verbose = args .verbose )
182
191
192
+ def get_build_target (args , cross_compile = False ):
193
+ """Returns the target-triple of the current machine or for cross-compilation."""
194
+ try :
195
+ command = [args .swiftc_path , '-print-target-info' ]
196
+ if cross_compile :
197
+ cross_compile_json = json .load (open (args .cross_compile_config ))
198
+ command += ['-target' , cross_compile_json ["target" ]]
199
+ target_info_json = subprocess .check_output (command ,
200
+ stderr = subprocess .PIPE , universal_newlines = True ).strip ()
201
+ args .target_info = json .loads (target_info_json )
202
+ return args .target_info ["target" ]["unversionedTriple" ]
203
+ except Exception as e :
204
+ # Temporary fallback for Darwin.
205
+ if platform .system () == 'Darwin' :
206
+ return 'x86_64-apple-macosx'
207
+ else :
208
+ error (str (e ))
209
+
183
210
# -----------------------------------------------------------
184
211
# Actions
185
212
# -----------------------------------------------------------
186
213
187
214
def build (args ):
188
215
parse_build_args (args )
216
+ build_swift_collections (args )
189
217
build_tsc (args )
190
218
219
+ def clean (args ):
220
+ parse_global_args (args )
221
+
222
+ call (["rm" , "-rf" , args .build_dir ], verbose = args .verbose )
223
+
191
224
# -----------------------------------------------------------
192
225
# Build functions
193
226
# -----------------------------------------------------------
@@ -222,11 +255,27 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
222
255
223
256
call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
224
257
225
- def build_tsc (args ):
258
+ def build_swift_collections (args ):
259
+ note ("Building swift-collections" )
260
+ args .swift_collections_build_dir = os .path .join (args .target_dir , "swift-collections" )
261
+
226
262
cmake_flags = []
227
263
if platform .system () == 'Darwin' :
228
- cmake_flags .append ("-DCMAKE_C_FLAGS=-target x86_64-apple-macosx10.10" )
229
- cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.10" )
264
+ cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
265
+ cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
266
+
267
+ build_with_cmake (args , cmake_flags , args .swift_collections_source_dir , args .swift_collections_build_dir )
268
+
269
+
270
+ def build_tsc (args ):
271
+ note ("Building TSC" )
272
+
273
+ cmake_flags = [
274
+ "-DSwiftCollections_DIR=" + os .path .join (args .swift_collections_build_dir , "cmake/modules" ),
275
+ ]
276
+ if platform .system () == 'Darwin' :
277
+ cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
278
+ cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
230
279
231
280
build_with_cmake (args , cmake_flags , args .project_root , args .build_dir )
232
281
0 commit comments