@@ -116,6 +116,20 @@ def delete_rpath(rpath, binary, verbose):
116
116
if verbose :
117
117
print (stdout )
118
118
119
+ def add_rpath (rpath , binary , verbose ):
120
+ cmd = ['install_name_tool' , '-add_rpath' , rpath , binary ]
121
+ if verbose :
122
+ print (' ' .join (cmd ))
123
+ installToolProcess = subprocess .Popen (cmd ,
124
+ stdout = subprocess .PIPE ,
125
+ stderr = subprocess .PIPE )
126
+ stdout , stderr = installToolProcess .communicate ()
127
+ if installToolProcess .returncode != 0 :
128
+ print ('install_name_tool command failed: ' )
129
+ print (stderr )
130
+ if verbose :
131
+ print (stdout )
132
+
119
133
def should_test_parallel ():
120
134
if platform .system () == 'Linux' :
121
135
distro = platform .linux_distribution ()
@@ -209,18 +223,23 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir):
209
223
# Fixup rpaths
210
224
for arch in macos_target_architectures :
211
225
exe_bin_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
212
- 'swift-driver' , 'bin' , exe )
213
- help_bin_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
214
- 'swift-driver' , 'bin' , 'swift-help' )
226
+ 'swift-driver' , 'bin' , exe )
215
227
driver_lib_dir_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
216
228
'swift-driver' , 'lib' )
229
+ tsc_lib_dir_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
230
+ 'swift-tools-support-core' , 'lib' )
217
231
delete_rpath (driver_lib_dir_path , exe_bin_path , args .verbose )
218
- # Only swift-driver requires libllbuild
232
+ delete_rpath (tsc_lib_dir_path , exe_bin_path , args .verbose )
233
+
234
+ # Only swift-driver relies libllbuild
219
235
if exe == 'swift-driver' :
220
236
llbuild_lib_dir_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
221
237
'llbuild' , 'lib' )
222
238
delete_rpath (llbuild_lib_dir_path , exe_bin_path , args .verbose )
223
239
240
+ # Point to the installed toolchain's lib
241
+ add_rpath ('@executable_path/../lib/swift/macosx' , exe_bin_path , args .verbose )
242
+
224
243
# Merge the multiple architecture binaries into a universal binary and install
225
244
output_bin_path = os .path .join (universal_bin_dir , exe )
226
245
lipo_cmd = ['lipo' ]
@@ -234,7 +253,7 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir):
234
253
install_binary (exe , universal_bin_dir , toolchain_bin_dir , args .verbose )
235
254
236
255
def install_libraries (args , build_dir , universal_lib_dir , toolchain_lib_dir ):
237
- # Fixup the rpath for libSwiftDriver (libSwiftOptions does not link against these libraries)
256
+ # Fixup the llbuild and swift-driver rpath for libSwiftDriver
238
257
for arch in macos_target_architectures :
239
258
lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
240
259
'swift-driver' , 'lib' , 'libSwiftDriver' + shared_lib_ext )
@@ -245,18 +264,51 @@ def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir):
245
264
delete_rpath (driver_lib_dir_path , lib_path , args .verbose )
246
265
delete_rpath (llbuild_lib_dir_path , lib_path , args .verbose )
247
266
267
+ # Fixup the TSC rpath for libSwiftDriver and libSwiftOptions
268
+ for lib in ['libSwiftDriver' , 'libSwiftOptions' ]:
269
+ for arch in macos_target_architectures :
270
+ lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
271
+ 'swift-driver' , 'lib' , lib + shared_lib_ext )
272
+ tsc_lib_dir_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
273
+ 'swift-tools-support-core' , 'lib' )
274
+ delete_rpath (tsc_lib_dir_path , lib_path , args .verbose )
275
+
248
276
# Install the libSwiftDriver and libSwiftOptions shared libraries into the toolchain lib
249
277
for lib in ['libSwiftDriver' , 'libSwiftOptions' ]:
250
- dylib_file = lib + shared_lib_ext
251
- output_dylib_path = os .path .join (universal_lib_dir , dylib_file )
278
+ shared_lib_file = lib + shared_lib_ext
279
+ output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
252
280
lipo_cmd = ['lipo' ]
253
281
for arch in macos_target_architectures :
254
282
input_lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
255
- 'swift-driver' , 'lib' , dylib_file )
283
+ 'swift-driver' , 'lib' , shared_lib_file )
256
284
lipo_cmd .append (input_lib_path )
257
285
lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
258
286
subprocess .check_call (lipo_cmd )
259
- install_binary (dylib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
287
+ install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
288
+
289
+ 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 )
300
+
301
+ def install_library (args , lib_name , ):
302
+ shared_lib_file = lib + shared_lib_ext
303
+ output_dylib_path = os .path .join (universal_lib_dir , shared_lib_file )
304
+ lipo_cmd = ['lipo' ]
305
+ for arch in macos_target_architectures :
306
+ input_lib_path = os .path .join (build_dir , arch + '-apple-macos' + macos_deployment_target ,
307
+ 'swift-driver' , 'lib' , shared_lib_file )
308
+ lipo_cmd .append (input_lib_path )
309
+ lipo_cmd .extend (['-create' , '-output' , output_dylib_path ])
310
+ subprocess .check_call (lipo_cmd )
311
+ install_binary (shared_lib_file , universal_lib_dir , toolchain_lib_dir , args .verbose )
260
312
261
313
def install_binary_swift_modules (args , build_dir , toolchain_lib_dir ):
262
314
# The common subpath from a project's build directory to where its build products are found
@@ -343,7 +395,6 @@ def build_llbuild_using_cmake(args, target, swiftc_exec, cmake_target_dir, base_
343
395
mkdir_p (llbuild_api_dir )
344
396
subprocess .check_call (['touch' , os .path .join (llbuild_api_dir , 'codemodel-v2' )])
345
397
flags = [
346
- '-DBUILD_SHARED_LIBS=OFF' ,
347
398
'-DCMAKE_C_COMPILER:=clang' ,
348
399
'-DCMAKE_CXX_COMPILER:=clang++' ,
349
400
'-DCMAKE_CXX_FLAGS=-target %s' % target ,
@@ -363,8 +414,7 @@ def build_tsc_using_cmake(args, target, swiftc_exec, cmake_target_dir, base_cmak
363
414
print ('Building TSC for target: %s' % target )
364
415
tsc_source_dir = os .path .join (os .path .dirname (args .package_path ), 'swift-tools-support-core' )
365
416
tsc_build_dir = os .path .join (cmake_target_dir , 'swift-tools-support-core' )
366
- tsc_flags = base_cmake_flags + ['-DBUILD_SHARED_LIBS=OFF' ]
367
- cmake_build (args , swiftc_exec , tsc_flags , tsc_source_dir , tsc_build_dir )
417
+ cmake_build (args , swiftc_exec , base_cmake_flags , tsc_source_dir , tsc_build_dir )
368
418
369
419
def build_yams_using_cmake (args , target , swiftc_exec , cmake_target_dir , base_cmake_flags ):
370
420
print ('Building Yams for target: %s' % target )
0 commit comments