From 8682afd971b68a9c73d66417cb2ba3fca57a85c1 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Fri, 29 May 2026 14:55:47 -0700 Subject: [PATCH] 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 --- Modules/CMakeDetermineSwiftCompiler.cmake | 4 ++++ Modules/CMakeSwiftCompiler.cmake.in | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Modules/CMakeDetermineSwiftCompiler.cmake b/Modules/CMakeDetermineSwiftCompiler.cmake index d1c09fc814..b8f69eea47 100644 --- a/Modules/CMakeDetermineSwiftCompiler.cmake +++ b/Modules/CMakeDetermineSwiftCompiler.cmake @@ -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) diff --git a/Modules/CMakeSwiftCompiler.cmake.in b/Modules/CMakeSwiftCompiler.cmake.in index 5e2483a02d..27139d646b 100644 --- a/Modules/CMakeSwiftCompiler.cmake.in +++ b/Modules/CMakeSwiftCompiler.cmake.in @@ -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()