Skip to content

Add CMake build #73

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 5 commits into from
Jun 12, 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
17 changes: 17 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ jobs:
format_check_enabled: false
unacceptable_language_check_enabled: false
api_breakage_check_enabled: false

cmake_build:
name: CMake Build
runs-on: ubuntu-latest
container: swift:6.1-noble
steps:
- name: checkout sources
uses: actions/checkout@v1
- name: Install dependencies
shell: bash
run: apt update && apt install -y cmake ninja-build
- name: Configure Project
shell: bash
run: cmake -G 'Ninja' -B build -S . -DCMAKE_C_COMPILER=clang -DCMAKE_Swift_COMPILER=swiftc -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES
- name: Build Project
shell: bash
run: cmake --build build
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

cmake_minimum_required(VERSION 3.26...3.29)
project(Subprocess LANGUAGES C Swift)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name ${PROJECT_NAME}>")

include(InstallExternalDependencies)

add_subdirectory(Sources)
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ let package = Package(
.product(name: "SystemPackage", package: "swift-system"),
],
path: "Sources/Subprocess",
exclude: [ "CMakeLists.txt" ],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.enableExperimentalFeature("NonescapableTypes"),
Expand Down Expand Up @@ -83,7 +84,8 @@ let package = Package(

.target(
name: "_SubprocessCShims",
path: "Sources/_SubprocessCShims"
path: "Sources/_SubprocessCShims",
exclude: [ "CMakeLists.txt" ]
),
]
)
23 changes: 23 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

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)
38 changes: 38 additions & 0 deletions Sources/Subprocess/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

target_sources(Subprocess PRIVATE
Execution.swift
Buffer.swift
Error.swift
Teardown.swift
Result.swift
IO/Output.swift
IO/Input.swift
Span+Subprocess.swift
AsyncBufferSequence.swift
API.swift
SubprocessFoundation/Span+SubprocessFoundation.swift
SubprocessFoundation/Output+Foundation.swift
SubprocessFoundation/Input+Foundation.swift
Configuration.swift)

if(WIN32)
target_sources(Subprocess PRIVATE Platforms/Subprocess+Windows.swift)
elseif(LINUX OR ANDROID)
target_sources(Subprocess PRIVATE
Platforms/Subprocess+Linux.swift
Platforms/Subprocess+Unix.swift)
elseif(APPLE)
target_sources(Subprocess PRIVATE
Platforms/Subprocess+Darwin.swift
Platforms/Subprocess+Unix.swift)
endif()
15 changes: 15 additions & 0 deletions Sources/_SubprocessCShims/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

target_sources(Subprocess PRIVATE process_shims.c)

target_include_directories(Subprocess PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
4 changes: 4 additions & 0 deletions Sources/_SubprocessCShims/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module _SubprocessCShims {
header "process_shims.h"
header "target_conditionals.h"
}
4 changes: 4 additions & 0 deletions Sources/_SubprocessCShims/process_shims.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
extern char **environ;
#endif

#if __has_include(<mach/vm_page_size.h>)
#include <mach/vm_page_size.h>
#endif

int _was_process_exited(int status) {
return WIFEXITED(status);
}
Expand Down
27 changes: 27 additions & 0 deletions cmake/modules/InstallExternalDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shahmishal @owenv FYI since we're currently trying to get this to 1.5.0.

GIT_SHALLOW YES)
list(APPEND dependencies SwiftSystem)


if(dependencies)
FetchContent_MakeAvailable(${dependencies})
endif()
Loading