Skip to content
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
39 changes: 30 additions & 9 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: "Analysis"

on: [push, pull_request, workflow_dispatch]
on:
push:
branches-ignore:
- docs
pull_request:
branches: ["main"]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
sonarcloud:
Expand All @@ -12,21 +22,29 @@ jobs:
fetch-depth: 0
- uses: mobiledevops/xcode-select-version-action@v1
with:
xcode-select-version: "15.1"
xcode-select-version: "15.2.0"
- uses: swift-actions/setup-swift@v2
with:
swift-version: "5.9.2"
- uses: ConorMacBride/install-package@v1.1.0
with:
brew: ninja
- uses: SonarSource/sonarcloud-github-c-cpp@v2
- uses: SonarSource/sonarcloud-github-c-cpp@v3.2.0

- name: "Run setup-metal-cpp.ps1"
run: ./setup-metal-cpp.ps1
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
shell: pwsh

- uses: lukka/run-vcpkg@v11.4
- uses: lukka/get-cmake@v4.0.0
with:
cmakeVersion: "3.31"

- uses: lukka/run-vcpkg@v11.5
with:
vcpkgDirectory: "/usr/local/share/vcpkg" # $VCPKG_INSTALLATION_ROOT
vcpkgGitCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00 # 2023.12.12
vcpkgJsonGlob: "${{ github.workspace }}/vcpkg.json"
vcpkgDirectory: "${{ runner.tool_cache }}/vcpkg"
vcpkgGitCommitId: b02e341c927f16d991edbd915d8ea43eac52096c # 2025.03.19
vcpkgJsonGlob: "**/vcpkg.json"
vcpkgConfigurationJsonGlob: "**/vcpkg-configuration.json"
runVcpkgInstall: true
- uses: lukka/run-cmake@v10.7
with:
Expand Down Expand Up @@ -60,14 +78,17 @@ jobs:
- name: "Run xccov-to-sonarqube-generic.sh"
id: xcresult
run: |
# xcrun --show-sdk-path
xcresult_path=$(find DerivedData/Logs/Test/ -maxdepth 1 -name "Test*.xcresult" | tail -n 1)
echo "path=$xcresult_path" >> "$GITHUB_OUTPUT"
echo "path=$(pwd)/xcresult_path" >> "$GITHUB_OUTPUT"
bash ./scripts/xccov-to-sonarqube-generic.sh $xcresult_path > docs/coverage.xml
shell: bash

- uses: kishikawakatsumi/xcresulttool@v1.7.1
continue-on-error: true
with:
path: "${{ steps.xcresult.outputs.path }}"
upload-bundles: 'failure'

- name: "Run xcrun(llvm-cov)"
run: |
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# References
#
# - https://swiftversion.net
# - https://github.com/actions/runner-images/tree/main/images/macos
# - https://developer.apple.com/documentation/xcode-release-notes
#
name: "Build"

on:
push:
branches-ignore:
- docs
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
swiftpm:
name: "Swift Package Manager"
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- uses: mobiledevops/xcode-select-version-action@v1
with:
xcode-select-version: "15.2.0"
- uses: swift-actions/setup-swift@v2
with:
swift-version: "5.9.2"
- uses: ConorMacBride/install-package@v1.1.0
with:
brew: swiftlint
- name: "Run setup-metal-cpp.ps1"
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
shell: pwsh
- name: "Swift Build(Debug)"
run: swift build --configuration debug # --verbose --target ...
- name: "Swift Build(Release)"
run: swift build --configuration release
- name: "Swift Test"
run: swift test --verbose --enable-code-coverage
- name: "Swift Lint"
run: swiftlint lint --output docs/lint.md --reporter markdown # --autocorrect

cmake:
name: "CMake"
runs-on: macos-13
env:
VCPKG_FEATURE_FLAGS: "manifests,binarycaching,registries"
steps:
- uses: actions/checkout@v4
- uses: swift-actions/setup-swift@v2
with:
swift-version: "5.9.2"
- name: "Run setup-metal-cpp.ps1"
run: scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
shell: pwsh
- uses: lukka/get-cmake@v4.0.0
with:
cmakeVersion: "3.31"
- uses: lukka/run-vcpkg@v11.5
with:
vcpkgDirectory: "${{ runner.tool_cache }}/vcpkg"
vcpkgGitCommitId: b02e341c927f16d991edbd915d8ea43eac52096c # 2025.03.19
vcpkgJsonGlob: "**/vcpkg.json"
vcpkgConfigurationJsonGlob: "**/vcpkg-configuration.json"
runVcpkgInstall: true
- uses: lukka/run-cmake@v10.7
with:
configurePreset: "x64-osx"
buildPreset: "x64-osx-debug"
testPreset: "x64-osx-debug"
58 changes: 0 additions & 58 deletions .github/workflows/cmake.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/swift.yml

This file was deleted.

63 changes: 37 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
# see https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
cmake_minimum_required(VERSION 3.28)
project(cpp_swift_bridges LANGUAGES CXX VERSION 1.2)
cmake_minimum_required(VERSION 3.31)
project(cpp_swift_bridges LANGUAGES CXX VERSION 1.3)

include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 20)

message(STATUS "Using system: ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID}")
if(APPLE)
set(CMAKE_Swift_LANGUAGE_VERSION 5)
find_program(CMAKE_Swift_COMPILER NAMES swiftc REQUIRED)
enable_language(Swift)
# set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
# if(ENABLE_COVERAGE)
# add_compile_options(-Wextra -ftest-coverage -fprofile-arcs)
# add_link_options(-ftest-coverage -fprofile-arcs)
# endif()
message(STATUS "Using swiftc: ${CMAKE_Swift_COMPILER}")

set(SWIFT_VERSION "5.0" CACHE STRING "Swift language version. 5.0 or 6.0")
if(CMAKE_GENERATOR MATCHES "Xcode")
set(CMAKE_XCODE_ATTRIBUTE_SWIFT_VERSION "${SWIFT_VERSION}")
elseif(CMAKE_GENERATOR MATCHES "Ninja")
# ...
endif()
endif()
message(STATUS "Using system: ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID}")

if(CMAKE_TOOLCHAIN_FILE MATCHES vcpkg.cmake)
message(STATUS "Using vcpkg: ${VCPKG_TARGET_TRIPLET}")
if(ENABLE_COVERAGE)
add_compile_options(-Wextra -ftest-coverage -fprofile-arcs)
add_link_options(-ftest-coverage -fprofile-arcs)
endif()

find_library(BORINGSSL_LIBPATH NAMES boringssl REQUIRED)
message(STATUS "using BoringSSL: ${BORINGSSL_LIBPATH}")
message(STATUS "Using BoringSSL: ${BORINGSSL_LIBPATH}")

find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protoc:")
message(STATUS " ${Protobuf_LIBRARY}")
message(STATUS " ${Protobuf_PROTOC_EXECUTABLE}")
find_package(Protobuf REQUIRED)
if(NOT DEFINED Protobuf_PROTOC_EXECUTABLE)
find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED)
endif()
message(STATUS "Using protoc: ${Protobuf_PROTOC_EXECUTABLE}")

find_path(MetalCpp_INCLUDE_DIR
NAMES "Metal/Metal.hpp"
PATHS ${PROJECT_SOURCE_DIR}/externals/metal-cpp
REQUIRED
)
message(STATUS "using Metal/Metal.hpp: ${MetalCpp_INCLUDE_DIR}")
message(STATUS "Using Metal.hpp: ${MetalCpp_INCLUDE_DIR}")

list(APPEND ifcs
src/Baguette.h
Expand Down Expand Up @@ -72,24 +74,33 @@ PUBLIC

target_link_libraries(BaguetteBridge
PUBLIC
"-framework Foundation"
"-framework Foundation" "-framework Metal"
${BORINGSSL_LIBPATH}
)

list(APPEND SWIFT_SRCS
platform-apple/AsyncRoutines.swift
platform-apple/BaguetteBridge.swift
platform-apple/CryptoRoutines.swift
platform-apple/DecoderRoutines.swift
platform-apple/HostInfo.swift
)
set_source_files_properties(${SWIFT_SRCS}
PROPERTIES
LANGUAGE Swift
COMPILE_OPTIONS "SHELL:-swift-version ${SWIFT_VERSION}"
)

target_sources(BaguetteBridge
PRIVATE
src/bridge_apple.cpp
${SWIFT_SRCS}
src/swift_crypto.cpp
src/swift_crypto.hpp
src/swift_decoder.cpp
src/swift_decoder.hpp
src/swift_hostinfo.hpp
src/swift_hostinfo.cpp
platform-apple/AsyncRoutines.swift
platform-apple/BaguetteBridge.swift
platform-apple/CryptoRoutines.swift
platform-apple/DecoderRoutines.swift
platform-apple/HostInfo.swift
)

install(TARGETS BaguetteBridge FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down
9 changes: 6 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"name": "vcpkg-find",
"hidden": true,
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"environment": {
"VCPKG_FEATURE_FLAGS": "manifests",
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": "",
"VCPKG_INSTALLED_DIR": "${sourceDir}/externals"
},
"environment": {
"VCPKG_FEATURE_FLAGS": "manifests,registries"
},
"debug": {
"find": true
"find": false
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

[![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)
[![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)
[![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)

### References

Expand All @@ -16,8 +15,8 @@

### Setup

```bash
pwsh setup-metal-cpp.ps1
```powershell
scripts/setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS15_iOS18.zip"
```

### Build
Expand Down
Loading
Loading