Skip to content

Commit 8ed5c1a

Browse files
committed
build: introduce and switch to GYB_SOURCES
This avoids us having to pattern match every source file which should help speed up the CMake generation. A secondary optimization is possible with CMake 3.14 which has the ability to remove the last extension component without having to resort to regular expressions. It also helps easily identify the GYB'ed sources.
1 parent 20a1781 commit 8ed5c1a

File tree

24 files changed

+160
-101
lines changed

24 files changed

+160
-101
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ function(_add_swift_library_single target name)
721721
FILE_DEPENDS
722722
FRAMEWORK_DEPENDS
723723
FRAMEWORK_DEPENDS_WEAK
724+
GYB_SOURCES
724725
INCORPORATE_OBJECT_LIBRARIES
725726
INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY
726727
INTERFACE_LINK_LIBRARIES
@@ -810,10 +811,14 @@ function(_add_swift_library_single target name)
810811
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
811812
endif()
812813

813-
handle_gyb_sources(
814-
gyb_dependency_targets
815-
SWIFTLIB_SINGLE_SOURCES
816-
"${SWIFTLIB_SINGLE_ARCHITECTURE}")
814+
if(SWIFTLIB_SINGLE_GYB_SOURCES)
815+
handle_gyb_sources(
816+
gyb_dependency_targets
817+
SWIFTLIB_SINGLE_GYB_SOURCES
818+
"${SWIFTLIB_SINGLE_ARCHITECTURE}")
819+
set(SWIFTLIB_SINGLE_SOURCES ${SWIFTLIB_SINGLE_SOURCES}
820+
${SWIFTLIB_SINGLE_GYB_SOURCES})
821+
endif()
817822

818823
# Remove the "swift" prefix from the name to determine the module name.
819824
if(SWIFTLIB_IS_STDLIB_CORE)
@@ -1620,6 +1625,7 @@ function(add_swift_target_library name)
16201625
FRAMEWORK_DEPENDS_IOS_TVOS
16211626
FRAMEWORK_DEPENDS_OSX
16221627
FRAMEWORK_DEPENDS_WEAK
1628+
GYB_SOURCES
16231629
INCORPORATE_OBJECT_LIBRARIES
16241630
INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY
16251631
INTERFACE_LINK_LIBRARIES
@@ -1914,6 +1920,7 @@ function(add_swift_target_library name)
19141920
DEPLOYMENT_VERSION_IOS "${SWIFTLIB_DEPLOYMENT_VERSION_IOS}"
19151921
DEPLOYMENT_VERSION_TVOS "${SWIFTLIB_DEPLOYMENT_VERSION_TVOS}"
19161922
DEPLOYMENT_VERSION_WATCHOS "${SWIFTLIB_DEPLOYMENT_VERSION_WATCHOS}"
1923+
GYB_SOURCES ${SWIFTLIB_GYB_SOURCES}
19171924
)
19181925

19191926
if(NOT SWIFTLIB_OBJECT_LIBRARY)

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,31 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
131131
"${SWIFT_SOURCE_DIR}/utils/gyb_sourcekit_support/UIDs.py")
132132

133133
foreach (src ${${sources_var_name}})
134-
string(REGEX REPLACE "[.]gyb$" "" src_sans_gyb "${src}")
135-
if(src STREQUAL src_sans_gyb)
136-
list(APPEND de_gybbed_sources "${src}")
134+
# On Windows (using Visual Studio), the generated project files assume that the
135+
# generated GYB files will be in the source, not binary directory.
136+
# We can work around this by modifying the root directory when generating VS projects.
137+
if ("${CMAKE_GENERATOR_PLATFORM}" MATCHES "Visual Studio")
138+
set(dir_root ${CMAKE_CURRENT_SOURCE_DIR})
137139
else()
140+
set(dir_root ${CMAKE_CURRENT_BINARY_DIR})
141+
endif()
138142

