Skip to content

Commit 910552c

Browse files
committed
build: statically link a subset of libraries
Now that Windows supports static link (to a certain extent), this strategically statically links some of the internal libraries of Swift Package manager. This set was determined empirically, and was shown to have a size benefit (beyond just reducing the distributed file count). Before: 273,408 Basics.dll 543,232 Build.dll 3,083,776 Commands.dll 187,904 LLBuildManifest.dll 994,304 PackageCollections.dll 168,960 PackageCollectionsModel.dll 892,928 PackageCollectionsSigning.dll 74,240 PackageFingerprint.dll 818,176 PackageGraph.dll 591,872 PackageLoading.dll 776,704 PackageModel.dll 220,672 PackageRegistry.dll 181,248 SourceControl.dll 560,640 SPMBuildCore.dll 44,544 SPMLLBuild.dll 1,037,312 Workspace.dll 587,776 XCBuildSupport.dll 310,272 Xcodeproj.dll 22,016 swift-build.exe 24,576 swift-package.exe 22,016 swift-run.exe 22,016 swift-test.exe 11,438,592 bytes After: 273,408 Basics.dll 662,528 Build.dll 5,531,136 Commands.dll 817,664 PackageGraph.dll 591,872 PackageLoading.dll 776,704 PackageModel.dll 560,640 SPMBuildCore.dll 1,355,264 Workspace.dll 20,992 swift-build.exe 23,552 swift-package.exe 20,992 swift-run.exe 20,992 swift-test.exe 10,655,744 bytes This saves ~768KiB. This additionally helps save ~1KiB from sourcekit-lsp after SourceKit-LSP transitions to static linking. Statically linking all the content in the repository causes the SPM distribution to balloon 250% to ~25MiB and causes SourceKit-LSP to balloon 300% to ~7MiB. While it would be nice to statically link in Build into the Commands (which saves ~100 KiB), it results in an overall bloat due to SK-LSP increasing by ~300 KiB.
1 parent 2cfd4a6 commit 910552c

File tree

10 files changed

+11
-74
lines changed

10 files changed

+11
-74
lines changed

