rastrillo / native Public

Clone
git clone https://amadan.net/rastrillo/native

Plain git — no account needed to clone.

Download

Download this file

1# Share Go logic with a native companion
2
3Use Go Mobile when the app already has useful Go logic to share. Keep the
4binding surface in a small package independent of HTTP handlers, the server
5bootstrap and UI. The app's normal Go module owns its engine and tool pins;
6Rastrillo Native does not make Go a dependency of Swift-only consumers.
7
8Install `gomobile` and `gobind` from the same reviewed `golang.org/x/mobile`
9revision, record that revision in the app's build configuration, and run
10`gomobile init`. Keep that module in the engine's dependency graph as well.
11Do not silently update a binding tool during a release build.
12
13From the engine module, with its exported binding package at `./mobile`:
14
15```sh
16gomobile bind -target=ios,iossimulator,macos -o AppEngine.xcframework ./mobile
17gomobile bind -target=android -o appengine.aar ./mobile
18```
19
20Apple builds need macOS and Xcode. Android builds need the Java toolchain,
21Android SDK and NDK. Use `gomobile help bind` from the pinned toolchain for
22its supported targets and flags. Import the XCFramework in the Apple app
23and the AAR in the Android app; UI and lifecycle remain platform code.
24
25These are integration recipes, not outputs validated by this package's CI.
26Before adopting a bridge, compile it for each supported target and exercise
27it through Swift/Kotlin, including errors, callbacks and cancellation.
28
29Only a subset of Go types can cross bindings. Prefer a small API carrying
30strings, numbers and byte slices; keep complex internal types behind it.
31Specify who owns callback lifetimes and which thread receives them, avoid
32blocking the UI thread, and batch work where repeated crossings are costly.
33Browser clients can keep a WebCrypto or JavaScript implementation pinned by
34the same test vectors. Neither a Swift package nor a mobile binding makes
35the web client use the Go engine automatically.
36
37Source: [Go Mobile command documentation](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile)
38and [Go Mobile binding model](https://go.dev/wiki/Mobile).
39