139-
# On Windows (using Visual Studio), the generated project files assume that the
140-
# generated GYB files will be in the source, not binary directory.
141-
# We can work around this by modifying the root directory when generating VS projects.
142-
if ("${CMAKE_GENERATOR_PLATFORM}" MATCHES "Visual Studio")
143-
set(dir_root ${CMAKE_CURRENT_SOURCE_DIR})
144-
else()
145-
set(dir_root ${CMAKE_CURRENT_BINARY_DIR})
146-
endif()
147-
148-
if (arch)
149-
set(dir "${dir_root}/${ptr_size}")
150-
else()
151-
set(dir "${dir_root}")
152-
endif()
153-
set(output_file_name "${dir}/${src_sans_gyb}")
154-
list(APPEND de_gybbed_sources "${output_file_name}")
155-
handle_gyb_source_single(dependency_target
156-
SOURCE "${src}"
157-
OUTPUT "${output_file_name}"
158-
FLAGS ${extra_gyb_flags}
159-
DEPENDS "${gyb_extra_sources}"
160-
COMMENT "with ptr size = ${ptr_size}")
161-
list(APPEND dependency_targets "${dependency_target}")
143+
if (arch)
144+
set(dir "${dir_root}/${ptr_size}")
145+
else()
146+
set(dir "${dir_root}")
162147
endif()
148+
# get_filename_component(src_sans_gyb ${src} NAME_WLE)
149+
string(REGEX REPLACE "\.gyb$" "" src_sans_gyb ${src})
150+
set(output_file_name "${dir}/${src_sans_gyb}")
151+
list(APPEND de_gybbed_sources "${output_file_name}")
152+
handle_gyb_source_single(dependency_target
153+
SOURCE "${src}"
154+
OUTPUT "${output_file_name}"
155+
FLAGS ${extra_gyb_flags}
156+
DEPENDS "${gyb_extra_sources}"
157+
COMMENT "with ptr size = ${ptr_size}")
158+
list(APPEND dependency_targets "${dependency_target}")
163159
endforeach()
164160
set("${dependency_out_var_name}" "${dependency_targets}" PARENT_SCOPE)
165161
set("${sources_var_name}" "${de_gybbed_sources}" PARENT_SCOPE)

lib/Basic/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ add_swift_host_library(swiftBasic STATIC
102102
# Platform-agnostic fallback TaskQueue implementation
103103
Default/TaskQueue.inc
104104

105-
UnicodeExtendedGraphemeClusters.cpp.gyb
105+
GYB_SOURCES
106+
UnicodeExtendedGraphemeClusters.cpp.gyb
106107

107108
C_COMPILE_FLAGS ${UUID_INCLUDE}
108109
LLVM_COMPONENT_DEPENDS support)

lib/Parse/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ add_swift_host_library(swiftParse STATIC
1010
ParseDecl.cpp
1111
ParsedRawSyntaxNode.cpp
1212
ParsedRawSyntaxRecorder.cpp
13-
ParsedSyntaxBuilders.cpp.gyb
14-
ParsedSyntaxNodes.cpp.gyb
15-
ParsedSyntaxRecorder.cpp.gyb
1613
ParsedTrivia.cpp
1714
ParseExpr.cpp
1815
ParseGeneric.cpp
@@ -24,7 +21,12 @@ add_swift_host_library(swiftParse STATIC
2421
PersistentParserState.cpp
2522
Scope.cpp
2623
SyntaxParsingCache.cpp
27-
SyntaxParsingContext.cpp)
24+
SyntaxParsingContext.cpp
25+
26+
GYB_SOURCES
27+
ParsedSyntaxBuilders.cpp.gyb
28+
ParsedSyntaxNodes.cpp.gyb
29+
ParsedSyntaxRecorder.cpp.gyb)
2830
target_link_libraries(swiftParse PRIVATE
2931
swiftAST
3032
swiftSyntax)

lib/Syntax/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ else()
55
endif()
66

77
add_swift_host_library(swiftSyntax STATIC
8-
SyntaxNodes.cpp.gyb
9-
SyntaxBuilders.cpp.gyb
10-
SyntaxKind.cpp.gyb
11-
SyntaxFactory.cpp.gyb
12-
SyntaxVisitor.cpp.gyb
13-
Trivia.cpp.gyb
148
RawSyntax.cpp
159
Syntax.cpp
1610
SyntaxData.cpp
17-
SyntaxSerialization.cpp.gyb
18-
UnknownSyntax.cpp)
11+
UnknownSyntax.cpp
12+
13+
GYB_SOURCES
14+
SyntaxNodes.cpp.gyb
15+
SyntaxBuilders.cpp.gyb
16+
SyntaxKind.cpp.gyb
17+
SyntaxFactory.cpp.gyb
18+
SyntaxVisitor.cpp.gyb
19+
Trivia.cpp.gyb
20+
SyntaxSerialization.cpp.gyb)

stdlib/private/SwiftPrivate/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ add_swift_target_library(swiftSwiftPrivate ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
77
# filename.
88
SwiftPrivate.swift
99

10-
AtomicInt.swift.gyb
1110
IO.swift
1211
ShardedAtomicCounter.swift
1312

13+
GYB_SOURCES
14+
AtomicInt.swift.gyb
15+
1416
SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT WinSDK
1517
SWIFT_COMPILE_FLAGS ${swift_swiftprivate_compile_flags}
1618
INSTALL_IN_COMPONENT stdlib-experimental)

