Skip to content

Commit 090321b

Browse files
authored
[1244] 修复goldfish的动态链接问题 (#4438)
1 parent 340b9a8 commit 090321b

3 files changed

Lines changed: 73 additions & 1 deletion

File tree

TeXmacs/plugins/goldfish/goldfish/goldfish/repl.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(liii base)
88
(scheme char)
99
) ;import
10-
(export goldfish-welcome goldfish-repl is-sicp-mode?)
10+
(export goldfish-welcome goldfish-repl)
1111
(begin
1212

1313
(define (goldfish-welcome)

devel/1244.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# [1244] 修复 macOS 上 goldfish 动态链接 Homebrew OpenSSL
2+
3+
## 相关文档
4+
5+
- [dddd.md](dddd.md)
6+
- [2092.md](2092.md) - goldfish 内置 libcurl/openssl3 的前置任务
7+
8+
## 任务相关的代码文件
9+
10+
- `xmake/requires.lua` - 本任务唯一改动文件
11+
12+
## 背景与根因
13+
14+
### 现象
15+
16+
macOS 上构建出的 goldfish 二进制动态链接了 Homebrew 的 OpenSSL:
17+
18+
```
19+
$ otool -L TeXmacs/plugins/goldfish/bin/goldfish
20+
/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib
21+
/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib
22+
...
23+
```
24+
25+
未安装 Homebrew openssl@3 的用户机器上,dyld 找不到这两个 dylib,
26+
goldfish 直接启动失败,Scheme 会话/LLM 等依赖 goldfish 的功能全部不可用。
27+
28+
### 根因
29+
30+
2092 之后 macOS 的 libcurl TLS 后端为 `openssl3`,但 `add_requires` 未限制
31+
其来源,xmake 默认优先解析系统包;装了 Homebrew openssl@3 的机器上
32+
pkg-config 能找到它,于是 `openssl3` 被解析为**系统动态库**而非 xmake
33+
源码静态构建,最终链进 goldfish 的 install name 指向
34+
`/opt/homebrew/opt/openssl@3/lib/`
35+
36+
Linux 不受此问题影响(发行版 OpenSSL 3 属系统标配),Windows 走
37+
SChannel 不依赖 OpenSSL,故修复限定 macOS。
38+
39+
## 修改
40+
41+
`xmake/requires.lua`:macOS 下用 `add_requireconfs` 强制 libcurl 依赖链上
42+
`openssl3` 以源码静态构建(`system = false`),不再解析 Homebrew
43+
系统包:
44+
45+
```lua
46+
if is_plat("macosx") then
47+
add_requireconfs("libcurl.openssl3", {system = false, override = true})
48+
add_requireconfs("cpr.libcurl.openssl3", {system = false, override = true})
49+
end
50+
```
51+
52+
## 如何测试
53+
54+
```bash
55+
# 重新配置并重建 goldfish(openssl3/libcurl 会以源码静态重建)
56+
xmake f -c --yes && xmake b -y goldfish-bin
57+
58+
# 检查链接库:不得出现 /opt/homebrew 下的 libssl/libcrypto
59+
otool -L TeXmacs/plugins/goldfish/bin/goldfish
60+
# 预期仅剩 /usr/lib/libz.1.dylib、/System/Library/Frameworks/*、
61+
# /usr/lib/libc++.1.dylib、/usr/lib/libSystem.B.dylib 等系统库
62+
63+
# 功能验证:HTTPS 请求返回 200
64+
TeXmacs/plugins/goldfish/bin/goldfish -e '(import (liii http)) (let ((r (http-get "https://liiistem.cn/"))) (display (number->string (r (quote status-code)))))'
65+
```

xmake/requires.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ end
3030
if not is_plat("wasm") then
3131
add_requires("libcurl", {system=false})
3232
end
33+
-- macOS:openssl3 默认会被 xmake 解析为 Homebrew 系统包(pkg-config 命中
34+
-- brew 的 openssl@3),goldfish 因此动态链接 /opt/homebrew 下的
35+
-- libssl/libcrypto.dylib,未装 brew 的用户机器无法启动。强制源码静态构建。
36+
if is_plat("macosx") then
37+
add_requireconfs("libcurl.openssl3", {system = false, override = true})
38+
add_requireconfs("cpr.libcurl.openssl3", {system = false, override = true})
39+
end
3340
if not is_plat("wasm") then
3441
-- cpr 默认 ssl=false,会导致 goldfish 的 libcurl 完全无法发起 HTTPS 请求
3542
-- (LLM 等 HTTPS 接口全部报 HTTP状态码为0),必须显式开启 ssl

0 commit comments

Comments
 (0)