Swift: Extract pointer size from Swift compiler

The target info in Swift 6.2 and newer supports emitting the pointer
size for a given target triple. We can use that to set the Swift data
pointer size, and the `CMAKE_SIZEOF_VOID_P`.

Fixes: #26649
This commit is contained in:
Evan Wilde
2026-05-29 15:15:43 -07:00
parent cd807309bf
commit 8682afd971
2 changed files with 9 additions and 0 deletions
@@ -139,6 +139,10 @@ if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2)
message(CONFIGURE_LOG "Swift target info:\n" "${swift_target_info}")
string(JSON module_triple GET "${swift_target_info}" "target" "moduleTriple")
set(CMAKE_Swift_MODULE_TRIPLE ${module_triple})
if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
string(JSON CMAKE_Swift_SIZEOF_DATA_PTR GET "${swift_target_info}" "target" "pointerWidthInBytes")
endif()
endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
+5
View File
@@ -18,3 +18,8 @@ set(CMAKE_Swift_COMPILER_USE_OLD_DRIVER "@CMAKE_Swift_COMPILER_USE_OLD_DRIVER@")
set(CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES@")
set(CMAKE_Swift_MODULE_TRIPLE "@CMAKE_Swift_MODULE_TRIPLE@")
set(CMAKE_Swift_SIZEOF_DATA_PTR "@CMAKE_Swift_SIZEOF_DATA_PTR@")
if(NOT CMAKE_SIZEOF_VOID_P AND CMAKE_Swift_SIZEOF_DATA_PTR)
set(CMAKE_SIZEOF_VOID_P "${CMAKE_Swift_SIZEOF_DATA_PTR}")
endif()