@@ -81,7 +81,7 @@ def _append_platform_cmake_options(self, cmake_options, swift_host_triple, has_p
81
81
cmake_options .define ('CMAKE_RANLIB' , os .path .join (
82
82
native_toolchain_path , 'bin' , 'llvm-ranlib' ))
83
83
84
- def _build_libxml2 (self , swift_host_triple , has_pthread , wasi_sysroot ):
84
+ def _build_libxml2 (self , swift_host_triple , clang_multiarch_triple , has_pthread , wasi_sysroot ):
85
85
libxml2 = CMakeProduct (
86
86
args = self .args ,
87
87
toolchain = self .toolchain ,
@@ -124,6 +124,10 @@ def _build_libxml2(self, swift_host_triple, has_pthread, wasi_sysroot):
124
124
libxml2 .cmake_options .define ('LIBXML2_WITH_XPTR' , 'FALSE' )
125
125
libxml2 .cmake_options .define ('LIBXML2_WITH_ZLIB' , 'FALSE' )
126
126
libxml2 .cmake_options .define ('BUILD_SHARED_LIBS' , 'FALSE' )
127
+ # Install libxml2.a under <sysroot>/lib/<clang_multiarch_triple>
128
+ # because Clang driver only passes arch-specific library paths as
129
+ # search paths to the linker for WebAssembly targets.
130
+ libxml2 .cmake_options .define ('CMAKE_INSTALL_LIBDIR' , f'lib/{ clang_multiarch_triple } ' )
127
131
128
132
cmake_thread_enabled = 'TRUE' if has_pthread else 'FALSE'
129
133
libxml2 .cmake_options .define ('LIBXML2_WITH_THREAD_ALLOC' , cmake_thread_enabled )
@@ -137,7 +141,7 @@ def _build_libxml2(self, swift_host_triple, has_pthread, wasi_sysroot):
137
141
shell .call ([self .toolchain .cmake , '--install' , '.' , '--prefix' , '/' , '--component' , 'development' ],
138
142
env = {'DESTDIR' : wasi_sysroot })
139
143
140
- def _build_foundation (self , swift_host_triple , has_pthread , wasi_sysroot ):
144
+ def _build_foundation (self , swift_host_triple , clang_multiarch_triple , has_pthread , wasi_sysroot ):
141
145
source_root = os .path .dirname (self .source_dir )
142
146
host_toolchain = self .native_toolchain_path (self .args .host_target )
143
147
@@ -155,9 +159,13 @@ def _build_foundation(self, swift_host_triple, has_pthread, wasi_sysroot):
155
159
foundation .cmake_options .define ('_SwiftFoundation_SourceDIR' , os .path .join (source_root , 'swift-foundation' ))
156
160
foundation .cmake_options .define ('_SwiftFoundationICU_SourceDIR' , os .path .join (source_root , 'swift-foundation-icu' ))
157
161
foundation .cmake_options .define ('SwiftFoundation_MACRO' , os .path .join (host_toolchain , 'lib' , 'swift' , 'host' , 'plugins' ))
158
-
159
- foundation .cmake_options .define ('LIBXML2_INCLUDE_DIR' , os .path .join (wasi_sysroot , 'include' , 'libxml2' ))
160
- foundation .cmake_options .define ('LIBXML2_LIBRARY' , os .path .join (wasi_sysroot , 'lib' ))
162
+ # Teach CMake to use wasi-sysroot for finding packages through `find_package`.
163
+ # With `CMAKE_LIBRARY_ARCHITECTURE`, CMake will search for libraries in
164
+ # `<sysroot>/lib/<clang_multiarch_triple>/cmake/<name>*/<name>-config.cmake`,
165
+ # which is the location where libxml2 installs its CMake config files.
166
+ # See https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure
167
+ foundation .cmake_options .define ('CMAKE_PREFIX_PATH' , wasi_sysroot )
168
+ foundation .cmake_options .define ('CMAKE_LIBRARY_ARCHITECTURE' , clang_multiarch_triple )
161
169
162
170
foundation .build_with_cmake ([], self .args .build_variant , [],
163
171
prefer_native_toolchain = not self .args .build_runtime_with_host_compiler ,
@@ -214,7 +222,7 @@ def _build_xctest(self, swift_host_triple, has_pthread, wasi_sysroot):
214
222
shell .call ([self .toolchain .cmake , '--install' , '.' , '--prefix' , '/usr' ],
215
223
env = {'DESTDIR' : dest_dir })
216
224
217
- def _build_target_package (self , swift_host_triple , has_pthread ,
225
+ def _build_target_package (self , swift_host_triple , clang_multiarch_triple , has_pthread ,
218
226
stdlib_build_path , llvm_runtime_libs_build_path ,
219
227
wasi_sysroot ):
220
228
@@ -235,8 +243,8 @@ def _build_target_package(self, swift_host_triple, has_pthread,
235
243
'--component' , 'clang_rt.builtins-wasm32' ],
236
244
env = {'DESTDIR' : clang_dir })
237
245
238
- self ._build_libxml2 (swift_host_triple , has_pthread , wasi_sysroot )
239
- self ._build_foundation (swift_host_triple , has_pthread , wasi_sysroot )
246
+ self ._build_libxml2 (swift_host_triple , clang_multiarch_triple , has_pthread , wasi_sysroot )
247
+ self ._build_foundation (swift_host_triple , clang_multiarch_triple , has_pthread , wasi_sysroot )
240
248
# Build swift-testing
241
249
self ._build_swift_testing (swift_host_triple , has_pthread , wasi_sysroot )
242
250
self ._build_xctest (swift_host_triple , has_pthread , wasi_sysroot )
@@ -266,7 +274,7 @@ def build(self, host_target):
266
274
build_root , '%s-%s' % ('wasmllvmruntimelibs' , host_target ),
267
275
clang_multiarch_triple )
268
276
package_path = self ._build_target_package (
269
- swift_host_triple , has_pthread , stdlib_build_path ,
277
+ swift_host_triple , clang_multiarch_triple , has_pthread , stdlib_build_path ,
270
278
llvm_runtime_libs_build_path , wasi_sysroot )
271
279
if build_sdk :
272
280
target_packages .append ((swift_host_triple , wasi_sysroot , package_path ))
0 commit comments