Skip to content

Commit c4bc404

Browse files
authored
Update build configurations for 2025/04 (#4)
* ci: update workflow, version, toolchain settings * relocate script, merge workflow files * use Swift 5.9.2, CMake 3.31 * cmake: fix source compile options with Ninja * analysis: use absolute path for .xcresult * ci: cancel if new job arrived
1 parent 8c0bd05 commit c4bc404

File tree

12 files changed

+214
-170
lines changed

12 files changed

+214
-170
lines changed

.github/workflows/analysis.yml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
name: "Analysis"
22

3-
on: [push, pull_request, workflow_dispatch]
3+
on:
4+
push:
5+
branches-ignore:
6+
- docs
7+
pull_request:
8+
branches: ["main"]
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
414

515
jobs:
616
sonarcloud:
@@ -12,21 +22,29 @@ jobs:
1222
fetch-depth: 0
1323
- uses: mobiledevops/xcode-select-version-action@v1
1424
with:
15-
xcode-select-version: "15.1"
25+
xcode-select-version: "15.2.0"
26+
- uses: swift-actions/setup-swift@v2
27+
with:
28+
swift-version: "5.9.2"
1629
- uses: ConorMacBride/install-package@v1.1.0
1730
with:
1831
brew: ninja
19-
- uses: SonarSource/sonarcloud-github-c-cpp@v2
32+
- uses: SonarSource/sonarcloud-github-c-cpp@v3.2.0
2033

2134
- name: "Run setup-metal-cpp.ps1"
22-
run: ./setup-metal-cpp.ps1
35+
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
2336
shell: pwsh
2437

25-
- uses: lukka/run-vcpkg@v11.4
38+
- uses: lukka/get-cmake@v4.0.0
39+
with:
40+
cmakeVersion: "3.31"
41+
42+
- uses: lukka/run-vcpkg@v11.5
2643
with:
27-
vcpkgDirectory: "/usr/local/share/vcpkg" # $VCPKG_INSTALLATION_ROOT
28-
vcpkgGitCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00 # 2023.12.12
29-
vcpkgJsonGlob: "${{ github.workspace }}/vcpkg.json"
44+
vcpkgDirectory: "${{ runner.tool_cache }}/vcpkg"
45+
vcpkgGitCommitId: b02e341c927f16d991edbd915d8ea43eac52096c # 2025.03.19
46+
vcpkgJsonGlob: "**/vcpkg.json"
47+
vcpkgConfigurationJsonGlob: "**/vcpkg-configuration.json"
3048
runVcpkgInstall: true
3149
- uses: lukka/run-cmake@v10.7
3250
with:
@@ -60,14 +78,17 @@ jobs:
6078
- name: "Run xccov-to-sonarqube-generic.sh"
6179
id: xcresult
6280
run: |
81+
# xcrun --show-sdk-path
6382
xcresult_path=$(find DerivedData/Logs/Test/ -maxdepth 1 -name "Test*.xcresult" | tail -n 1)
64-
echo "path=$xcresult_path" >> "$GITHUB_OUTPUT"
83+
echo "path=$(pwd)/xcresult_path" >> "$GITHUB_OUTPUT"
6584
bash ./scripts/xccov-to-sonarqube-generic.sh $xcresult_path > docs/coverage.xml
6685
shell: bash
6786

6887
- uses: kishikawakatsumi/xcresulttool@v1.7.1
88+
continue-on-error: true
6989
with:
7090
path: "${{ steps.xcresult.outputs.path }}"
91+
upload-bundles: 'failure'
7192

7293
- name: "Run xcrun(llvm-cov)"
7394
run: |

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# References
2+
#
3+
# - https://swiftversion.net
4+
# - https://github.com/actions/runner-images/tree/main/images/macos
5+
# - https://developer.apple.com/documentation/xcode-release-notes
6+
#
7+
name: "Build"
8+
9+
on:
10+
push:
11+
branches-ignore:
12+
- docs
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref_name }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
swiftpm:
21+
name: "Swift Package Manager"
22+
runs-on: macos-13
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: mobiledevops/xcode-select-version-action@v1
26+
with:
27+
xcode-select-version: "15.2.0"
28+
- uses: swift-actions/setup-swift@v2
29+
with:
30+
swift-version: "5.9.2"
31+
- uses: ConorMacBride/install-package@v1.1.0
32+
with:
33+
brew: swiftlint
34+
- name: "Run setup-metal-cpp.ps1"
35+
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
36+
shell: pwsh
37+
- name: "Swift Build(Debug)"
38+
run: swift build --configuration debug # --verbose --target ...
39+
- name: "Swift Build(Release)"
40+
run: swift build --configuration release
41+
- name: "Swift Test"
42+
run: swift test --verbose --enable-code-coverage
43+
- name: "Swift Lint"
44+
run: swiftlint lint --output docs/lint.md --reporter markdown # --autocorrect
45+
46+
cmake:
47+
name: "CMake"
48+
runs-on: macos-13
49+
env:
50+
VCPKG_FEATURE_FLAGS: "manifests,binarycaching,registries"
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: swift-actions/setup-swift@v2
54+
with:
55+
swift-version: "5.9.2"
56+
- name: "Run setup-metal-cpp.ps1"
57+
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
58+
shell: pwsh
59+
- uses: lukka/get-cmake@v4.0.0
60+
with:
61+
cmakeVersion: "3.31"
62+
- uses: lukka/run-vcpkg@v11.5
63+
with:
64+
vcpkgDirectory: "${{ runner.tool_cache }}/vcpkg"
65+
vcpkgGitCommitId: b02e341c927f16d991edbd915d8ea43eac52096c # 2025.03.19
66+
vcpkgJsonGlob: "**/vcpkg.json"
67+
vcpkgConfigurationJsonGlob: "**/vcpkg-configuration.json"
68+
runVcpkgInstall: true
69+
- uses: lukka/run-cmake@v10.7
70+
with:
71+
configurePreset: "x64-osx"
72+
buildPreset: "x64-osx-debug"
73+
testPreset: "x64-osx-debug"

.github/workflows/cmake.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.github/workflows/swift.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
# see https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
2-
cmake_minimum_required(VERSION 3.28)
3-
project(cpp_swift_bridges LANGUAGES CXX VERSION 1.2)
2+
cmake_minimum_required(VERSION 3.31)
3+
project(cpp_swift_bridges LANGUAGES CXX VERSION 1.3)
44

55
include(GNUInstallDirs)
66
set(CMAKE_CXX_STANDARD 20)
77

8+
message(STATUS "Using system: ${CMAKE_SYSTEM_VERSION}")
9+
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID}")
810
if(APPLE)
9-
set(CMAKE_Swift_LANGUAGE_VERSION 5)
1011
find_program(CMAKE_Swift_COMPILER NAMES swiftc REQUIRED)
1112
enable_language(Swift)
12-
# set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
13-
# if(ENABLE_COVERAGE)
14-
# add_compile_options(-Wextra -ftest-coverage -fprofile-arcs)
15-
# add_link_options(-ftest-coverage -fprofile-arcs)
16-
# endif()
13+
message(STATUS "Using swiftc: ${CMAKE_Swift_COMPILER}")
14+
15+
set(SWIFT_VERSION "5.0" CACHE STRING "Swift language version. 5.0 or 6.0")
16+
if(CMAKE_GENERATOR MATCHES "Xcode")
17+
set(CMAKE_XCODE_ATTRIBUTE_SWIFT_VERSION "${SWIFT_VERSION}")
18+
elseif(CMAKE_GENERATOR MATCHES "Ninja")
19+
# ...
20+
endif()
1721
endif()
18-
message(STATUS "Using system: ${CMAKE_SYSTEM_VERSION}")
19-
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID}")
20-
21-
if(CMAKE_TOOLCHAIN_FILE MATCHES vcpkg.cmake)
22-
message(STATUS "Using vcpkg: ${VCPKG_TARGET_TRIPLET}")
22+
if(ENABLE_COVERAGE)
23+
add_compile_options(-Wextra -ftest-coverage -fprofile-arcs)
24+
add_link_options(-ftest-coverage -fprofile-arcs)
2325
endif()
2426

2527
find_library(BORINGSSL_LIBPATH NAMES boringssl REQUIRED)
26-
message(STATUS "using BoringSSL: ${BORINGSSL_LIBPATH}")
28+
message(STATUS "Using BoringSSL: ${BORINGSSL_LIBPATH}")
2729

28-
find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED)
29-
find_package(Protobuf CONFIG REQUIRED)
30-
message(STATUS "Using protoc:")
31-
message(STATUS " ${Protobuf_LIBRARY}")
32-
message(STATUS " ${Protobuf_PROTOC_EXECUTABLE}")
30+
find_package(Protobuf REQUIRED)
31+
if(NOT DEFINED Protobuf_PROTOC_EXECUTABLE)
32+
find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED)
33+
endif()
34+
message(STATUS "Using protoc: ${Protobuf_PROTOC_EXECUTABLE}")
3335

3436
find_path(MetalCpp_INCLUDE_DIR
3537
NAMES "Metal/Metal.hpp"
3638
PATHS ${PROJECT_SOURCE_DIR}/externals/metal-cpp
3739
REQUIRED
3840
)
39-
message(STATUS "using Metal/Metal.hpp: ${MetalCpp_INCLUDE_DIR}")
41+
message(STATUS "Using Metal.hpp: ${MetalCpp_INCLUDE_DIR}")
4042

4143
list(APPEND ifcs
4244
src/Baguette.h
@@ -72,24 +74,33 @@ PUBLIC
7274

7375
target_link_libraries(BaguetteBridge
7476
PUBLIC
75-
"-framework Foundation"
77+
"-framework Foundation" "-framework Metal"
7678
${BORINGSSL_LIBPATH}
7779
)
7880

81+
list(APPEND SWIFT_SRCS
82+
platform-apple/AsyncRoutines.swift
83+
platform-apple/BaguetteBridge.swift
84+
platform-apple/CryptoRoutines.swift
85+
platform-apple/DecoderRoutines.swift
86+
platform-apple/HostInfo.swift
87+
)
88+
set_source_files_properties(${SWIFT_SRCS}
89+
PROPERTIES
90+
LANGUAGE Swift
91+
COMPILE_OPTIONS "SHELL:-swift-version ${SWIFT_VERSION}"
92+
)
93+
7994
target_sources(BaguetteBridge
8095
PRIVATE
8196
src/bridge_apple.cpp
97+
${SWIFT_SRCS}
8298
src/swift_crypto.cpp
8399
src/swift_crypto.hpp
84100
src/swift_decoder.cpp
85101
src/swift_decoder.hpp
86102
src/swift_hostinfo.hpp
87103
src/swift_hostinfo.cpp
88-
platform-apple/AsyncRoutines.swift
89-
platform-apple/BaguetteBridge.swift
90-
platform-apple/CryptoRoutines.swift
91-
platform-apple/DecoderRoutines.swift
92-
platform-apple/HostInfo.swift
93104
)
94105

95106
install(TARGETS BaguetteBridge FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})

CMakePresets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
"name": "vcpkg-find",
1111
"hidden": true,
1212
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
13-
"environment": {
14-
"VCPKG_FEATURE_FLAGS": "manifests",
13+
"cacheVariables": {
14+
"VCPKG_MANIFEST_FEATURES": "",
1515
"VCPKG_INSTALLED_DIR": "${sourceDir}/externals"
1616
},
17+
"environment": {
18+
"VCPKG_FEATURE_FLAGS": "manifests,registries"
19+
},
1720
"debug": {
18-
"find": true
21+
"find": false
1922
}
2023
},
2124
{

readme.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
[![CMake](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/cmake.yml/badge.svg)](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/cmake.yml)
3-
[![Swift](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/swift.yml/badge.svg)](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/swift.yml)
2+
[![Build](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/build.yml/badge.svg)](https://github.com/luncliff/cpp-swift-experiment/actions/workflows/build.yml)
43

54
### References
65

@@ -16,8 +15,8 @@
1615

1716
### Setup
1817

19-
```bash
20-
pwsh setup-metal-cpp.ps1
18+
```powershell
19+
scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
2120
```
2221

2322
### Build

0 commit comments

Comments
 (0)