14
14
import shutil
15
15
16
16
from . import product
17
+ from . import swiftpm
17
18
from .. import shell
18
19
19
20
@@ -37,7 +38,7 @@ def is_before_build_script_impl_product(cls):
37
38
38
39
@classmethod
39
40
def get_dependencies (cls ):
40
- return []
41
+ return [swiftpm . SwiftPM ]
41
42
42
43
def should_build (self , host_target ):
43
44
return self .args .build_wasmkit
@@ -47,10 +48,16 @@ def should_test(self, host_target):
47
48
48
49
def should_install (self , host_target ):
49
50
# Currently, it's only used for testing stdlib.
50
- return False
51
+ return True
51
52
52
53
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' )
54
61
55
62
def build (self , host_target ):
56
63
bin_path = run_swift_build (host_target , self , 'wasmkit-cli' )
@@ -66,19 +73,27 @@ def cli_file_path(cls, build_dir):
66
73
return os .path .join (build_dir , 'bin' , 'wasmkit-cli' )
67
74
68
75
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 = []
74
89
75
90
build_args = [
76
91
swift_build ,
77
- '--product' , swpft_package_product_name ,
92
+ '--product' , swiftpm_package_product_name ,
78
93
'--package-path' , os .path .join (product .source_dir ),
79
94
'--build-path' , product .build_dir ,
80
95
'--configuration' , 'release' ,
81
- ]
96
+ ] + rpath_args
82
97
83
98
if product .args .verbose_build :
84
99
build_args .append ('--verbose' )
@@ -90,4 +105,4 @@ def run_swift_build(host_target, product, swpft_package_product_name):
90
105
91
106
bin_dir_path = shell .capture (
92
107
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