Skip to content

Commit 4c156ae

Browse files
author
yiguo
committed
Document single Go runtime limitation
1 parent d0ab60a commit 4c156ae

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,29 @@ use [gomobile](https://github.com/golang/mobile) .
7272

7373
### iOS && macOS
7474

75+
> [!WARNING]
76+
> **Use only one Go runtime per process.** Go does not support loading multiple
77+
> independently built Go runtimes into one process. Both the cgo and gomobile
78+
> Apple artifacts embed a Go runtime. Do not link `LibXray.xcframework`
79+
> together with another independently built Go or gomobile framework into the
80+
> same app or extension executable. Doing so can fail at link time or crash
81+
> during runtime initialization, before application code or
82+
> `NEPacketTunnelProvider` runs.
83+
> If one process needs Go packages from several frameworks, include those
84+
> packages in the same Go build or `gomobile bind` invocation and produce one
85+
> framework so they share a runtime. Merely repackaging or merging independently
86+
> built frameworks is not sufficient. The containing app and a Network
87+
> Extension are separate processes, so apply this rule independently to each
88+
> target. See [Go #18976](https://github.com/golang/go/issues/18976#issuecomment-308505600),
89+
> [x/mobile #15956](https://github.com/golang/go/issues/15956#issuecomment-373709423),
90+
> and [libXray #116](https://github.com/XTLS/libXray/issues/116).
91+
7592
#### 1. use gomobile
7693

7794
Need "iOS Simulator Runtime".
7895

79-
This is the best choice for general scenarios and will not conflict with other frameworks.
96+
This is the best choice for general scenarios. The single-runtime restriction
97+
above still applies when linking other Go-based frameworks.
8098

8199
Supports iOS, iOSSimulator, macOS, macCatalyst.
82100

‎readme/README.zh_CN.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,26 @@ python3 build/main.py windows local
4040

4141
### iOS && macOS
4242

43+
> [!WARNING]
44+
> **每个进程只能使用一个 Go runtime。** Go 不支持在同一进程中加载多个独立构建的
45+
> Go runtime。cgo 和 gomobile 生成的 Apple 产物都会嵌入 Go runtime。不要在同一个
46+
> App 或 Extension 可执行文件中同时链接 `LibXray.xcframework` 与另一个独立构建的
47+
> Go 或 gomobile framework,否则可能在链接阶段失败,或在 runtime 初始化阶段崩溃,
48+
> 甚至早于应用代码或 `NEPacketTunnelProvider` 执行。如果同一进程需要多个
49+
> framework 中的 Go package,应将这些 package 放入同一次 Go build 或
50+
> `gomobile bind` 并生成一个 framework,
51+
> 使其共享一个 runtime。仅重新打包或合并已经独立构建的 frameworks 并不能解决问题。
52+
> 宿主 App 与 Network Extension 是不同进程,因此需要分别对每个 target 遵守这一限制。
53+
> 参见 [Go #18976](https://github.com/golang/go/issues/18976#issuecomment-308505600)、
54+
> [x/mobile #15956](https://github.com/golang/go/issues/15956#issuecomment-373709423)
55+
> 和 [libXray #116](https://github.com/XTLS/libXray/issues/116)。
56+
4357
#### 1. 使用 gomobile
4458

4559
需要 “iOS Simulator Runtime”。
4660

47-
这是常规场景下的最佳选择,不会与其他 frameworks 冲突。
61+
这是常规场景下的最佳选择;与其他基于 Go 的 framework 同时集成时,仍须遵守上方的
62+
单 runtime 限制。
4863

4964
支持 iOS,iOSSimulator,macOS,macCatalyst。
5065

0 commit comments

Comments
 (0)