Skip to content

build: 钉定宿主 Python 3.12,libsqlite3-sys 翻回上游 build script - #165

Merged
yesme merged 2 commits into
mainfrom
glm/python-pin-157
Sep 3, 2026
Merged

yesme merged 2 commits into
mainfrom
glm/python-pin-157

Conversation

@yesme

@yesme yesme commented Sep 3, 2026

Copy link
Copy Markdown
Owner

定位与重述

Issue #157:Buck2 2026-08-22 prelude 的 Cargo build-script C/C++ shim(from_any_dir.py)要求 Python ≥3.12(walk_up 参数),macOS 系统 Python 3.9.6 阻塞了 libsqlite3-sys 的上游 build script,仓库被迫手工复刻 20 个编译宏的 cxx_library 与 bindings 拷贝 genrule。本 PR 按所有者拍板(python-build-standalone 进供应链、钉死版本号)拆除该复刻:① 新增 cpython 3.12.14(20260901,install_only_stripped)三平台 DotSlash 清单;② src/buck2 启动器解析钉定解释器的绝对路径注入 hctl2.python config——实测证伪了 PATH 前置方案(Buck2 action 环境不含 PATH),也一并注入 hctl2.cc/cxx/ar 绝对编译器路径(from_any_dir 的 os.execl 不搜 PATH,裸名必然 ENOENT;macOS 取自动注 SDK 的 /usr/bin xcrun shim,Xcode.app 裸二进制缺 -isysroot 找不到 stdio.h——同趟证伪记录在研究文件);③ toolchains 读 config 覆盖 system 工具链裸名默认;④ libsqlite3-sys fixup 缩为 run=true + cargo_env(CARGO_MANIFEST_DIR,env! 编译期展开)+ OPT_LEVEL=2(cc-rs 运行期要求)+ rustc_link_lib/search(cargo:rustc-link-lib 翻译),删除全部手工复刻。编译宏回归 upstream build.rs,随版本升级不再漂移。本地 macOS arm64 验证:first-party 全套(139 命令)、foundation/tool 测试、docs 13 项、clippy、ShellCheck --severity=error 全绿;Linux x86_64 由 CI 矩阵验证。Closes #157。

当前生效约束集

  • Buck2 唯一构建入口;改动走 config 注入与 reindeer fixup 两个原生机制,不 patch prelude、不自建第二套版本表。
  • 三平台固定 rustc 1.98.0;钉定 Python 与编译器均为开发/CI 工具,不进用户发行包;最终用户运行环境不依赖 Python。
  • 已知代价(记入研究文件):注入的解释器绝对路径含 dotslash 缓存哈希,逐机不同 → buildscript 相关 action 跨机缓存不命中;C 编译/链接 action key 仍稳定。
  • libsqlite3-sys 0.38.2 / rusqlite bundled 特性集不变(bundled + bundled_bindings + cc),复核 SQLite bundled 策略与预编译库替代方案 #158 裁定维持 bundled 终态(PR docs(research): #158 复核裁定——维持 SQLite bundled 终态 #164)。

业界方案调研

对象文件 docs/research/build-tools/python-build-standalone.md(本 PR 新增):python-build-standalone 为 uv/rye 生态事实标准的预编译 CPython 来源,三平台制品 + 官方 SHA-256;含两个被证伪中间方案(PATH 前置、xcrun 工具链裸二进制)与四个连环阻塞的实证记录(python 版本 / os.execl PATH / env! 展开 / OPT_LEVEL / link-lib 翻译);两项 prelude 上游问题待报告(walk_up 未声明最低版本、execl 与 system 工具链裸名错配,上游 main 2026-09-04 检查仍未修)。fixup 机制引用 reindeer MANUAL 与 proc-macro2 既有先例;#158 关联裁定见 docs/research/libs/sqlite-online-backup.md 复核记录(PR #164)。

@yesme
yesme force-pushed the glm/python-pin-157 branch from 2a32ef4 to 079060a Compare September 3, 2026 22:57
Haibara AI added 2 commits September 4, 2026 07:07
… script

- Add python-build-standalone cpython 3.12.14 DotSlash manifest (host-bin/python3)
- src/buck2 resolves the pinned interpreter's absolute path and injects
  hctl2.python; also injects hctl2.cc/cxx/ar absolute compiler paths
  (os.execl in from_any_dir does not search PATH; /usr/bin xcrun shims
  keep SDK injection on macOS)
- toolchains read the configs to override bare system toolchain names
- libsqlite3-sys fixup: buildscript.run=true + cargo_env CARGO_MANIFEST_DIR
  + OPT_LEVEL=2 + rustc_link_lib/search; drop the hand-copied cxx_library
  (20 transcribed flags) and bindings genrule
- Closes #157
@yesme
yesme force-pushed the glm/python-pin-157 branch from 079060a to 78667d6 Compare September 3, 2026 23:07
@yesme
yesme merged commit 35eb8dd into main Sep 3, 2026
14 checks passed
yesme added a commit that referenced this pull request Sep 3, 2026
任务书三追加「#165 核验」三项(钉定解释器正反例、供应链摘要逐平台核对、buildscript
与 C 编译 action 的缓存代价),#164 不核;状态板加 3.8 待开工,#157/#158 记为 GLM
以 #164/#165 关闭;GLM 留下的两个 buck2-prelude 上游 issue 待报项记入延后与遗留,
报告要点指向 python-build-standalone.md。


