Skip to content

Commit 41ce3df

Browse files
authored
build: replicate the SPM style build, address TODO (#122)
This restructures the internal modules to match what we do in SPM. This is primarily to help make it easier to mirror behaviour. Address the TODO, adding support to build against a swift-system build tree which is going to be required for integrating this into the Windows toolchain build. If one is not provided, continue the ability to vendor swift-system for ease of local development.
1 parent adc2749 commit 41ce3df

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

Sources/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,5 @@
99
##
1010
##===----------------------------------------------------------------------===##
1111

12-
add_library(Subprocess)
13-
1412
add_subdirectory(_SubprocessCShims)
1513
add_subdirectory(Subprocess)
16-
17-
target_compile_options(Subprocess PRIVATE
18-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StrictConcurrency>"
19-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTyeps>"
20-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
21-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")
22-
23-
target_link_libraries(Subprocess PRIVATE SystemPackage)

Sources/Subprocess/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##
1010
##===----------------------------------------------------------------------===##
1111

12-
target_sources(Subprocess PRIVATE
12+
add_library(Subprocess
1313
Execution.swift
1414
Buffer.swift
1515
Error.swift
@@ -24,9 +24,9 @@ target_sources(Subprocess PRIVATE
2424
SubprocessFoundation/Output+Foundation.swift
2525
SubprocessFoundation/Input+Foundation.swift
2626
Configuration.swift)
27-
2827
if(WIN32)
29-
target_sources(Subprocess PRIVATE Platforms/Subprocess+Windows.swift)
28+
target_sources(Subprocess PRIVATE
29+
Platforms/Subprocess+Windows.swift)
3030
elseif(LINUX OR ANDROID)
3131
target_sources(Subprocess PRIVATE
3232
Platforms/Subprocess+Linux.swift
@@ -36,3 +36,13 @@ elseif(APPLE)
3636
Platforms/Subprocess+Darwin.swift
3737
Platforms/Subprocess+Unix.swift)
3838
endif()
39+
40+
target_compile_options(Subprocess PRIVATE
41+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StrictConcurrency>"
42+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTyeps>"
43+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
44+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")
45+
target_link_libraries(Subprocess PUBLIC
46+
_SubprocessCShims)
47+
target_link_libraries(Subprocess PRIVATE
48+
SwiftSystem::SystemPackage)

Sources/_SubprocessCShims/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
##
1010
##===----------------------------------------------------------------------===##
1111

12-
target_sources(Subprocess PRIVATE process_shims.c)
13-
14-
target_include_directories(Subprocess PRIVATE
15-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
12+
add_library(_SubprocessCShims STATIC
13+
process_shims.c)
14+
target_include_directories(_SubprocessCShims PUBLIC
15+
include)

cmake/modules/InstallExternalDependencies.cmake

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@
1111

1212
include_guard()
1313

14-
# TODO: Use find_package to find a pre-built SwiftSystem
15-
1614
include(FetchContent)
1715

18-
FetchContent_Declare(SwiftSystem
19-
GIT_REPOSITORY https://github.com/apple/swift-system.git
20-
GIT_TAG a34201439c74b53f0fd71ef11741af7e7caf01e1 # 1.4.2
21-
GIT_SHALLOW YES)
22-
list(APPEND dependencies SwiftSystem)
23-
16+
find_package(SwiftSystem QUIET)
17+
if(NOT SwiftSystem_FOUND)
18+
message("-- Vendoring swift-system")
19+
FetchContent_Declare(SwiftSystem
20+
GIT_REPOSITORY https://github.com/apple/swift-system.git
21+
GIT_TAG a34201439c74b53f0fd71ef11741af7e7caf01e1 # 1.4.2
22+
GIT_SHALLOW YES)
23+
list(APPEND VendoredDependencies SwiftSystem)
24+
endif()
2425

25-
if(dependencies)
26-
FetchContent_MakeAvailable(${dependencies})
26+
if(VendoredDependencies)
27+
FetchContent_MakeAvailable(${VendoredDependencies})
28+
if(NOT TARGET SwiftSystem::SystemPackage)
29+
add_library(SwiftSystem::SystemPackage ALIAS SystemPackage)
30+
endif()
2731
endif()

0 commit comments

Comments
 (0)