diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index a554eab..c697686 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -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: @@ -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: @@ -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: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0dbdad9 --- /dev/null +++ b/.github/workflows/build.yml @@ -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" diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml deleted file mode 100644 index 54b0a54..0000000 --- a/.github/workflows/cmake.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: "CMake" - -on: - push: - branches: ["**"] - pull_request: - branches: ["**"] - workflow_dispatch: - -env: - VCPKG_FEATURE_FLAGS: "manifests,binarycaching" - -jobs: - macos12: - runs-on: macos-12 - steps: - - uses: actions/checkout@v4 - - uses: swift-actions/setup-swift@v1.25.0 - with: - swift-version: "5.9.0" - - name: "Setup Metal-cpp" - run: | - ./setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS13.3_iOS16.4.zip" - shell: pwsh - - uses: lukka/run-vcpkg@v11.4 - with: - vcpkgDirectory: "/usr/local/share/vcpkg" # $VCPKG_INSTALLATION_ROOT - vcpkgGitCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00 # 2023.12.12 - vcpkgJsonGlob: "${{ github.workspace }}/vcpkg.json" - runVcpkgInstall: true - - uses: lukka/run-cmake@v10.7 - with: - configurePreset: "x64-osx" - buildPreset: "x64-osx-debug" - testPreset: "x64-osx-debug" - - macos13: - runs-on: macos-13 - steps: - - uses: actions/checkout@v4 - - uses: swift-actions/setup-swift@v1.25.0 - with: - swift-version: "5.9.0" - - name: "Setup Metal-cpp" - run: | - ./setup-metal-cpp.ps1 -Folder "externals" -FileName "metal-cpp_macOS14.2_iOS17.2.zip" - shell: pwsh - - uses: lukka/run-vcpkg@v11.4 - with: - vcpkgDirectory: "/usr/local/share/vcpkg" # $VCPKG_INSTALLATION_ROOT - vcpkgGitCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00 # 2023.12.12 - vcpkgJsonGlob: "${{ github.workspace }}/vcpkg.json" - runVcpkgInstall: true - - uses: lukka/run-cmake@v10.7 - with: - configurePreset: "x64-osx" - buildPreset: "x64-osx-debug" - testPreset: "x64-osx-debug" diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml deleted file mode 100644 index b7a191f..0000000 --- a/.github/workflows/swift.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "Swift" - -on: - push: - branches: ["**"] - pull_request: - branches: ["**"] - -jobs: - swiftpm: - runs-on: macos-13 - steps: - - uses: actions/checkout@v4 - - uses: mobiledevops/xcode-select-version-action@v1 - with: - xcode-select-version: "15.0.1" - - uses: swift-actions/setup-swift@v1.25.0 - with: - swift-version: "5.9.0" - - uses: ConorMacBride/install-package@v1.1.0 - with: - brew: swiftlint - - name: "Setup Metal-cpp" - run: | - ./setup-metal-cpp.ps1 - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d2cce..18aabb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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}) diff --git a/CMakePresets.json b/CMakePresets.json index e82d618..3ae2fee 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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 } }, { diff --git a/readme.md b/readme.md index 91eb6a4..fd585b7 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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 diff --git a/scripts/setup-metal-cpp.ps1 b/scripts/setup-metal-cpp.ps1 new file mode 100644 index 0000000..0b66afd --- /dev/null +++ b/scripts/setup-metal-cpp.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS + Script to download and extract Metal-cpp sources +.DESCRIPTION + Download sources from https://developer.apple.com/metal/cpp/ and extract them to the designated folder + +.EXAMPLE + PS> ./setup-metal-cpp.ps1 -Folder "externals" +#> +using namespace System +param +( + [String]$Folder = "externals", + [String]$FileName = "metal-cpp_macOS15.2_iOS18.2.zip" +) + +$Candidates = @( + "metal-cpp_macOS15.2_iOS18.2.zip", + "metal-cpp_macOS15_iOS18.zip", + "metal-cpp_macOS15_iOS18-beta.zip", + "metal-cpp_macOS14.2_iOS17.2.zip", + "metal-cpp_macOS14_iOS17-beta.zip", + "metal-cpp_macOS13.3_iOS16.4.zip", + "metal-cpp_macOS13_iOS16.zip", + "metal-cpp_macOS12_iOS15.zip" +) +if ($Candidates -notcontains $FileName) { + Write-Warning "The '$FileName' is not recognized. Please check the file exists in https://developer.apple.com/metal/cpp/" + Write-Host "The known values are: $($Candidates -join ', ')" +} + +# Download if not exists +if ($(Test-Path -Path $FileName) -eq $false) { + [Uri]$Remote = "https://developer.apple.com/metal/cpp/files/${FileName}" + Invoke-WebRequest -Uri $Remote -OutFile $FileName +} + +# Overwrite existing files +Expand-Archive -Path $FileName -DestinationPath $Folder -Force diff --git a/setup-metal-cpp.ps1 b/setup-metal-cpp.ps1 deleted file mode 100644 index 5ba5d96..0000000 --- a/setup-metal-cpp.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -<# -.SYNOPSIS - Script to download and extract Metal-cpp sources -.DESCRIPTION - Download sources from https://developer.apple.com/metal/cpp/ and extract them to "externals/" folder - -.EXAMPLE - PS> ./setup-metal-cpp.ps1 -Folder "externals" -#> -using namespace System -param -( - [String]$Folder = "externals", - [String]$FileName = "metal-cpp_macOS13_iOS16.zip" -) - -# Download if not exists -if ($(Test-Path -Path $FileName) -eq $false) { - [Uri]$Remote = "https://developer.apple.com/metal/cpp/files/${FileName}" - Invoke-WebRequest -Uri $Remote -OutFile $FileName -} - -# Overwrite existing files -Expand-Archive -Path $FileName -DestinationPath $Folder -Force diff --git a/sonar-project.properties b/sonar-project.properties index 73efcb2..2dedd65 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,7 +4,7 @@ sonar.organization=luncliff-github sonar.projectKey=luncliff_cpp-swift-experiment sonar.projectName=cpp-swift-experiment -sonar.projectVersion=1.2 +sonar.projectVersion=1.3 sonar.sourceEncoding=UTF-8 diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..d262199 --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-configuration.schema.json", + "default-registry": { + "kind": "git", + "repository": "https://github.com/microsoft/vcpkg", + "reference": "2025.03.19", + "baseline": "b02e341c927f16d991edbd915d8ea43eac52096c" + }, + "registries": [] +} \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 4384a8e..e42c911 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,12 +1,16 @@ { - "name": "cpp-swift-experiment", - "version-string": "1.1", - "description": "Experiment project for Mac/iPhone library with C++/Swift Programming Language", - "dependencies": [ - "protobuf", - { - "name": "protobuf", - "host": true - } - ] -} \ No newline at end of file + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "cpp-swift-experiment", + "version-date": "2025-04-08", + "description": "Experiment project for Mac/iPhone library with C++/Swift Programming Language", + "homepage": "https://github.com/luncliff/cpp-swift-experiment", + "license": "CC0-1.0", + "supports": "osx | ios", + "dependencies": [ + "protobuf", + { + "name": "protobuf", + "host": true + } + ] +}