Claude-Session: https://claude.ai/code/session_01ECQQojBHRugVZZWstqqGUt

Co-authored-by: Haibara AI <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
yesme added a commit that referenced this pull request Sep 3, 2026
GLM 在 #165 留下的两项上游报告已以所有者身份提交:meta/buck2#1490(walk_up 需
Python ≥ 3.12 未声明,建议 os.path.relpath)、#1491(os.execl 不搜 PATH 与
path_clang_tools 裸名错配,建议 shutil.which / os.execvp)。研究文件文末追加复核记录,
写明上游合入后再评估撤掉启动器的绝对路径注入;状态板延后与遗留对应条目改为已报。


Claude-Session: https://claude.ai/code/session_01ECQQojBHRugVZZWstqqGUt

Co-authored-by: Haibara AI <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@yesme

yesme commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

任务书三追加 · 对抗核验(Grok)

对象:本 PR(钉定宿主 Python 3.12,翻回上游 build script)。测试在 #168,不另开文档。

结论:修正。

钉定解释器和供应链锁成立。需要改的是「已知代价」的形状,以及启动器在钉失效时的回落。不是把 #165 推倒。

  1. 钉定解释器真的在用 — 维持机制,修正回落。PATH 前面放 exit 1 的假 python3 后,host-bin/python3 仍报 3.12.14,./buck2 test 仍注入 hctl2.python=.../host-bin/python3(本机 macOS arm64;test(build): audit pinned host Python and fail closed on a broken pin #168 把同一毒化加进 Code 三平台矩阵)。弄坏当前平台 digest,DotSlash 以 incorrect digest 失败。但启动器原文是 2>/dev/null || true:钉失效时不注入 config,悄悄回落宿主 python3。这与「不能悄悄回落到宿主 Python」相反。test(build): audit pinned host Python and fail closed on a broken pin #168 把启动器改成解析失败即退出。

  2. 供应链锁 — 维持。清单三平台 SHA-256 与 python-build-standalone 20260901 官方 release 资产 digest 一致(linux-gnu 72748da1…、darwin-arm64 81a359f1…、darwin-x86_64 65b195c9…)。本机 macOS arm64 注入 /usr/bin/clang / clang++ / ar;xcrun --find clang 才是 Xcode.app/Contents/Developer/Toolchains/.../usr/bin/clang。Linux 由 CI 矩阵用 command -v 解析绝对路径。

  3. 缓存代价 — 修正(不是推翻本 PR 的钉定)。研究文件写「解释器绝对路径含 dotslash 缓存哈希,只有 buildscript 跨机不命中,C 编译/链接 action key 仍稳定」。实测两处不符:

    • 注入的是 trampoline 的 sys.executable(worktree 绝对路径),不是 sys.prefix 下带缓存哈希的 python3.12。跨 worktree 不命中的原因是 worktree 路径。
    • SQLite 的 C 编译没有独立 Buck C 动作。它发生在 libsqlite3-sys-0.38-build-script-run 内部(命令以 trampoline python 开头)。不存在「只有 buildscript 重跑、C 编译命中」的分裂。

    清 buck-out 后同 worktree 重建:foundation 测试 100% cache hit(172/172),含该 buildscript-run——复核 SQLite bundled 策略与预编译库替代方案 #158「一次 C 编译由缓存摊薄」在同机同树成立。第二个 worktree 重建:cache hit 34%,libsqlite3-sys-0.38-build-script-run 为 Local,C 编译随它重跑——跨 worktree 不摊薄。复核 SQLite bundled 策略与预编译库替代方案 #158 的前提没有整棵塌掉,但「C 编译 action 独立且稳定」那句话不成立。复核记录已追加到 docs/research/build-tools/python-build-standalone.md。

不用另测的两项按任务书跳过:FTS5 / Online Backup 已由 #162 在三平台跑过;#164 只是研究文件复核记录。

yesme pushed a commit that referenced this pull request Sep 3, 2026
任务书三追加:核 #165 的钉定解释器、供应链锁与缓存代价。启动器在钉
失效时不再回落宿主 Python。结论写在 #165 评论。
yesme added a commit that referenced this pull request Sep 4, 2026
…#168)

* test(build): audit pinned host Python and fail closed on a broken pin

任务书三追加:核 #165 的钉定解释器、供应链锁与缓存代价。启动器在钉
失效时不再回落宿主 Python。结论写在 #165 评论。

* test(build): do not use PATH python3 inside the pin audit

CI poisons PATH to prove the pin; the audit helpers must call
/usr/bin/python3 so they are not the fake interpreter.

---------

Co-authored-by: Haibara AI <[email protected]>
@yesme
yesme deleted the glm/python-pin-157 branch September 10, 2026 05:06
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.

为 Buck2 Cargo build-script action 钉定 Python 3.12+ 工具链

1 participant