@@ -249,6 +249,20 @@ def install_swiftdriver(args, build_dir, prefix, targets) :
249
249
# swift-driver and swift-help
250
250
install_executables (args , build_dir , bin_dir , install_bin , targets )
251
251
252
+ # libSwiftDriver and libSwiftDriverExecution and libSwiftOptions
253
+ install_libraries (args , build_dir , lib_dir , install_lib , targets )
254
+
255
+ # Binary Swift Modules:
256
+ # swift-driver: SwiftDriver.swiftmodule, SwiftOptions.swiftmodule
257
+ # swift-tools-support-core: TSCUtility.swiftmodule, TSCLibc.swiftmodule, TSCBasic.swiftmodule
258
+ # swift-argument-parser: ArgumentParser.swiftmodule (disabled until needed)
259
+ # swift-system: SystemPackage.swiftmodule
260
+ install_binary_swift_modules (args , build_dir , install_lib , targets )
261
+
262
+ # Modulemaps for C Modules:
263
+ # TSCclibc
264
+ install_c_module_includes (args , build_dir , install_include )
265
+
252
266
# Install universal binaries for swift-driver and swift-help into the toolchain bin
253
267
# directory
254
268
def install_executables (args , build_dir , universal_bin_dir , toolchain_bin_dir , targets ):
@@ -257,6 +271,16 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir, t
257
271
for target in targets :
258
272
exe_bin_path = os .path .join (build_dir , target ,
259
273
args .configuration , 'bin' , exe )
274
+ driver_lib_dir_path = os .path .join (build_dir , target ,
275
+ args .configuration , 'lib' )
276
+ delete_rpath (driver_lib_dir_path , exe_bin_path , args .verbose )
277
+
278
+ for lib in ['swift-tools-support-core' , 'swift-argument-parser' ]:
279
+ lib_dir_path = os .path .join (build_dir , target ,
280
+ args .configuration , 'dependencies' ,
281
+ lib , 'lib' )
282
+ delete_rpath (lib_dir_path , exe_bin_path , args .verbose )
283
+
260
284
# Point to the installation toolchain's lib directory
261
285
add_rpath ('@executable_path/../lib/swift/macosx' , exe_bin_path , args .verbose )
262
286
@@ -272,6 +296,128 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir, t
272
296
subprocess .check_call (lipo_cmd )
273
297
install_binary (exe , universal_bin_dir , toolchain_bin_dir , args .verbose )
274
298
299
+ # Install shared libraries for the driver and its dependencies into the toolchain
300
+ def install_libraries (args , build_dir , universal_lib_dir , toolchain_lib_dir , targets ):
301
+ # Fixup the SwiftDriver rpath for libSwiftDriver and libSwiftDriverExecution
302
+ for lib in ['libSwiftDriver' , 'libSwiftDriverExecution' ]:
303
+ for target in targets :
304
+ lib_path = os .path .join (build_dir , target ,
305
+ args .configuration , 'lib' , lib + shared_lib_ext )
306
+ driver_lib_dir_path = os .path .join (build_dir , target ,
307
+ args .configuration , 'lib' )
308
+ delete_rpath (driver_lib_dir_path , lib_path , args .verbose )
309
+
310
+ # Fixup the TSC and llbuild rpaths
311
+ driver_libs = map (lambda d : os .path .join ('lib' , d ), ['libSwiftDriver' , 'libSwiftOptions' , 'libSwiftDriverExecution' ])
312
+ tsc_libs = map (lambda d : os .path .join ('dependencies' , 'swift-tools-support-core' , 'lib' , d ),
313
+ ['libTSCBasic' , 'libTSCLibc' , 'libTSCUtility' ])
314
+ for lib in driver_libs + tsc_libs :
315
+ for target in targets :
316
+ lib_path = os .path .join (build_dir , target ,
317
+ args .configuration , lib + shared_lib_ext )
318
+ for dep in ['swift-tools-support-core' , 'llbuild' ]:
319
+ lib_dir_path = os .path .join (build_dir , target ,
320
+ args .configuration , 'dependencies' ,
321
+ dep , 'lib' )
322
+ delete_rpath (lib_dir_path , lib_path , args .verbose )
323
+
324
+ # Install the libSwiftDriver and libSwiftOptions and libSwiftDriverExecution
325
+ # shared libraries into the toolchain lib
326
+ package_subpath = args .configuration
327
+ for lib in ['libSwiftDriver' , 'libSwiftOptions' , 'libSwiftDriverExecution' ]:
328
+ install_library (args , build_dir , package_subpath , lib ,
329
+ universal_lib_dir , toolchain_lib_dir , 'swift-driver' , targets )
330
+
331
+ # Install the swift-tools-support core shared libraries into the toolchain lib
332
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-tools-support-core' )
333
+ for lib in ['libTSCBasic' , 'libTSCLibc' , 'libTSCUtility' ]:
334
+ install_library (args , build_dir , package_subpath , lib ,
335
+ universal_lib_dir , toolchain_lib_dir , 'swift-tools-support-core' , targets )
336
+
337
+ # Install the swift-system shared library into the toolchain lib
338
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-system' )
339
+ install_library (args , build_dir , package_subpath , 'libSystemPackage' ,
340
+ universal_lib_dir , toolchain_lib_dir , 'swift-system' , targets )
341
+
342
+ # Install the swift-argument-parser shared libraries into the toolchain lib
343
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-argument-parser' )
344
+ for lib in ['libArgumentParser' , 'libArgumentParserToolInfo' ]:
345
+ install_library (args , build_dir , package_subpath , lib ,
346
+ universal_lib_dir , toolchain_lib_dir ,'swift-argument-parser' , targets )
347
+
348
+ # Install the llbuild core shared libraries into the toolchain lib
349
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'llbuild' )
350
+ for lib in ['libllbuildSwift' , 'libllbuild' ]:
351
+ install_library (args , build_dir , package_subpath , lib ,
352
+ universal_lib_dir , toolchain_lib_dir ,'llbuild' , targets )
353
+
354
+ # Create a universal shared-library file and install it into the toolchain lib
355
+ def install_library (args , build_dir , package_subpath , lib_name ,
356
+ universal_lib_dir , toolchain_lib_dir , package_name , targets ):
357
+ shared_lib_file = lib_name + shared_lib_ext
358
+ output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
359
+ lipo_cmd = ['lipo' ]
360
+ for target in targets :
361
+ input_lib_path = os .path .join (build_dir , target ,
362
+ package_subpath , 'lib' , shared_lib_file )
363
+ lipo_cmd .append (input_lib_path )
364
+ lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
365
+ subprocess .check_call (lipo_cmd )
366
+ install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
367
+
368
+ # Install binary .swiftmodule files for the driver and its dependencies into the toolchain lib
369
+ def install_binary_swift_modules (args , build_dir , toolchain_lib_dir , targets ):
370
+ # The common subpath from a project's build directory to where its build products are found
371
+ product_subpath = 'swift'
372
+
373
+ # swift-driver
374
+ package_subpath = os .path .join (args .configuration , product_subpath )
375
+ for module in ['SwiftDriver' , 'SwiftOptions' ]:
376
+ install_module (args , build_dir , package_subpath , toolchain_lib_dir , module , targets )
377
+
378
+ # swift-tools-support-core
379
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-tools-support-core' ,
380
+ product_subpath )
381
+ for module in ['TSCUtility' , 'TSCLibc' , 'TSCBasic' ]:
382
+ install_module (args , build_dir , package_subpath , toolchain_lib_dir , module , targets )
383
+
384
+ # swift-argument-parser
385
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-argument-parser' ,
386
+ product_subpath )
387
+ install_module (args , build_dir , package_subpath , toolchain_lib_dir , 'ArgumentParser' , targets )
388
+
389
+ # swift-system
390
+ package_subpath = os .path .join (args .configuration , 'dependencies' , 'swift-system' ,
391
+ product_subpath )
392
+ install_module (args , build_dir , package_subpath , toolchain_lib_dir , 'SystemPackage' , targets )
393
+
394
+
395
+ # Install the modulemaps and headers of the driver's C module dependencies into the toolchain
396
+ # include directory
397
+ def install_c_module_includes (args , build_dir , toolchain_include_dir ):
398
+ # TSCclibc C module's modulemap and header files
399
+ tscc_include_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-tools-support-core' , 'Sources' ,
400
+ 'TSCclibc' , 'include' )
401
+ install_include_artifacts (args , toolchain_include_dir , tscc_include_dir , 'TSCclibc' )
402
+
403
+ def install_module (args , build_dir , package_subpath , toolchain_lib , module_name , targets ):
404
+ toolchain_module_dir = os .path .join (toolchain_lib , module_name + '.swiftmodule' )
405
+ mkdir_p (toolchain_module_dir )
406
+ for target in targets :
407
+ swift_dir = os .path .join (build_dir , target ,
408
+ package_subpath )
409
+ for fileext in ['.swiftmodule' , '.swiftdoc' ]:
410
+ install_binary (module_name + fileext , swift_dir , toolchain_module_dir , args .verbose )
411
+ os .rename (os .path .join (toolchain_module_dir , module_name + fileext ),
412
+ os .path .join (toolchain_module_dir , target + fileext ))
413
+
414
+ # Copy over the contents of a module's include directory contents (modulemap, headers, etc.)
415
+ def install_include_artifacts (args , toolchain_include_dir , src_include_dir , dst_module_name ):
416
+ toolchain_module_include_dir = os .path .join (toolchain_include_dir , dst_module_name )
417
+ if os .path .exists (toolchain_module_include_dir ):
418
+ shutil .rmtree (toolchain_module_include_dir , ignore_errors = True )
419
+ shutil .copytree (src_include_dir , toolchain_module_include_dir )
420
+
275
421
def build_using_cmake (args , toolchain_bin , build_dir , targets ):
276
422
swiftc_exec = os .path .join (toolchain_bin , 'swiftc' )
277
423
swift_flags = []
@@ -329,8 +475,7 @@ def build_llbuild_using_cmake(args, target, swiftc_exec, build_dir, base_cmake_f
329
475
'-DCMAKE_C_COMPILER:=clang' ,
330
476
'-DCMAKE_CXX_COMPILER:=clang++' ,
331
477
'-DCMAKE_CXX_FLAGS=-target %s' % target ,
332
- '-DLLBUILD_SUPPORT_BINDINGS=Swift' ,
333
- '-DBUILD_SHARED_LIBS=NO'
478
+ '-DLLBUILD_SUPPORT_BINDINGS:=Swift'
334
479
]
335
480
if platform .system () == 'Darwin' :
336
481
flags .append ('-DCMAKE_OSX_ARCHITECTURES=%s' % target .split ('-' )[0 ])
@@ -351,7 +496,9 @@ def build_system_using_cmake(args, target, swiftc_exec, build_dir, base_cmake_fl
351
496
print ('Building Swift Driver dependency: Swift System' )
352
497
system_source_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-system' )
353
498
system_build_dir = os .path .join (build_dir , 'swift-system' )
354
- flags = ['-DBUILD_SHARED_LIBS=NO' ]
499
+ flags = [
500
+ # requried due to swift-autolink-extract bug ("The file was not recognized as a valid object file")
501
+ "-DBUILD_SHARED_LIBS=YES" ]
355
502
system_cmake_flags = base_cmake_flags + flags
356
503
system_swift_flags = swift_flags [:]
357
504
cmake_build (args , swiftc_exec , system_cmake_flags , system_swift_flags ,
@@ -362,8 +509,7 @@ def build_tsc_using_cmake(args, target, swiftc_exec, build_dir, base_cmake_flags
362
509
tsc_source_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-tools-support-core' )
363
510
tsc_build_dir = os .path .join (build_dir , 'swift-tools-support-core' )
364
511
flags = [
365
- '-DSwiftSystem_DIR=' + os .path .join (os .path .join (build_dir , 'swift-system' ), 'cmake/modules' ),
366
- '-DBUILD_SHARED_LIBS=NO' ]
512
+ '-DSwiftSystem_DIR=' + os .path .join (os .path .join (build_dir , 'swift-system' ), 'cmake/modules' )]
367
513
tsc_cmake_flags = base_cmake_flags + flags
368
514
369
515
tsc_swift_flags = swift_flags [:]
@@ -376,7 +522,7 @@ def build_yams_using_cmake(args, target, swiftc_exec, build_dir, base_cmake_flag
376
522
yams_build_dir = os .path .join (build_dir , 'yams' )
377
523
yams_cmake_flags = base_cmake_flags + [
378
524
'-DCMAKE_C_COMPILER:=clang' ,
379
- '-DBUILD_SHARED_LIBS=NO ' ]
525
+ '-DBUILD_SHARED_LIBS=OFF ' ]
380
526
381
527
if platform .system () == 'Darwin' :
382
528
yams_cmake_flags .append ('-DCMAKE_OSX_DEPLOYMENT_TARGET=%s' % macos_deployment_target )
@@ -393,8 +539,7 @@ def build_argument_parser_using_cmake(args, target, swiftc_exec, build_dir, base
393
539
print ('Building Swift Driver dependency: Argument Parser' )
394
540
parser_source_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-argument-parser' )
395
541
parser_build_dir = os .path .join (build_dir , 'swift-argument-parser' )
396
- custom_flags = ['-DBUILD_TESTING=NO' , '-DBUILD_EXAMPLES=NO' ,
397
- '-DBUILD_SHARED_LIBS=NO' ]
542
+ custom_flags = ['-DBUILD_TESTING=NO' , '-DBUILD_EXAMPLES=NO' ]
398
543
parser_cmake_flags = base_cmake_flags + custom_flags
399
544
parser_swift_flags = swift_flags [:]
400
545
cmake_build (args , swiftc_exec , parser_cmake_flags , parser_swift_flags ,
@@ -409,7 +554,6 @@ def build_swift_driver_using_cmake(args, target, swiftc_exec, build_dir, base_cm
409
554
# TODO: Enable Library Evolution
410
555
driver_swift_flags = swift_flags [:]
411
556
flags = [
412
- '-DBUILD_SHARED_LIBS=NO' ,
413
557
'-DLLBuild_DIR=' + os .path .join (os .path .join (dependencies_dir , 'llbuild' ), 'cmake/modules' ),
414
558
'-DTSC_DIR=' + os .path .join (os .path .join (dependencies_dir , 'swift-tools-support-core' ), 'cmake/modules' ),
415
559
'-DYams_DIR=' + os .path .join (os .path .join (dependencies_dir , 'yams' ), 'cmake/modules' ),
0 commit comments