stdlib/public/Darwin/AVFoundation/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ add_swift_target_library(swiftAVFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYP
88
AVCaptureVideoDataOutput.swift
99
AVError.swift
1010
AVMetadataObject.swift
11-
NSValue.swift.gyb
11+
12+
GYB_SOURCES
13+
NSValue.swift.gyb
1214

1315
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
1416
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"

stdlib/public/Darwin/Accelerate/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
BNNS.swift.gyb
5+
6+
GYB_SOURCES
7+
BNNS.swift.gyb
68

79
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
810
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/CoreGraphics/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftCoreGraphics ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
55
CoreGraphics.swift
6-
CGFloat.swift.gyb
76
Private.swift
87

8+
GYB_SOURCES
9+
CGFloat.swift.gyb
10+
911
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
1012
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1113
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation Dispatch IOKit ObjectiveC # auto-updated

stdlib/public/Darwin/CoreLocation/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftCoreLocation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
55
CLError.swift
6-
NSValue.swift.gyb
6+
7+
GYB_SOURCES
8+
NSValue.swift.gyb
79

810
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
911
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/Foundation/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ add_swift_target_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
5151
NSTextCheckingResult.swift
5252
NSUndoManager.swift
5353
NSURL.swift
54-
NSValue.swift.gyb
5554
PersonNameComponents.swift
5655
PlistEncoder.swift
5756
Progress.swift
@@ -64,6 +63,9 @@ add_swift_target_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
6463
UUID.swift
6564
CheckClass.mm
6665

66+
GYB_SOURCES
67+
NSValue.swift.gyb
68+
6769
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}" "-Xllvm" "-sil-inline-generics" "-Xllvm" "-sil-partial-specialization" "-swift-version" "5"
6870
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
6971

stdlib/public/Darwin/GLKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftGLKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
GLKMath.swift.gyb
5+
6+
GYB_SOURCES
7+
GLKMath.swift.gyb
68

79
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
810
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/MapKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftMapKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
NSValue.swift.gyb
5+
6+
GYB_SOURCES
7+
NSValue.swift.gyb
68

79
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
810
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/QuartzCore/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftQuartzCore ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
NSValue.swift.gyb
5+
6+
GYB_SOURCES
7+
NSValue.swift.gyb
68

79
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
810
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/SceneKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftSceneKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
SceneKit.swift.gyb
5+
6+
GYB_SOURCES
7+
SceneKit.swift.gyb
68

79
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
810
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/SpriteKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftSpriteKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
55
SpriteKit.swift
6-
SpriteKitQuickLooks.swift.gyb
6+
7+
GYB_SOURCES
8+
SpriteKitQuickLooks.swift.gyb
79

810
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
911
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/UIKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ include("../../../../cmake/modules/StandaloneOverlay.cmake")
44
add_swift_target_library(swiftUIKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
55
DesignatedInitializers.mm
66
UIKit.swift
7-
UIKit_FoundationExtensions.swift.gyb
7+
8+
GYB_SOURCES
9+
UIKit_FoundationExtensions.swift.gyb
810

911
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} -swift-version 4.2
1012
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Darwin/simd/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.4.3)
22
include("../../../../cmake/modules/StandaloneOverlay.cmake")
33

44
add_swift_target_library(swiftsimd ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
5-
simd.swift.gyb
6-
Quaternion.swift.gyb
5+
6+
GYB_SOURCES
7+
simd.swift.gyb
8+
Quaternion.swift.gyb
79

810
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
911
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

stdlib/public/Platform/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
set(swift_platform_sources
22
Platform.swift
3-
TiocConstants.swift
3+
TiocConstants.swift)
4+
set(swift_platform_gyb_sources
45
tgmath.swift.gyb)
56

67
add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
7-
Darwin.swift.gyb
88
${swift_platform_sources}
99
POSIXError.swift
1010
MachError.swift
1111

12+
GYB_SOURCES
13+
${swift_platform_gyb_sources}
14+
Darwin.swift.gyb
15+
1216
SWIFT_COMPILE_FLAGS -Xfrontend -disable-objc-attr-requires-foundation-module "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
1317
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1418
TARGET_SDKS ALL_APPLE_PLATFORMS
@@ -18,9 +22,12 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
1822
DEPENDS copy_apinotes)
1923

2024
add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
21-
Glibc.swift.gyb
2225
${swift_platform_sources}
2326

27+
GYB_SOURCES
28+
${swift_platform_gyb_sources}
29+
Glibc.swift.gyb
30+
2431
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
2532
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
2633
TARGET_SDKS ANDROID CYGWIN FREEBSD LINUX HAIKU
@@ -30,6 +37,9 @@ add_swift_target_library(swiftMSVCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
3037
msvcrt.swift
3138
${swift_platform_sources}
3239

40+
GYB_SOURCES
41+
${swift_platform_gyb_sources}
42+
3343
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
3444
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
3545
TARGET_SDKS WINDOWS)

0 commit comments

Comments
 (0)