@@ -172,7 +172,7 @@ def handle_invocation(toolchain_bin, args):
172
172
elif args .action == 'install' :
173
173
if platform .system () == 'Darwin' :
174
174
distribution_build_dir = os .path .join (args .build_path , 'dist' )
175
- build_for_distribution (args , toolchain_bin , distribution_build_dir )
175
+ build_for_toolchain_install (args , toolchain_bin , distribution_build_dir )
176
176
install (args , distribution_build_dir )
177
177
else :
178
178
bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
@@ -191,7 +191,7 @@ def non_darwin_install(swiftpm_bin_path, toolchain, verbose):
191
191
192
192
def install (args , build_dir ):
193
193
# Construct and install universal swift-driver, swift-help executables
194
- # and libSwiftDriver, libSwiftOptions libraries
194
+ # and libSwiftDriver, libSwiftOptions libraries, along with their dependencies.
195
195
toolchain_bin = os .path .join (args .toolchain , 'bin' )
196
196
toolchain_lib = os .path .join (args .toolchain , 'lib' , 'swift' , 'macosx' )
197
197
toolchain_include = os .path .join (args .toolchain , 'include' , 'swift' )
@@ -210,14 +210,16 @@ def install(args, build_dir):
210
210
211
211
# Binary Swift Modules:
212
212
# swift-driver: SwiftDriver.swiftmodule, SwiftOptions.swiftmodule
213
- # swift-argument-parser: ArgumentParser.swiftmodule
213
+ # TODO: swift-argument-parser: ArgumentParser.swiftmodule
214
214
# swift-tools-support-core: TSCUtility.swiftmodule, TSCLibc.swiftmodule, TSCBasic.swiftmodule
215
215
install_binary_swift_modules (args , build_dir , toolchain_lib )
216
216
217
217
# Modulemaps for C Modules:
218
218
# llbuild, TSCclibc
219
219
install_c_module_includes (args , build_dir , toolchain_include )
220
220
221
+ # Install universal binaries for swift-driver and swift-help into the toolchain bin
222
+ # directory
221
223
def install_executables (args , build_dir , universal_bin_dir , toolchain_bin_dir ):
222
224
for exe in ['swift-driver' , 'swift-help' ]:
223
225
# Fixup rpaths
@@ -252,8 +254,9 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir):
252
254
subprocess .check_call (lipo_cmd )
253
255
install_binary (exe , universal_bin_dir , toolchain_bin_dir , args .verbose )
254
256
257
+ # Install shared libraries for the driver and its dependencies into the toolchain
255
258
def install_libraries (args , build_dir , universal_lib_dir , toolchain_lib_dir ):
256
- # Fixup the llbuild and swift-driver rpath for libSwiftDriver
259
+ # Fixup the llbuild and SwiftDriver rpath for libSwiftDriver
257
260
for arch in macos_target_architectures :
258
261
lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
259
262
'swift-driver' , 'lib' , 'libSwiftDriver' + shared_lib_ext )
@@ -275,41 +278,29 @@ def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir):
275
278
276
279
# Install the libSwiftDriver and libSwiftOptions shared libraries into the toolchain lib
277
280
for lib in ['libSwiftDriver' , 'libSwiftOptions' ]:
278
- shared_lib_file = lib + shared_lib_ext
279
- output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
280
- lipo_cmd = ['lipo' ]
281
- for arch in macos_target_architectures :
282
- input_lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
283
- 'swift-driver' , 'lib' , shared_lib_file )
284
- lipo_cmd .append (input_lib_path )
285
- lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
286
- subprocess .check_call (lipo_cmd )
287
- install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
281
+ install_library (args , build_dir , lib , universal_lib_dir , toolchain_lib_dir , 'swift-driver' )
288
282
283
+ # Instal the swift-tools-support core shared libraries into the toolchain lib
289
284
for lib in ['libTSCBasic' , 'libTSCLibc' , 'libTSCUtility' ]:
290
- shared_lib_file = lib + shared_lib_ext
291
- output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
292
- lipo_cmd = ['lipo' ]
293
- for arch in macos_target_architectures :
294
- input_lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
295
- 'swift-tools-support-core' , 'lib' , shared_lib_file )
296
- lipo_cmd .append (input_lib_path )
297
- lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
298
- subprocess .check_call (lipo_cmd )
299
- install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
285
+ install_library (args , build_dir , lib , universal_lib_dir , toolchain_lib_dir , 'swift-tools-support-core' )
300
286
301
- def install_library (args , lib_name , ):
302
- shared_lib_file = lib + shared_lib_ext
287
+ # TODO: Until the argument parser is used, avoid installing it into the toolchain here
288
+ #install_library(args, build_dir, 'libArgumentParser', universal_lib_dir, toolchain_lib_dir, 'swift-argument-parser')
289
+
290
+ # Create a universal shared-library file and install it into the toolchain lib
291
+ def install_library (args , build_dir , lib_name , universal_lib_dir , toolchain_lib_dir , package_name ):
292
+ shared_lib_file = lib_name + shared_lib_ext
303
293
output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
304
294
lipo_cmd = ['lipo' ]
305
295
for arch in macos_target_architectures :
306
296
input_lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
307
- 'swift-driver' , 'lib' , shared_lib_file )
297
+ package_name , 'lib' , shared_lib_file )
308
298
lipo_cmd .append (input_lib_path )
309
299
lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
310
300
subprocess .check_call (lipo_cmd )
311
301
install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
312
302
303
+ # Install binary .swiftmodule files for the driver and its dependencies into the toolchain lib
313
304
def install_binary_swift_modules (args , build_dir , toolchain_lib_dir ):
314
305
# The common subpath from a project's build directory to where its build products are found
315
306
product_subpath = 'swift'
@@ -318,27 +309,30 @@ def install_binary_swift_modules(args, build_dir, toolchain_lib_dir):
318
309
for module in ['SwiftDriver' , 'SwiftOptions' ]:
319
310
install_module (args , build_dir , product_subpath , toolchain_lib_dir , module , 'swift-driver' )
320
311
321
- # swift-argument-parser
322
- install_module (args , build_dir , product_subpath , toolchain_lib_dir , 'ArgumentParser' , 'swift-argument-parser' )
323
-
324
312
# swift-tools-support-core
325
313
for module in ['TSCUtility' , 'TSCLibc' , 'TSCBasic' ]:
326
314
install_module (args , build_dir , product_subpath , toolchain_lib_dir , module , 'swift-tools-support-core' )
327
315
316
+ # swift-argument-parser
317
+ # TODO: Until the argument parser is used, avoid installing it into the toolchain
318
+ #install_module(args, build_dir, product_subpath, toolchain_lib_dir, 'ArgumentParser', 'swift-argument-parser')
319
+
328
320
# llbuildSwift
329
321
llbuild_product_subpath = os .path .join ('products' , 'llbuildSwift' )
330
322
install_module (args , build_dir , llbuild_product_subpath , toolchain_lib_dir , 'llbuildSwift' , 'llbuild' )
331
323
324
+ # Install the modulemaps and headers of the driver's C module dependencies into the toolchain
325
+ # include directory
332
326
def install_c_module_includes (args , build_dir , toolchain_include_dir ):
333
327
# TSCclibc C module's modulemap and header files
334
328
tscc_include_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-tools-support-core' , 'Sources' ,
335
329
'TSCclibc' , 'include' )
336
- install_module_includes (args , toolchain_include_dir , tscc_include_dir , 'TSCclibc' )
330
+ install_include_artifacts (args , toolchain_include_dir , tscc_include_dir , 'TSCclibc' )
337
331
338
332
# llbuild C module's modulemap and header files
339
333
llbuild_include_dir = os .path .join (os .path .dirname (args .package_path ), 'llbuild' , 'products' ,
340
334
'libllbuild' , 'include' )
341
- install_module_includes (args , toolchain_include_dir , llbuild_include_dir , 'llbuild' )
335
+ install_include_artifacts (args , toolchain_include_dir , llbuild_include_dir , 'llbuild' )
342
336
343
337
def install_module (args , build_dir , product_subpath , toolchain_lib , module_name , source_package ):
344
338
toolchain_module_dir = os .path .join (toolchain_lib , module_name + '.swiftmodule' )
@@ -351,13 +345,14 @@ def install_module(args, build_dir, product_subpath, toolchain_lib, module_name,
351
345
os .rename (os .path .join (toolchain_module_dir , module_name + fileext ),
352
346
os .path .join (toolchain_module_dir , arch + '-apple-macos' + fileext ))
353
347
354
- def install_module_includes (args , toolchain_include_dir , src_include_dir , dst_module_name ):
348
+ # Copy over the contents of a module's include directory contents (modulemap, headers, etc.)
349
+ def install_include_artifacts (args , toolchain_include_dir , src_include_dir , dst_module_name ):
355
350
toolchain_module_include_dir = os .path .join (toolchain_include_dir , dst_module_name )
356
351
if os .path .exists (toolchain_module_include_dir ):
357
352
shutil .rmtree (toolchain_module_include_dir , ignore_errors = True )
358
353
shutil .copytree (src_include_dir , toolchain_module_include_dir )
359
354
360
- def build_for_distribution (args , toolchain_bin , build_dir ):
355
+ def build_for_toolchain_install (args , toolchain_bin , build_dir ):
361
356
print ('Preparing SwiftDriver for distribution using CMake.' )
362
357
swiftc_exec = os .path .join (toolchain_bin , 'swiftc' )
363
358
@@ -427,7 +422,7 @@ def build_argument_parser_using_cmake(args, target, swiftc_exec, cmake_target_di
427
422
print ('Building Argument Parser for target: %s' % target )
428
423
parser_source_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-argument-parser' )
429
424
parser_build_dir = os .path .join (cmake_target_dir , 'swift-argument-parser' )
430
- custom_flags = ['-DBUILD_SHARED_LIBS=OFF' , '- DBUILD_TESTING=NO' , '-DBUILD_EXAMPLES=NO' ]
425
+ custom_flags = ['-DBUILD_TESTING=NO' , '-DBUILD_EXAMPLES=NO' ]
431
426
parser_flags = base_cmake_flags + custom_flags
432
427
cmake_build (args , swiftc_exec , parser_flags , parser_source_dir , parser_build_dir )
433
428
return
0 commit comments