Skip to content

Commit 4921eaf

Browse files
authored
[CMake] Avoid stomping cache variables when cross-compiling (#76054)
If one is building unified and also cross-compiling (for example building from Linux x86_64 to Linux aarch64), these variables which are normally set in the cache pointing to a native toolchain are overwritten unconditionally pointing to the `CMAKE_BINARY_DIR`, which can be incompatible with the build machine. The value of `SWIFT_NATIVE_CLANG_TOOLS_PATH` is eventually passed to the Swift compiler as `-tools-directory`, which the new `swift-driver` actually seems to use to find `swiftc`. When the `swift-driver` tries to use the incompatible `swiftc`, it returns with a very unhelpful "error: failed to retrieve frontend target info". Avoiding overwriting the variables when cross-compiling lets the build system use the variables provided in the cache, which point to correct binaries for the build machine.
1 parent 327d556 commit 4921eaf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ endmacro()
268268
# cmake variables.
269269
macro(swift_common_unified_build_config product)
270270
set(${product}_PATH_TO_CLANG_BUILD "${CMAKE_BINARY_DIR}")
271-
set(${product}_NATIVE_LLVM_TOOLS_PATH "${CMAKE_BINARY_DIR}/bin")
272-
set(${product}_NATIVE_CLANG_TOOLS_PATH "${CMAKE_BINARY_DIR}/bin")
271+
if (NOT CMAKE_CROSSCOMPILING)
272+
set(${product}_NATIVE_LLVM_TOOLS_PATH "${CMAKE_BINARY_DIR}/bin")
273+
set(${product}_NATIVE_CLANG_TOOLS_PATH "${CMAKE_BINARY_DIR}/bin")
274+
endif()
273275
set(LLVM_PACKAGE_VERSION ${PACKAGE_VERSION})
274276
set(LLVM_CMAKE_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
275277
set(CLANG_INCLUDE_DIRS

0 commit comments

Comments
 (0)