Skip to content

Commit a332b7b

Browse files
committed
FoundationMacros: use cross-compilation to build for host
Use `ExternalProject` to switch FoundationMacros to cross-compilation. This allows us to build the macros for the right OS/architecture when cross-compiling Foundation for other environments.
1 parent 046bb36 commit a332b7b

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Sources/CMakeLists.txt

+20-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,27 @@
1212
##
1313
##===----------------------------------------------------------------------===##
1414

15-
add_subdirectory(_FoundationCShims)
16-
17-
# Disable the macro build on Windows until we can correctly build it for the host architecture
18-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
19-
add_subdirectory(FoundationMacros)
15+
include(ExternalProject)
16+
if(CMAKE_HOST_WIN32)
17+
set(_FoundationMacrosSwiftFlags -DCMAKE_Swift_FLAGS="-use-ld=lld")
18+
endif()
19+
ExternalProject_Add(FoundationMacros
20+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/FoundationMacros"
21+
PREFIX "${CMAKE_BINARY_DIR}/_deps"
22+
BINARY_DIR "macros"
23+
CMAKE_ARGS
24+
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
25+
${_FoundationMacrosSwiftFlags}
26+
INSTALL_COMMAND "")
27+
ExternalProject_Get_Property(FoundationMacros BINARY_DIR)
28+
if(CMAKE_HOST_WIN32)
29+
set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros.exe#PredicateMacro")
30+
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros.exe#ExpressionMacro")
31+
else()
32+
set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros#PredicateMacro")
33+
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros#ExpressionMacro")
2034
endif()
2135

36+
add_subdirectory(_FoundationCShims)
2237
add_subdirectory(FoundationEssentials)
2338
add_subdirectory(FoundationInternationalization)

Sources/FoundationMacros/CMakeLists.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@
1212
##
1313
##===----------------------------------------------------------------------===##
1414

15+
cmake_minimum_required(VERSION 3.22)
16+
17+
if(POLICY CMP0156)
18+
# Deduplicate linked libraries where appropriate
19+
cmake_policy(SET CMP0156 NEW)
20+
endif()
21+
if(POLICY CMP0157)
22+
# New Swift build model: improved incremental build performance and LSP support
23+
cmake_policy(SET CMP0157 NEW)
24+
endif()
25+
26+
project(FoundationMacros
27+
LANGUAGES Swift)
28+
1529
# SwiftSyntax Dependency
16-
include(FetchContent)
1730
find_package(SwiftSyntax)
1831
if(NOT SwiftSyntax_FOUND)
32+
include(FetchContent)
33+
1934
# If building at desk, check out and link against the SwiftSyntax repo's targets
2035
FetchContent_Declare(SwiftSyntax
2136
GIT_REPOSITORY https://github.com/swiftlang/swift-syntax.git

0 commit comments

Comments
 (0)