Skip to content

[Bug] 桌面端 Core 构建在固定检出与 LITHE_CORE_RUST_DIR 之间切换后,继续暂存并链接上一份 Core 的静态库 #1922

Closed

Description

@xiaoyumuxi

Platform / 平台

macOS

Area / 模块

Other / 其他

Lithe version / Lithe 版本

preview 059d878(桌面端构建脚本 scripts/desktop/build-desktop-core.sh,只影响本地开发构建)

Priority / 优先级

P2 / 后续考虑:目前不着急,可安排到后续版本

OS and architecture / 操作系统与架构

macOS 27.3, Apple Silicon (arm64)

Environment / 环境信息

rustc 1.96.0 (ac68faa20 2026-05-25)
cargo 1.96.0 (30a34c682 2026-05-25)
Other: Viva 桌面端本地构建,scripts/desktop/desktop-go.sh 调用 scripts/desktop/build-desktop-core.sh 暂存 Core 静态库。CI 每次都是全新检出固定提交,不受影响;Windows Git Bash 走同一个脚本,未在 Windows 上复现。

Steps to reproduce / 复现步骤

  1. 在一个桌面端工作树里,不设置 LITHE_CORE_RUST_DIR,运行 scripts/desktop/desktop-go.sh test ./internal/core,构建并暂存固定提交的 Core。
  2. 准备一个 Lithe-core-rust 本地检出,其中有固定提交里没有的改动(例如新增的 Core 命令),且这些 rust/ 文件的修改时间早于第 1 步的构建(例如更早建好的分支检出)。
  3. 运行 LITHE_CORE_RUST_DIR=<CORE_CHECKOUT> scripts/desktop/desktop-go.sh test ./internal/core。
  4. 反方向同样成立:先用本地检出构建,再去掉 LITHE_CORE_RUST_DIR,固定检出的提交没变时不会被重新编译。

Expected behavior / 预期行为

切换 Core 来源(固定提交 ↔ LITHE_CORE_RUST_DIR 本地检出,或换另一个本地检出)后,暂存的 liblithe_core.a 和 lithe-mcp 由当前来源编译。docs/ci-builds.md “独立工作树的本地编译”一节也写着:“固定提交变了或本地检出改了都不会继续链接旧库”。

Actual behavior / 实际行为

Cargo 认为当前来源已是最新,没有编译就结束;暂存目录 .artifacts/desktop/lithe-core/<target>/<profile>/lib/liblithe_core.a 仍是上一份来源的库,桌面端继续链接旧 Core。identity.txt 却按当前来源写入 core-revision 和 core-source,看不出库和身份记录不一致。

在 HTML 预览联调中遇到:本地检出里新增的 Core 命令在桌面端测试中不存在,只有 touch 该检出中改动过的 .rs 文件后重新构建才恢复。

初步诊断(下方日志用最小 Cargo 工作区复现了这一机制):build-desktop-core.sh 第 110–112 行让固定检出和 LITHE_CORE_RUST_DIR 共用同一个 CARGO_TARGET_DIR(.artifacts/desktop/lithe-core-rust/target)。两份检出是同一个 workspace,成员 crate 相对 workspace 根的路径相同,Cargo 把它们当作同一组编译单元,只比较源文件修改时间和上次构建的时间;另一份检出的文件更旧时就判定无需重编,target/<profile>/ 下的库也不会被替换。

建议方案(待评估):两种来源不共用 Cargo 目标目录。例如固定检出保留 lithe-core-rust/target/,本地检出改用按检出路径区分的目录(如 lithe-core-rust/override-target/<路径摘要>/),同时更新 scripts/resources/worktree-resources.json 的 viva-core-build-state 路径和 docs/ci-builds.md 对应段落。代价是本地检出第一次构建需要完整编译,并多占一份数 GB 的目标目录。另一种做法是在目标目录记录上次构建的检出路径,路径变化时清理 workspace 成员的编译产物。

Logs or diagnostic output / 日志或诊断输出

# 两份同名 workspace(a、b),共用一个 CARGO_TARGET_DIR;b 的文件时间更早
# a/rust/crates/core/src/lib.rs: #[no_mangle] pub extern "C" fn which() -> u32 { 1111 }
# b/rust/crates/core/src/lib.rs: #[no_mangle] pub extern "C" fn which() -> u32 { 2222 }   (touch -t 202601010000)
$ export CARGO_TARGET_DIR=$REPRO/target
$ cargo build -q --manifest-path $REPRO/a/rust/Cargo.toml
$ cargo build --manifest-path $REPRO/b/rust/Cargo.toml
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
$ objdump -d demo_core-*.rcgu.o   # 从 $REPRO/target/debug/libdemo_core.a 解出
       0: 52808ae0     	mov	w0, #0x457              ; =1111
# 构建 b 之后,静态库里仍是 a 的代码(1111),不是 b 的 2222

Screenshots or recordings / 截图或录屏

不适用(命令行构建问题,没有界面)

Checklist / 提交前检查

  • I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复报告。
  • I removed secrets and personal data from the report. / 我已从报告中移除敏感信息和个人数据。

Activity

  1. added
    review: high
    on Nov 14, 2026
  2. added
    bug
    P2
    platform:macos
    on Nov 14, 2026
  3. 1lck commented on Nov 21, 2026

    @1lck
    Owner

    在 Apple Silicon macOS 上用 desktop-v0.8.13 的构建脚本复测通过。复测用两份同结构的最小 Cargo 工作区代替真实 Core 检出,两份源码的修改时间都早于首次构建,共用脚本指定的 Cargo 编译目录。

    按固定检出 → LITHE_CORE_RUST_DIR → 固定检出切换,每次都实际链接并运行暂存的 liblithe_core.a,也运行了暂存的 lithe-mcp。两份产物均依次返回各自来源的标记 1111 → 2222 → 1111,和 identity.txt 记录一致。再次使用固定检出构建,产物仍对应固定来源。

    修复随 #1945 合入,构建脚本在检出路径变化时清理 Cargo 工作区成员后重编。这个回归场景已验证,关闭此 Issue。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:otherbugplatform:macosreview: high

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions