17
17
from . import swift
18
18
from . import wasisysroot
19
19
from . import wasmkit
20
+ from .. import cmake
21
+ from .. import shell
20
22
21
23
22
24
class WasmStdlib (cmake_product .CMakeProduct ):
@@ -39,13 +41,52 @@ def should_test(self, host_target):
39
41
return self .args .test_wasmstdlib
40
42
41
43
def build (self , host_target ):
42
- self ._build (host_target , 'wasm32-wasi' )
44
+ self ._build (host_target , 'wasm32-wasi' , 'wasi-wasm32' )
43
45
44
- def _build (self , host_target , target_triple ):
46
+ def _build (self , host_target , target_triple , short_triple ):
47
+ llvm_build_dir = self ._configure_llvm (target_triple , short_triple )
48
+ llvm_cmake_dir = os .path .join (llvm_build_dir , 'lib' , 'cmake' , 'llvm' )
49
+ self ._build_stdlib (host_target , target_triple , llvm_cmake_dir )
50
+
51
+ def _configure_llvm (self , target_triple , short_triple ):
52
+ # Configure LLVM for WebAssembly target independently
53
+ # from the native LLVM build to turn off zlib and libxml2
54
+ build_root = os .path .dirname (self .build_dir )
55
+ build_dir = os .path .join (
56
+ build_root , 'llvm-%s' % short_triple )
57
+ llvm_source_dir = os .path .join (
58
+ os .path .dirname (self .source_dir ), 'llvm-project' , 'llvm' )
59
+ cmake_options = cmake .CMakeOptions ()
60
+ cmake_options .define ('CMAKE_BUILD_TYPE:STRING' , self ._build_variant )
61
+ # compiler-rt for WebAssembly target is not installed in the host toolchain
62
+ # so skip compiler health checks here.
63
+ cmake_options .define ('CMAKE_C_COMPILER_WORKS:BOOL' , 'TRUE' )
64
+ cmake_options .define ('CMAKE_CXX_COMPILER_WORKS:BOOL' , 'TRUE' )
65
+ cmake_options .define ('LLVM_COMPILER_CHECKED:BOOL' , 'TRUE' )
66
+ cmake_options .define ('LLVM_ENABLE_ZLIB:BOOL' , 'FALSE' )
67
+ cmake_options .define ('LLVM_ENABLE_LIBXML2:BOOL' , 'FALSE' )
68
+ cmake_options .define ('LLVM_ENABLE_LIBEDIT:BOOL' , 'FALSE' )
69
+ cmake_options .define ('LLVM_ENABLE_TERMINFO:BOOL' , 'FALSE' )
70
+
71
+ llvm_cmake = cmake .CMake (
72
+ self .args , self .toolchain , prefer_native_toolchain = True )
73
+ # Only configure LLVM, not build it because we just need
74
+ # LLVM CMake functionalities
75
+ shell .call (["env" , self .toolchain .cmake , "-B" , build_dir ]
76
+ + list (llvm_cmake .common_options (self ))
77
+ + list (cmake_options )
78
+ + [llvm_source_dir ])
79
+ return build_dir
80
+
81
+ def _build_stdlib (self , host_target , target_triple , llvm_cmake_dir ):
45
82
self .cmake_options .define ('CMAKE_INSTALL_PREFIX:PATH' , '/usr' )
46
83
self .cmake_options .define ('CMAKE_BUILD_TYPE:STRING' , self ._build_variant )
84
+ # Teach about the WebAssembly target. UNIX is explicitly set to TRUE
85
+ # as CMake still doesn't recognize WASI as a UNIX platform and the
86
+ # variable is used in LLVM CMake configuration.
47
87
self .cmake_options .define ('CMAKE_SYSTEM_NAME:STRING' , 'WASI' )
48
88
self .cmake_options .define ('CMAKE_SYSTEM_PROCESSOR:STRING' , 'wasm32' )
89
+ self .cmake_options .define ('UNIX:BOOL' , 'TRUE' )
49
90
self .cmake_options .define (
50
91
'SWIFT_STDLIB_BUILD_TYPE:STRING' , self ._build_variant )
51
92
@@ -71,9 +112,13 @@ def _build(self, host_target, target_triple):
71
112
self .cmake_options .define ('SWIFT_WASI_SYSROOT_PATH:STRING' ,
72
113
self ._wasi_sysroot_path (target_triple ))
73
114
74
- # It's ok to use the host LLVM build dir just for CMake functionalities
75
- llvm_cmake_dir = os .path .join (self ._host_llvm_build_dir (
76
- host_target ), 'lib' , 'cmake' , 'llvm' )
115
+ # compiler-rt for WebAssembly target is not installed in the host toolchain
116
+ # so skip compiler health checks here.
117
+ self .cmake_options .define ('CMAKE_C_COMPILER_WORKS:BOOL' , 'TRUE' )
118
+ self .cmake_options .define ('CMAKE_CXX_COMPILER_WORKS:BOOL' , 'TRUE' )
119
+ self .cmake_options .define ('CMAKE_Swift_COMPILER_WORKS:BOOL' , 'TRUE' )
120
+ self .cmake_options .define ('LLVM_COMPILER_CHECKED:BOOL' , 'TRUE' )
121
+
77
122
self .cmake_options .define ('LLVM_DIR:PATH' , llvm_cmake_dir )
78
123
79
124
# Standalone stdlib configuration
@@ -90,6 +135,9 @@ def _build(self, host_target, target_triple):
90
135
self .cmake_options .define ('SWIFT_BUILD_STATIC_STDLIB:BOOL' , 'TRUE' )
91
136
self .cmake_options .define ('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL' , 'FALSE' )
92
137
self .cmake_options .define ('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL' , 'TRUE' )
138
+ # TODO: Turn off library evolution once we establish a good way to teach
139
+ # libraries including swift-testing whether to use the stable ABI.
140
+ self .cmake_options .define ('SWIFT_STDLIB_STABLE_ABI:BOOL' , 'TRUE' )
93
141
self .cmake_options .define ('SWIFT_STDLIB_TRACING:BOOL' , 'FALSE' )
94
142
self .cmake_options .define ('SWIFT_STDLIB_HAS_ASLR:BOOL' , 'FALSE' )
95
143
self .cmake_options .define ('SWIFT_STDLIB_CONCURRENCY_TRACING:BOOL' , 'FALSE' )
@@ -200,7 +248,7 @@ def get_dependencies(cls):
200
248
201
249
class WasmThreadsStdlib (WasmStdlib ):
202
250
def build (self , host_target ):
203
- self ._build (host_target , 'wasm32-wasip1-threads' )
251
+ self ._build (host_target , 'wasm32-wasip1-threads' , 'wasip1-threads-wasm32' )
204
252
205
253
def should_test_executable (self ):
206
254
# TODO(katei): Enable tests once WasmKit supports WASI threads
0 commit comments