From 72f440d889e30faad338a535e1ab7f9ed6f8cf7f Mon Sep 17 00:00:00 2001 From: Foti Dim Date: Sun, 22 Nov 2026 21:33:52 +0100 Subject: [PATCH 1/2] CI: typecheck the Apple sources on every pull request No workflow job built the darwin sources: the pull request checks are Windows, Linux, Android, Chrome and pana, so a Swift change was only verified by whoever ran it locally. That is how the guards added in #394 could reach review with nothing but a local typecheck behind them. Add a macOS job that downloads Flutter's macOS and iOS engine frameworks and typechecks the shared plugin sources against each: the files branch with #if os(...) and import FlutterMacOS or Flutter, so a single platform's module only proves that platform's branch. It also runs the three isolated Apple helpers (write ownership, discovery progress, central restoration ownership), which compile one source file each with counted assertions. --- .github/workflows/pull_request.yml | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a369b199..1524766b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,6 +20,47 @@ jobs: - run: cmake --build build/windows-tests --config Debug - run: ctest --test-dir build/windows-tests -C Debug --output-on-failure + apple: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + channel: stable + + # Nothing else builds the Apple sources. They are shared by iOS and macOS + # and import Flutter's macOS or iOS module behind `#if os(...)`, so each + # platform's branch is typechecked against its own engine framework. + - name: Download the Apple engine frameworks + run: flutter precache --macos --ios + + - name: Typecheck the Apple sources + run: | + set -euo pipefail + flutter_root="$(dirname "$(dirname "$(command -v flutter)")")" + engine="$flutter_root/bin/cache/artifacts/engine" + sources=(darwin/universal_ble/Sources/universal_ble/*.swift) + + xcrun swiftc -typecheck \ + -target "$(uname -m)-apple-macos10.15" \ + -sdk "$(xcrun --sdk macosx --show-sdk-path)" \ + -F "$engine/darwin-x64" \ + "${sources[@]}" + + xcrun swiftc -typecheck \ + -target arm64-apple-ios13.1 \ + -sdk "$(xcrun --sdk iphoneos --show-sdk-path)" \ + -F "$engine/ios/Flutter.xcframework/ios-arm64" \ + "${sources[@]}" + + # Each helper compiles one source file with counted checks; they are not + # part of the plugin build. + - name: Run the Apple helper tests + run: | + bash darwin/universal_ble/Tests/run_write_ownership_test.sh + bash darwin/universal_ble/Tests/run_discovery_progress_test.sh + bash darwin/universal_ble/Tests/run_central_restoration_owner_test.sh + test: runs-on: ubuntu-latest From 6a3a64c8e2a9a96cc0218a7f54cc80644ab33698 Mon Sep 17 00:00:00 2001 From: Foti Dim Date: Mon, 23 Nov 2026 12:06:05 +0100 Subject: [PATCH 2/2] CI: resolve the Apple engine layout by looking for the frameworks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The job failed twice on the runner. First the hosted SDK's engine directory existed without the macOS framework, so precache skipped the download. Then, once it did download, the framework turned out to be a slice inside FlutterMacOS.xcframework rather than a bare FlutterMacOS.framework beside the engine artifacts — and the directory is named after the host arch (darwin-x64, darwin-arm64). Move the typecheck into .github/scripts/typecheck_apple.sh, which locates the macOS framework in either layout under the arch-named directory, resolves the iOS flutter.xcframework/ios-arm64 slice, forces the precache download when either is missing, and prints the engine listing if they still are not found. The two workflow steps only call it, with --download-only for the fetch step. Verified locally against both layouts: the installed SDK's bare framework and a simulated runner tree with FlutterMacOS.xcframework/macos-arm64_x86_64. --- .github/scripts/typecheck_apple.sh | 79 ++++++++++++++++++++++++++++++ .github/workflows/pull_request.yml | 20 +------- 2 files changed, 81 insertions(+), 18 deletions(-) create mode 100755 .github/scripts/typecheck_apple.sh diff --git a/.github/scripts/typecheck_apple.sh b/.github/scripts/typecheck_apple.sh new file mode 100755 index 00000000..d04e08f4 --- /dev/null +++ b/.github/scripts/typecheck_apple.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# +# Typechecks the shared Apple plugin sources against the Flutter engine +# frameworks, once for macOS and once for iOS. The sources branch on +# `#if os(...)` and import FlutterMacOS or Flutter, so one platform's module +# only proves that platform's branch. +# +# Run by the `apple` job in .github/workflows/pull_request.yml. Pass +# --download-only to fetch the frameworks without typechecking. +# +# The engine layout differs between Flutter versions: the macOS framework can +# be a bare FlutterMacOS.framework beside the engine artifacts, or a slice +# inside FlutterMacOS.xcframework, and its directory is named after the host +# arch (darwin-x64, darwin-arm64). A cached SDK can also contain the directory +# without the framework, in which case `flutter precache` treats it as done and +# skips the download. So: look for the framework, force the download when it is +# missing, then use the path that was found. + +set -euo pipefail + +flutter_root="${FLUTTER_ROOT:-$(dirname "$(dirname "$(command -v flutter)")")}" +engine="$flutter_root/bin/cache/artifacts/engine" + +# Echoes the directory that holds the macOS FlutterMacOS.framework, else fails. +macos_framework_dir() { + local dir found + for dir in "$engine"/darwin-x64 "$engine"/darwin-arm64; do + [ -d "$dir" ] || continue + found="$(find "$dir" -maxdepth 3 -type d -name FlutterMacOS.framework -print -quit)" + if [ -n "$found" ]; then + dirname "$found" + return 0 + fi + done + return 1 +} + +# Echoes the directory that holds the iOS Flutter.framework, else fails. +ios_framework_dir() { + local xcframework="$engine/ios/Flutter.xcframework" found + [ -d "$xcframework" ] || return 1 + found="$(find "$xcframework" -maxdepth 2 -type d -name ios-arm64 -print -quit)" + [ -n "$found" ] || return 1 + printf '%s\n' "$found" +} + +have_frameworks() { + macos_framework_dir >/dev/null && ios_framework_dir >/dev/null +} + +flutter precache --macos --ios +if ! have_frameworks; then + flutter precache --force --macos --ios +fi +if ! have_frameworks; then + echo "Apple engine frameworks are missing under $engine" >&2 + find "$engine" -maxdepth 2 -type d -print | sed -n '1,20p' >&2 + exit 1 +fi + +if [ "${1:-}" = "--download-only" ]; then + exit 0 +fi + +macos_framework_dir="$(macos_framework_dir)" +ios_framework_dir="$(ios_framework_dir)" +sources=(darwin/universal_ble/Sources/universal_ble/*.swift) + +xcrun swiftc -typecheck \ + -target "$(uname -m)-apple-macos10.15" \ + -sdk "$(xcrun --sdk macosx --show-sdk-path)" \ + -F "$macos_framework_dir" \ + "${sources[@]}" + +xcrun swiftc -typecheck \ + -target arm64-apple-ios13.1 \ + -sdk "$(xcrun --sdk iphoneos --show-sdk-path)" \ + -F "$ios_framework_dir" \ + "${sources[@]}" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1524766b..087a25f6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -32,26 +32,10 @@ jobs: # and import Flutter's macOS or iOS module behind `#if os(...)`, so each # platform's branch is typechecked against its own engine framework. - name: Download the Apple engine frameworks - run: flutter precache --macos --ios + run: bash .github/scripts/typecheck_apple.sh --download-only - name: Typecheck the Apple sources - run: | - set -euo pipefail - flutter_root="$(dirname "$(dirname "$(command -v flutter)")")" - engine="$flutter_root/bin/cache/artifacts/engine" - sources=(darwin/universal_ble/Sources/universal_ble/*.swift) - - xcrun swiftc -typecheck \ - -target "$(uname -m)-apple-macos10.15" \ - -sdk "$(xcrun --sdk macosx --show-sdk-path)" \ - -F "$engine/darwin-x64" \ - "${sources[@]}" - - xcrun swiftc -typecheck \ - -target arm64-apple-ios13.1 \ - -sdk "$(xcrun --sdk iphoneos --show-sdk-path)" \ - -F "$engine/ios/Flutter.xcframework/ios-arm64" \ - "${sources[@]}" + run: bash .github/scripts/typecheck_apple.sh # Each helper compiles one source file with counted checks; they are not # part of the plugin build.