Skip to content

Commit 25f4791

Browse files
authored
Merge pull request #73 from etcwilde/ewilde/cmake-build
Add CMake build
2 parents c6c761e + 8121674 commit 25f4791

File tree

9 files changed

+151
-1
lines changed

9 files changed

+151
-1
lines changed

.github/workflows/pull_request.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,20 @@ jobs:
2626
format_check_enabled: false
2727
unacceptable_language_check_enabled: false
2828
api_breakage_check_enabled: false
29+
30+
cmake_build:
31+
name: CMake Build
32+
runs-on: ubuntu-latest
33+
container: swift:6.1-noble
34+
steps:
35+
- name: checkout sources
36+
uses: actions/checkout@v1
37+
- name: Install dependencies
38+
shell: bash
39+
run: apt update && apt install -y cmake ninja-build
40+
- name: Configure Project
41+
shell: bash
42+
run: cmake -G 'Ninja' -B build -S . -DCMAKE_C_COMPILER=clang -DCMAKE_Swift_COMPILER=swiftc -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES
43+
- name: Build Project
44+
shell: bash
45+
run: cmake --build build

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
cmake_minimum_required(VERSION 3.26...3.29)
13+
project(Subprocess LANGUAGES C Swift)
14+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
15+
16+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name ${PROJECT_NAME}>")
17+
18+
include(InstallExternalDependencies)
19+
20+
add_subdirectory(Sources)

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ let package = Package(
5050
.product(name: "SystemPackage", package: "swift-system"),
5151
],
5252
path: "Sources/Subprocess",
53+
exclude: [ "CMakeLists.txt" ],
5354
swiftSettings: [
5455
.enableExperimentalFeature("StrictConcurrency"),
5556
.enableExperimentalFeature("NonescapableTypes"),
@@ -83,7 +84,8 @@ let package = Package(
8384

8485
.target(
8586
name: "_SubprocessCShims",
86-
path: "Sources/_SubprocessCShims"
87+
path: "Sources/_SubprocessCShims",
88+
exclude: [ "CMakeLists.txt" ]
8789
),
8890
]
8991
)

Sources/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
add_library(Subprocess)
13+
14+
add_subdirectory(_SubprocessCShims)
15+
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
target_sources(Subprocess PRIVATE
13+
Execution.swift
14+
Buffer.swift
15+
Error.swift
16+
Teardown.swift
17+
Result.swift
18+
IO/Output.swift
19+
IO/Input.swift
20+
Span+Subprocess.swift
21+
AsyncBufferSequence.swift
22+
API.swift
23+
SubprocessFoundation/Span+SubprocessFoundation.swift
24+
SubprocessFoundation/Output+Foundation.swift
25+
SubprocessFoundation/Input+Foundation.swift
26+
Configuration.swift)
27+
28+
if(WIN32)
29+
target_sources(Subprocess PRIVATE Platforms/Subprocess+Windows.swift)
30+
elseif(LINUX OR ANDROID)
31+
target_sources(Subprocess PRIVATE
32+
Platforms/Subprocess+Linux.swift
33+
Platforms/Subprocess+Unix.swift)
34+
elseif(APPLE)
35+
target_sources(Subprocess PRIVATE
36+
Platforms/Subprocess+Darwin.swift
37+
Platforms/Subprocess+Unix.swift)
38+
endif()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
target_sources(Subprocess PRIVATE process_shims.c)
13+
14+
target_include_directories(Subprocess PRIVATE
15+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module _SubprocessCShims {
2+
header "process_shims.h"
3+
header "target_conditionals.h"
4+
}

Sources/_SubprocessCShims/process_shims.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
extern char **environ;
4444
#endif
4545

46+
#if __has_include(<mach/vm_page_size.h>)
47+
#include <mach/vm_page_size.h>
48+
#endif
49+
4650
int _was_process_exited(int status) {
4751
return WIFEXITED(status);
4852
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
##
10+
##===----------------------------------------------------------------------===##
11+
12+
include_guard()
13+
14+
# TODO: Use find_package to find a pre-built SwiftSystem
15+
16+
include(FetchContent)
17+
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+
24+
25+
if(dependencies)
26+
FetchContent_MakeAvailable(${dependencies})
27+
endif()

0 commit comments

Comments
 (0)