1414import shutil
1515
1616from . import product
17+ from . import swiftpm
1718from .. import shell
1819
1920
@@ -37,7 +38,7 @@ def is_before_build_script_impl_product(cls):
3738
3839 @classmethod
3940 def get_dependencies (cls ):
40- return []
41+ return [swiftpm . SwiftPM ]
4142
4243 def should_build (self , host_target ):
4344 return self .args .build_wasmkit
@@ -47,10 +48,16 @@ def should_test(self, host_target):
4748
4849 def should_install (self , host_target ):
4950 # Currently, it's only used for testing stdlib.
50- return False
51+ return True
5152
5253 def install (self , host_target ):
53- pass
54+ """
55+ Install WasmKit to the target location
56+ """
57+ install_destdir = self .host_install_destdir (host_target )
58+ build_toolchain_path = install_destdir + self .args .install_prefix + '/bin'
59+ bin_path = run_swift_build (host_target , self , 'wasmkit-cli' , set_installation_rpath = True )
60+ shutil .copy (bin_path , build_toolchain_path + '/wasmkit' )
5461
5562 def build (self , host_target ):
5663 bin_path = run_swift_build (host_target , self , 'wasmkit-cli' )
@@ -66,19 +73,27 @@ def cli_file_path(cls, build_dir):
6673 return os .path .join (build_dir , 'bin' , 'wasmkit-cli' )
6774
6875
69- def run_swift_build (host_target , product , swpft_package_product_name ):
70- # Building with the host toolchain's SwiftPM
71- swiftc_path = os .path .abspath (product .toolchain .swiftc )
72- toolchain_path = os .path .dirname (os .path .dirname (swiftc_path ))
73- swift_build = os .path .join (toolchain_path , 'bin' , 'swift-build' )
76+ def run_swift_build (host_target , product , swiftpm_package_product_name , set_installation_rpath = False ):
77+ # Building with the freshly-built SwiftPM
78+ swift_build = os .path .join (product .install_toolchain_path (host_target ), "bin" , "swift-build" )
79+
80+ build_os = host_target .split ('-' )[0 ]
81+ if set_installation_rpath and not host_target .startswith ('macos' ):
82+ # Library rpath for swift, dispatch, Foundation, etc. when installing
83+ rpath_args = [
84+ '--disable-local-rpath' , '-Xswiftc' , '-no-toolchain-stdlib-rpath' ,
85+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/' + build_os
86+ ]
87+ else :
88+ rpath_args = []
7489
7590 build_args = [
7691 swift_build ,
77- '--product' , swpft_package_product_name ,
92+ '--product' , swiftpm_package_product_name ,
7893 '--package-path' , os .path .join (product .source_dir ),
7994 '--build-path' , product .build_dir ,
8095 '--configuration' , 'release' ,
81- ]
96+ ] + rpath_args
8297
8398 if product .args .verbose_build :
8499 build_args .append ('--verbose' )
@@ -90,4 +105,4 @@ def run_swift_build(host_target, product, swpft_package_product_name):
90105
91106 bin_dir_path = shell .capture (
92107 build_args + ['--show-bin-path' ], dry_run = False , echo = False ).rstrip ()
93- return os .path .join (bin_dir_path , swpft_package_product_name )
108+ return os .path .join (bin_dir_path , swiftpm_package_product_name )
0 commit comments