Skip to content

Commit 56d99c0

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 56d99c0

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

Sources/CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,29 @@
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(_SwiftFlags -DCMAKE_Swift_FLAGS="-use-ld=lld")
18+
else()
19+
set(_SwiftFlags)
20+
endif()
21+
ExternalProject_Add(FoundationMacros
22+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/FoundationMacros"
23+
PREFIX "${CMAKE_BINARY_DIR}/_deps"
24+
BINARY_DIR "macros"
25+
CMAKE_ARGS
26+
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
27+
${_SwiftFlags}
28+
INSTALL_COMMAND "")
29+
ExternalProject_Get_Property(FoundationMacros BINARY_DIR)
30+
if(CMAKE_HOST_WIN32)
31+
set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros.exe#PredicateMacro")
32+
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros.exe#ExpressionMacro")
33+
else()
34+
set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros#PredicateMacro")
35+
set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros#ExpressionMacro")
2036
endif()
2137

38+
add_subdirectory(_FoundationCShims)
2239
add_subdirectory(FoundationEssentials)
2340
add_subdirectory(FoundationInternationalization)

Sources/FoundationMacros/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
##
1313
##===----------------------------------------------------------------------===##
1414

15+
cmake_minimum_required(VERSION 3.22)
16+
if(POLICY CMP0157)
17+
cmake_policy(SET CMP0157 NEW)
18+
endif()
19+
20+
project(FoundationMacros
21+
LANGUAGES Swift)
22+
1523
# SwiftSyntax Dependency
16-
include(FetchContent)
1724
find_package(SwiftSyntax)
1825
if(NOT SwiftSyntax_FOUND)
26+
include(FetchContent)
27+
1928
# If building at desk, check out and link against the SwiftSyntax repo's targets
2029
FetchContent_Declare(SwiftSyntax
2130
GIT_REPOSITORY https://github.com/swiftlang/swift-syntax.git

0 commit comments

Comments
 (0)