Sources/LLBuildManifest/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(LLBuildManifest
9+
add_library(LLBuildManifest STATIC
1010
BuildManifest.swift
1111
Command.swift
1212
ManifestWriter.swift
@@ -22,10 +22,4 @@ target_link_libraries(LLBuildManifest PUBLIC
2222
set_target_properties(LLBuildManifest PROPERTIES
2323
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2424

25-
if(USE_CMAKE_INSTALL)
26-
install(TARGETS LLBuildManifest
27-
ARCHIVE DESTINATION lib
28-
LIBRARY DESTINATION lib
29-
RUNTIME DESTINATION bin)
30-
endif()
3125
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS LLBuildManifest)

Sources/PackageCollections/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(PackageCollections
9+
add_library(PackageCollections STATIC
1010
Model/Collection.swift
1111
Model/CVE.swift
1212
Model/License.swift
@@ -46,10 +46,4 @@ target_link_libraries(PackageCollections PUBLIC
4646
set_target_properties(PackageCollections PROPERTIES
4747
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
4848

49-
if(USE_CMAKE_INSTALL)
50-
install(TARGETS PackageCollections
51-
ARCHIVE DESTINATION lib
52-
LIBRARY DESTINATION lib
53-
RUNTIME DESTINATION bin)
54-
endif()
5549
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageCollections)

Sources/PackageCollectionsModel/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(PackageCollectionsModel
9+
add_library(PackageCollectionsModel STATIC
1010
PackageCollectionModel.swift
1111
PackageCollectionModel+v1.swift)
1212
target_link_libraries(PackageCollectionsModel PUBLIC
@@ -15,10 +15,4 @@ target_link_libraries(PackageCollectionsModel PUBLIC
1515
set_target_properties(PackageCollectionsModel PROPERTIES
1616
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
1717

18-
if(USE_CMAKE_INSTALL)
19-
install(TARGETS PackageCollectionsModel
20-
ARCHIVE DESTINATION lib
21-
LIBRARY DESTINATION lib
22-
RUNTIME DESTINATION bin)
23-
endif()
2418
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageCollectionsModel)

Sources/PackageCollectionsSigning/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(PackageCollectionsSigning
9+
add_library(PackageCollectionsSigning STATIC
1010
Certificate/Certificate.swift
1111
Certificate/CertificatePolicy.swift
1212
Key/ASN1/ASN1.swift
@@ -50,10 +50,4 @@ set_target_properties(PackageCollectionsSigning PROPERTIES
5050
target_link_options(PackageCollectionsSigning PRIVATE
5151
"$<$<PLATFORM_ID:Darwin>:SHELL:-Xlinker -framework -Xlinker Security>")
5252

53-
if(USE_CMAKE_INSTALL)
54-
install(TARGETS PackageCollectionsSigning
55-
ARCHIVE DESTINATION lib
56-
LIBRARY DESTINATION lib
57-
RUNTIME DESTINATION bin)
58-
endif()
5953
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageCollectionsSigning)

Sources/PackageFingerprint/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(PackageFingerprint
9+
add_library(PackageFingerprint STATIC
1010
FilePackageFingerprintStorage.swift
1111
Model.swift
1212
PackageFingerprintStorage.swift)
@@ -19,10 +19,4 @@ target_link_libraries(PackageFingerprint PUBLIC
1919
set_target_properties(PackageFingerprint PROPERTIES
2020
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2121

22-
if(USE_CMAKE_INSTALL)
23-
install(TARGETS PackageFingerprint
24-
ARCHIVE DESTINATION lib
25-
LIBRARY DESTINATION lib
26-
RUNTIME DESTINATION bin)
27-
endif()
2822
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageFingerprint)

Sources/PackageRegistry/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(PackageRegistry
9+
add_library(PackageRegistry STATIC
1010
Registry.swift
1111
RegistryConfiguration.swift
1212
RegistryClient.swift
@@ -22,10 +22,4 @@ target_link_libraries(PackageRegistry PUBLIC
2222
set_target_properties(PackageRegistry PROPERTIES
2323
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2424

25-
if(USE_CMAKE_INSTALL)
26-
install(TARGETS PackageRegistry
27-
ARCHIVE DESTINATION lib
28-
LIBRARY DESTINATION lib
29-
RUNTIME DESTINATION bin)
30-
endif()
3125
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageRegistry)

Sources/SPMLLBuild/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SPMLLBuild
9+
add_library(SPMLLBuild STATIC
1010
llbuild.swift)
1111
# NOTE(compnerd) workaround for CMake not setting up include flags yet
1212
set_target_properties(SPMLLBuild PROPERTIES
@@ -18,10 +18,4 @@ target_link_libraries(SPMLLBuild PUBLIC
1818
Basics
1919
llbuildSwift)
2020

21-
if(USE_CMAKE_INSTALL)
22-
install(TARGETS SPMLLBuild
23-
ARCHIVE DESTINATION lib
24-
LIBRARY DESTINATION lib
25-
RUNTIME DESTINATION bin)
26-
endif()
2721
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS SPMLLBuild)

Sources/SourceControl/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SourceControl
9+
add_library(SourceControl STATIC
1010
GitRepository.swift
1111
Repository.swift
1212
RepositoryManager.swift)
13-
1413
target_link_libraries(SourceControl PUBLIC
1514
Basics
1615
PackageModel
@@ -22,10 +21,4 @@ target_link_libraries(SourceControl PUBLIC
2221
set_target_properties(SourceControl PROPERTIES
2322
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2423

25-
if(USE_CMAKE_INSTALL)
26-
install(TARGETS SourceControl
27-
ARCHIVE DESTINATION lib
28-
LIBRARY DESTINATION lib
29-
RUNTIME DESTINATION bin)
30-
endif()
3124
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS SourceControl)

Sources/XCBuildSupport/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(XCBuildSupport
9+
add_library(XCBuildSupport STATIC
1010
PIF.swift
1111
PIFBuilder.swift
1212
XCBuildDelegate.swift
1313
XCBuildMessage.swift
1414
XCBuildOutputParser.swift
15-
XcodeBuildSystem.swift
16-
)
15+
XcodeBuildSystem.swift)
1716
target_link_libraries(XCBuildSupport PUBLIC
1817
Build
1918
TSCBasic
@@ -23,10 +22,3 @@ target_link_libraries(XCBuildSupport PUBLIC
2322

2423
set_target_properties(XCBuildSupport PROPERTIES
2524
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
26-
27-
if(USE_CMAKE_INSTALL)
28-
install(TARGETS XCBuildSupport
29-
ARCHIVE DESTINATION lib
30-
LIBRARY DESTINATION lib
31-
RUNTIME DESTINATION bin)
32-
endif()

Sources/Xcodeproj/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(Xcodeproj
9+
add_library(Xcodeproj STATIC
1010
generate.swift
1111
pbxproj.swift
1212
PropertyList.swift
@@ -22,9 +22,3 @@ target_link_libraries(Xcodeproj PUBLIC
2222
set_target_properties(Xcodeproj PROPERTIES
2323
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2424

25-
if(USE_CMAKE_INSTALL)
26-
install(TARGETS Xcodeproj
27-
ARCHIVE DESTINATION lib
28-
LIBRARY DESTINATION lib
29-
RUNTIME DESTINATION bin)
30-
endif()

0 commit comments

Comments
 (0)