Skip to content

specs: design for dropping Cgo on mobile (iOS purego, Android non-goal)#123

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

specs: design for dropping Cgo on mobile (iOS purego, Android non-goal)#123
changkun merged 1 commit into
mainfrom
design/mobile-remove-cgo

Conversation

@changkun

@changkun changkun commented Jun 6, 2026

Copy link
Copy Markdown
Member

Design spec only — no implementation — following the #118 precedent for the Linux design PR.

Summary

Completes the Cgo-removal track (darwin #117, Linux #120, BSD #121) for the two remaining mobile backends, after investigating both. The investigation produced a clean split on a single test: can the platform's clipboard backend function without importing a package that itself requires Cgo?

  • iOS — actionable. clipboard_ios.go imports no x/mobile package (UIPasteboard is process-global), and GOOS=ios CGO_ENABLED=0 go build std passes. Port it to the same purego/objc pasteboard binding shipped for darwin (darwin: remove the Cgo / C-toolchain dependency (purego) (#69) #117), retargeted to UIPasteboard; delete clipboard_ios.m. Simpler than darwin: text-only, no image, no TIFF, no Dlsym.
  • Android — non-goal, documented. The backend needs x/mobile/app.RunOnJVMmobileinit.RunOnJVMC.lockJNI (Cgo), and gomobile Android apps are -buildmode=c-shared via the NDK regardless. No source change; the spec records the full dependency analysis and rejects the purego-over-JNI alternative (churn, no toolchain win).

Notable findings

  • Silent-degradation bug (the one darwin: remove the CGO / C toolchain dependency #69 fixed on darwin) also affects both mobile targets today: under CGO_ENABLED=0, clipboard.go resolves to undefined: initialize/read/write/watch — neither a backend nor the graceful stubs link. The iOS port fixes it for iOS.
  • Latent use-after-free in clipboard_ios.m: return (char *)[str UTF8String] returns a pointer into autoreleased storage without copying. The purego port copies bytes out, with a regression test.
  • Benefit is scoped honestly: this removes Cgo from the library, not from a gomobile app (x/mobile's iOS scaffolding is itself Cgo). The spec spells out the library-vs-app distinction so the claim isn't overstated.

No open tracking issue exists for mobile (closed #8/#70); references the sibling #69/#25 and builds on #117.

@changkun changkun force-pushed the design/mobile-remove-cgo branch from 9404129 to 39ec2ca Compare June 6, 2026 22:17
@changkun changkun merged commit 9426912 into main Jun 6, 2026
7 checks passed
@changkun changkun deleted the design/mobile-remove-cgo branch June 6, 2026 22:34
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.

Android support

1 participant