Skip to content

chore: make MeshCore portable for non-Apple builds - #498

Merged
Avi0n merged 2 commits into
devfrom
chore/meshcore-android-portability
Nov 20, 2026
Merged

Avi0n merged 2 commits into
devfrom
chore/meshcore-android-portability

Conversation

@Avi0n

@Avi0n Avi0n commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Written by an AI agent on behalf of @Avi0n.

Description

MeshCore on dev imports Apple-only system frameworks (os, CryptoKit, CommonCrypto, Network, and unguarded Synchronization) directly, so cross-compiling MeshCore for Android or Linux fails immediately and forces the multiplatform branch to carry recurring merge-conflicting shims across 30+ MeshCore/ files and root build files. Moving these behavior-neutral #if canImport(...) shims, sendVerifiedChannelMessage, and zero-conflict branch hooks onto dev keeps Apple behavior identical while allowing multiplatform to merge dev without conflicts.

Overview of Changes

  • Non-Apple shims & crypto fallback (MeshCore/):
    • Guarded os, CryptoKit, CommonCrypto, Network, and Synchronization imports behind #if canImport(...) across MeshCore/Sources/ and MeshCore/Tests/ (including SubmittedCommandWindow and WiFiTransportError handling in MeshCoreSession+TransportWrites.swift).
    • Added Compat/OSLogCompat.swift (Logger / OSSignposter sink with <private> redaction parity off Apple), Compat/OSAllocatedUnfairLock.swift, and Protocol/AES128ECBFallback.swift (per-block AES-CBC with zero IV via swift-crypto 5.0.0, linked only on .android, .linux, and .windows).
    • Added AES128ECBPortabilityTests and LogPrivacyTests pinning off-Apple behavior against the Apple CommonCrypto and os.Logger semantics.
  • Verified channel send (MeshCoreSession+ChannelSending.swift):
    • Added sendVerifiedChannelMessage(channel:text:timestamp:floodScope:expectedSecret:), which verifies channel occupancy with getChannel and sends within a single serialized command slot.
    • Added 5 unit tests in VerifiedChannelSendTests.swift covering unscoped send, flood-scoped send + baseline reset, secret mismatch rejection, notFound rejection, and cancellation before write.
  • Zero-conflict branch hooks & CI:
    • Added optional -include multiplatform/Makefile (and -h on help grep) in Makefile, MeshCoreBridge/.build excludes in .swiftlint.yml and .swiftformat, and radio-dev.env in .gitignore.
    • Added .github/workflows/meshcore-portability.yml to build --target MeshCore inside swift:6.2-noble when MeshCore/** changes on PRs to dev or main.

Details & Trade-offs

  • Apple builds (iOS / macOS) continue linking only Apple's system os, CryptoKit, CommonCrypto, Network, and Synchronization frameworks; swift-crypto 5.0.0 is gated by .when(platforms: [.android, .linux, .windows]).
  • WiFiTransport.swift and WiFiTransportTests.swift remain fenced with #if canImport(Network) and formatted normally under .swiftformat.
  • Local swiftformat is 0.64.7 (CI pins 0.64.5), so MeshCore/ was formatted and verified against .swiftformat without touching unrelated MC1/MC1Services files.
  • The new Linux CI workflow (.github/workflows/meshcore-portability.yml) has not run in GitHub Actions yet; it will execute on PR open. make test-app and make test-store were not run locally (simulator build + both SPM package suites ran instead).

ELI5

The shared radio protocol package previously failed to compile off Apple devices because it imported macOS/iOS logging, networking, and cryptography modules directly. This change wraps those imports in platform checks with non-Apple fallbacks and adds a small Linux build check on PRs, so the Android branch can share MeshCore directly from dev without carrying merge-conflicting patches.

Testing

Before (dev at 059bc163a)

PATH="$HOME/.swiftly/bin:$PATH" ANDROID_NDK_HOME="$HOME/Library/Android/sdk/ndk/30.0.16248370" swiftly run +6.4.0 swift build --package-path MeshCore --swift-sdk swift-6.4.0-RELEASE_android --triple aarch64-unknown-linux-android28 --target MeshCore

Exit code 1:

Building for debugging...
[Planning deferred tasks]
error: SwiftCompile normal aarch64 failed with a nonzero exit code. Command line:     cd /Users/nate/Developer/MeshCore/MeshCoreOne
    
/Users/nate/Developer/MeshCore/MeshCoreOne/MeshCore/Sources/MeshCore/Events/EventDispatcher.swift:2:8: error: no such module 'os'
  1 | import Foundation
  2 | import os
    |        `- error: no such module 'os'
  3 | 
  4 | private let dispatcherLogger = Logger(subsystem: "MeshCore", category: "EventDispatcher")
...
error: Build failed

After (chore/meshcore-android-portability at 5e838da56)

Android aarch64 cross-compile (EXIT_ARM64=0):

PATH="$HOME/.swiftly/bin:$PATH" ANDROID_NDK_HOME="$HOME/Library/Android/sdk/ndk/30.0.16248370" swiftly run +6.4.0 swift build --package-path MeshCore --swift-sdk swift-6.4.0-RELEASE_android --triple aarch64-unknown-linux-android28 --target MeshCore
[578/578] MeshCore
Build complete! (53.80 sec)
EXIT_ARM64=0

Android x86_64 cross-compile (EXIT_X64=0):

PATH="$HOME/.swiftly/bin:$PATH" ANDROID_NDK_HOME="$HOME/Library/Android/sdk/ndk/30.0.16248370" swiftly run +6.4.0 swift build --package-path MeshCore --swift-sdk swift-6.4.0-RELEASE_android --triple x86_64-unknown-linux-android28 --target MeshCore
[578/578] MeshCore
Build complete! (76.69 sec)
EXIT_X64=0

Package & iOS checks:

  • make help — exit 0, lists root targets cleanly without error when multiplatform/Makefile is absent.
  • make test-meshcore — exit 0, Test run with 596 tests in 74 suites passed after 11.585 seconds. (includes VerifiedChannelSendTests, AES128ECBPortabilityTests, LogPrivacyTests, WiFiTransportTests).
  • make test-services — exit 0, Test run with 2882 tests in 332 suites passed after 506.334 seconds.
  • make generate && xcodebuild build -project MC1.xcodeproj -scheme MC1 -destination "platform=iOS Simulator,name=iPhone 17e,OS=27.2" 2>&1 | xcsift -f toon — exit 0, status: success, errors: 0, warnings: 9, linker_errors: 0.
  • swiftformat --config .swiftformat --lint --strict MeshCore/ — exit 0, 0/166 files require formatting, 15 files skipped.
  • swiftlint lint --strict --config .swiftlint.yml MeshCore/ MC1Services/ MC1/ MC1Tests/ — exit 0, Done linting! Found 0 violations, 0 serious in 2188 files.

Tested on

  • iOS [version]
  • iPadOS [version]
  • macOS (package tests + Xcode iOS Simulator build + Android Swift 6.4.0 cross-compile)

Gate Apple-only frameworks (os, CryptoKit, CommonCrypto, Network, Synchronization) behind canImport checks, add cross-platform fallbacks, port sendVerifiedChannelMessage with tests, and add the Linux MeshCore build check and optional multiplatform Makefile include.
@Avi0n
Avi0n merged commit 2646049 into dev Nov 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant