@@ -67,9 +67,11 @@ def _configure_llvm(self, target_triple, short_triple):
6767 cmake_options .define ('LLVM_ENABLE_LIBXML2:BOOL' , 'FALSE' )
6868 cmake_options .define ('LLVM_ENABLE_LIBEDIT:BOOL' , 'FALSE' )
6969 cmake_options .define ('LLVM_ENABLE_TERMINFO:BOOL' , 'FALSE' )
70+ if self .args .build_runtime_with_host_compiler :
71+ cmake_options .define ('CMAKE_ASM_COMPILER:PATH' , self .toolchain .cc )
7072
7173 llvm_cmake = cmake .CMake (
72- self .args , self .toolchain , prefer_native_toolchain = True )
74+ self .args , self .toolchain , prefer_native_toolchain = not self . args . build_runtime_with_host_compiler )
7375 # Only configure LLVM, not build it because we just need
7476 # LLVM CMake functionalities
7577 shell .call (["env" , self .toolchain .cmake , "-B" , build_dir ]
@@ -90,25 +92,35 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir):
9092 self .cmake_options .define (
9193 'SWIFT_STDLIB_BUILD_TYPE:STRING' , self ._build_variant )
9294
93- # Toolchain configuration
94- toolchain_path = self .native_toolchain_path (host_target )
95- # Explicitly set the CMake AR and RANLIB to force it to use llvm-ar/llvm-ranlib
96- # instead of the system ar/ranlib, which usually don't support WebAssembly
97- # object files.
98- self .cmake_options .define ('CMAKE_AR:STRING' , os .path .join (
99- toolchain_path , 'bin' , 'llvm-ar' ))
100- self .cmake_options .define ('CMAKE_RANLIB:STRING' , os .path .join (
101- toolchain_path , 'bin' , 'llvm-ranlib' ))
102- self .cmake_options .define (
103- 'SWIFT_NATIVE_CLANG_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
104- self .cmake_options .define (
105- 'SWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
106- self .cmake_options .define (
107- 'SWIFT_NATIVE_LLVM_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
108- self .cmake_options .define (
109- 'BOOTSTRAPPING_MODE:STRING' , 'CROSSCOMPILE' )
110- self .cmake_options .define (
111- 'SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER:BOOL' , 'FALSE' )
95+ if self .args .build_runtime_with_host_compiler :
96+ self .cmake_options .define ('SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER:BOOL' , "TRUE" )
97+ self .cmake_options .define (
98+ 'SWIFT_NATIVE_CLANG_TOOLS_PATH:STRING' , os .path .dirname (self .toolchain .cc ))
99+ self .cmake_options .define (
100+ 'SWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING' , os .path .dirname (self .toolchain .swiftc ))
101+ self .cmake_options .define (
102+ 'SWIFT_NATIVE_LLVM_TOOLS_PATH:STRING' , os .path .dirname (self .toolchain .llvm_ar ))
103+ else :
104+ # Toolchain configuration
105+ toolchain_path = self .native_toolchain_path (host_target )
106+ # Explicitly set the CMake AR and RANLIB to force it to use llvm-ar/llvm-ranlib
107+ # instead of the system ar/ranlib, which usually don't support WebAssembly
108+ # object files.
109+ self .cmake_options .define ('CMAKE_AR:STRING' , os .path .join (
110+ toolchain_path , 'bin' , 'llvm-ar' ))
111+ self .cmake_options .define ('CMAKE_RANLIB:STRING' , os .path .join (
112+ toolchain_path , 'bin' , 'llvm-ranlib' ))
113+ self .cmake_options .define (
114+ 'SWIFT_NATIVE_CLANG_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
115+ self .cmake_options .define (
116+ 'SWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
117+ self .cmake_options .define (
118+ 'SWIFT_NATIVE_LLVM_TOOLS_PATH:STRING' , os .path .join (toolchain_path , 'bin' ))
119+ self .cmake_options .define (
120+ 'BOOTSTRAPPING_MODE:STRING' , 'CROSSCOMPILE' )
121+ self .cmake_options .define (
122+ 'SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER:BOOL' , 'FALSE' )
123+
112124 self .cmake_options .define ('SWIFT_WASI_SYSROOT_PATH:STRING' ,
113125 self ._wasi_sysroot_path (target_triple ))
114126
@@ -195,7 +207,7 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir):
195207
196208 # Configure with WebAssembly target variant, and build with just-built toolchain
197209 self .build_with_cmake ([], self ._build_variant , [],
198- prefer_native_toolchain = True )
210+ prefer_native_toolchain = not self . args . build_runtime_with_host_compiler )
199211
200212 def add_extra_cmake_options (self ):
201213 self .cmake_options .define ('SWIFT_THREADING_PACKAGE:STRING' , 'none' )
0 commit comments