Skip to content

build: replicate the SPM style build, address TODO #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,5 @@
##
##===----------------------------------------------------------------------===##

add_library(Subprocess)

add_subdirectory(_SubprocessCShims)
add_subdirectory(Subprocess)

target_compile_options(Subprocess PRIVATE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StrictConcurrency>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTyeps>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")

target_link_libraries(Subprocess PRIVATE SystemPackage)
16 changes: 13 additions & 3 deletions Sources/Subprocess/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##
##===----------------------------------------------------------------------===##

target_sources(Subprocess PRIVATE
add_library(Subprocess
Execution.swift
Buffer.swift
Error.swift
Expand All @@ -24,9 +24,9 @@ target_sources(Subprocess PRIVATE
SubprocessFoundation/Output+Foundation.swift
SubprocessFoundation/Input+Foundation.swift
Configuration.swift)

if(WIN32)
target_sources(Subprocess PRIVATE Platforms/Subprocess+Windows.swift)
target_sources(Subprocess PRIVATE
Platforms/Subprocess+Windows.swift)
elseif(LINUX OR ANDROID)
target_sources(Subprocess PRIVATE
Platforms/Subprocess+Linux.swift
Expand All @@ -36,3 +36,13 @@ elseif(APPLE)
Platforms/Subprocess+Darwin.swift
Platforms/Subprocess+Unix.swift)
endif()

target_compile_options(Subprocess PRIVATE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StrictConcurrency>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTyeps>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")
target_link_libraries(Subprocess PUBLIC
_SubprocessCShims)
target_link_libraries(Subprocess PRIVATE
SwiftSystem::SystemPackage)
8 changes: 4 additions & 4 deletions Sources/_SubprocessCShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##
##===----------------------------------------------------------------------===##

target_sources(Subprocess PRIVATE process_shims.c)

target_include_directories(Subprocess PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
add_library(_SubprocessCShims STATIC
process_shims.c)
target_include_directories(_SubprocessCShims PUBLIC
include)
24 changes: 14 additions & 10 deletions cmake/modules/InstallExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@

include_guard()

# TODO: Use find_package to find a pre-built SwiftSystem

include(FetchContent)

FetchContent_Declare(SwiftSystem
GIT_REPOSITORY https://github.com/apple/swift-system.git
GIT_TAG a34201439c74b53f0fd71ef11741af7e7caf01e1 # 1.4.2
GIT_SHALLOW YES)
list(APPEND dependencies SwiftSystem)

find_package(SwiftSystem QUIET)
if(NOT SwiftSystem_FOUND)
message("-- Vendoring swift-system")
FetchContent_Declare(SwiftSystem
GIT_REPOSITORY https://github.com/apple/swift-system.git
GIT_TAG a34201439c74b53f0fd71ef11741af7e7caf01e1 # 1.4.2
GIT_SHALLOW YES)
list(APPEND VendoredDependencies SwiftSystem)
endif()

if(dependencies)
FetchContent_MakeAvailable(${dependencies})
if(VendoredDependencies)
FetchContent_MakeAvailable(${VendoredDependencies})
if(NOT TARGET SwiftSystem::SystemPackage)
add_library(SwiftSystem::SystemPackage ALIAS SystemPackage)
endif()
endif()