Skip to content

specs: correct mobile Cgo conclusion — iOS is not feasible either#127

Merged
changkun merged 1 commit into
mainfrom
design/mobile-remove-cgo-erratum
Jun 6, 2026
Merged

specs: correct mobile Cgo conclusion — iOS is not feasible either#127
changkun merged 1 commit into
mainfrom
design/mobile-remove-cgo-erratum

Conversation

@changkun

@changkun changkun commented Jun 6, 2026

Copy link
Copy Markdown
Member

Corrects the merged mobile Cgo spec (#123). Implementing #125 disproved its iOS conclusion.

What changed

The spec said iOS was actionable (purego/objc on UIPasteboard, mirroring darwin #117) and only Android stayed Cgo. That's wrong. iOS cannot drop Cgo either, for two independent reasons — both verified by attempting the implementation:

  1. purego forbids cgo-free iOS. purego/is_ios.go (ios && !cgo) is a deliberate compile-time tripwire (_PUREGO_REQUIRES_CGO_ON_IOS). Once the iOS backend imports purego/objc, GOOS=ios CGO_ENABLED=0 go build . fails to compile. Still true on latest (v0.10.1).
  2. Go's iOS port forces external (C) linking. Independent of our code — an empty func main(){} fails GOOS=ios CGO_ENABLED=0 go build with ios/arm64 requires external (cgo) linking. darwin (non-iOS) internal-links fine, which is exactly why darwin: remove the Cgo / C-toolchain dependency (purego) (#69) #117 worked and iOS can't.

Why the original check was a false positive

The spec's iOS proof was GOOS=ios CGO_ENABLED=0 go build std passing — but go build std compiles packages without linking and without pulling in purego, sidestepping both blockers. The erratum documents the correct check (build the real package with its FFI dep, and link a binary) as a lesson for future platform specs.

Result

Docs-only.

An implementation attempt for #125 disproved the spec's iOS conclusion.
iOS fails on two independent, unfixable-from-here blockers:

- purego refuses to build for ios under CGO_ENABLED=0 (is_ios.go tripwire),
  so the library cannot compile Cgo-free once it imports purego/objc.
- Go's iOS port forces external (C) linking; even an empty program fails
  'GOOS=ios CGO_ENABLED=0 go build'. No iOS artifact links without a C toolchain.

The original feasibility check ('go build std') was a false positive: it
compiles packages but never links and never pulls in purego. Corrected
conclusion: both iOS and Android keep Cgo; no source change.
@changkun changkun merged commit cc84b7a into main Jun 6, 2026
7 checks passed
@changkun changkun deleted the design/mobile-remove-cgo-erratum branch June 6, 2026 22:49
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