1717from . import swift
1818from . import wasisysroot
1919from . import wasmkit
20+ from .. import cmake
21+ from .. import shell
2022
2123
2224class WasmStdlib (cmake_product .CMakeProduct ):
@@ -39,11 +41,52 @@ def should_test(self, host_target):
3941 return self .args .test_wasmstdlib
4042
4143 def build (self , host_target ):
42- self ._build (host_target , 'wasm32-wasi' )
44+ self ._build (host_target , 'wasm32-wasi' , 'wasi-wasm32' )
4345
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 ):
4582 self .cmake_options .define ('CMAKE_INSTALL_PREFIX:PATH' , '/usr' )
4683 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.
87+ self .cmake_options .define ('CMAKE_SYSTEM_NAME:STRING' , 'WASI' )
88+ self .cmake_options .define ('CMAKE_SYSTEM_PROCESSOR:STRING' , 'wasm32' )
89+ self .cmake_options .define ('UNIX:BOOL' , 'TRUE' )
4790 self .cmake_options .define (
4891 'SWIFT_STDLIB_BUILD_TYPE:STRING' , self ._build_variant )
4992
@@ -69,9 +112,13 @@ def _build(self, host_target, target_triple):
69112 self .cmake_options .define ('SWIFT_WASI_SYSROOT_PATH:STRING' ,
70113 self ._wasi_sysroot_path (target_triple ))
71114
72- # It's ok to use the host LLVM build dir just for CMake functionalities
73- llvm_cmake_dir = os .path .join (self ._host_llvm_build_dir (
74- 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+
75122 self .cmake_options .define ('LLVM_DIR:PATH' , llvm_cmake_dir )
76123
77124 # Standalone stdlib configuration
@@ -88,6 +135,9 @@ def _build(self, host_target, target_triple):
88135 self .cmake_options .define ('SWIFT_BUILD_STATIC_STDLIB:BOOL' , 'TRUE' )
89136 self .cmake_options .define ('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL' , 'FALSE' )
90137 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' )
91141 self .cmake_options .define ('SWIFT_STDLIB_TRACING:BOOL' , 'FALSE' )
92142 self .cmake_options .define ('SWIFT_STDLIB_HAS_ASLR:BOOL' , 'FALSE' )
93143 self .cmake_options .define ('SWIFT_STDLIB_CONCURRENCY_TRACING:BOOL' , 'FALSE' )
@@ -198,7 +248,7 @@ def get_dependencies(cls):
198248
199249class WasmThreadsStdlib (WasmStdlib ):
200250 def build (self , host_target ):
201- self ._build (host_target , 'wasm32-wasip1-threads' )
251+ self ._build (host_target , 'wasm32-wasip1-threads' , 'wasip1-threads-wasm32' )
202252
203253 def should_test_executable (self ):
204254 # TODO(katei): Enable tests once WasmKit supports WASI threads
0 commit comments