cmux-tui: a new build stamp no longer recompiles cmux-tui-core

Merged
LA
17d ago
+82-23

Summary

cmd_server.rs in cmux-tui-core read CMUX_TUI_BUILD_COMMIT, CMUX_MUX_BUILD_COMMIT and CMUX_TUI_GHOSTTY_COMMIT with option_env!. rustc records these in dep-info, so every new build stamp recompiled cmux-tui-core and, through it, cmux-remote.

Now only the binary crate reads the stamp at compile time:

  • cmux-tui-core/src/server/daemon_build.rs: a new BuildStamp in a OnceLock, set by install_build_stamp (first call wins). The stamped_build_commit() and stamped_ghostty_commit() functions read it.
  • cmux-tui/src/main.rs: build_stamp() reads the env values in the same order as before (TUI, then MUX; an empty value counts as no stamp). main() installs it as its first step after the link-token take, before any mode can serve identify or ping. version_string() reads the same build_stamp().
  • A mux that runs without an installed stamp (core tests, embedders) reports null, which is what an unstamped build reported before.

cmux-relay has the same pattern, but it is not in the cmux-tui bin graph (it is only a dev-dependency of cmux-remote), so this PR does not change it.

Proof (Blacksmith Testbox, 32 vCPU, cargo build -v -p cmux-tui --bin cmux-tui --locked)

Stamps A=aaaa… and B=bbbb… (40 hex), ghostty cccc…. The same tree for each pair.

Pool Linux twin settings (CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0, CMUX_TUI_DISTRIBUTION_VERSION and CMUX_GIT_SHORT_SHA follow the stamp), --timings:

stamp changewallcmux-tui-core
beforeA to B51.5 sCompiling, 39.0 s
beforeB to A52.5 sCompiling, 39.5 s
afterA to B32.9 sFresh
afterB to A32.5 sFresh

After the change these units still rebuild for each new stamp: cmux-tui (18.4 s), acpmux (16.7 s, from CMUX_GIT_SHORT_SHA/SOURCE_DATE_EPOCH), cmux-remote (9.6 s, from CMUX_TUI_DISTRIBUTION_VERSION in ssh_bootstrap.rs), and the cmux-build-identity build script. Those are not in this PR.

Incremental dev profile, only the commit and ghostty stamps changed: before, the build compiled cmux-build-identity, cmux-remote, cmux-tui-core and cmux-tui. After, it compiled only cmux-build-identity and cmux-tui, and every library was Fresh.

Readers, after the change, through a real headless daemon socket (identify and ping) and --version. The values are identical to the before-change binary with the same stamp:

after-A --version: cmux 0.1.0 (aaaa…aaaa; ghostty cccc…cccc)
  identify: build_commit=aaaa…aaaa ghostty_commit=cccc…cccc build_id=aaaa…aaaa
  ping:     build_commit=aaaa…aaaa ghostty_commit=cccc…cccc
after-B --version: cmux 0.1.0 (bbbb…bbbb; ghostty cccc…cccc)
  identify: build_commit=bbbb…bbbb ghostty_commit=cccc…cccc build_id=bbbb…bbbb
  ping:     build_commit=bbbb…bbbb ghostty_commit=cccc…cccc

The A and B binaries (after the change) have the same size (1183893440 bytes). Of the 380 differing bytes, 360 are in the 9 stamp strings. The other 20 are the ELF .note.gnu.build-id hash (offset 812-831; section at 0x31c).

Tests

  • cargo fmt --check -p cmux-tui-core -p cmux-tui: ok
  • cargo test -p cmux-tui-core --lib identify_and_ping_return_build_metadata: ok
  • cargo test -p cmux-tui --test resource_cli_v2 --test cli -- startup_help_and_version_use_the_public_command_name machine_agent: 3 ok
  • cargo clippy --locked -p cmux-tui-core -p cmux-tui --all-targets -- -D warnings: ok

No new tests.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Moves build stamp reading out of cmux-tui-core so a new stamp no longer recompiles it. cmd_server.rs previously read CMUX_TUI_BUILD_COMMIT, CMUX_MUX_BUILD_COMMIT, and CMUX_TUI_GHOSTTY_COMMIT with option_env!, which rustc tracked in dep-info and forced cmux-tui-core (and cmux-remote through it) to rebuild on every stamp change. Now only the cmux-tui binary reads the environment at compile time and installs a BuildStamp in core at startup.

  • main() installs the stamp as its first step, before any mode can serve identify or ping; reading order is unchanged, and an empty value still counts as no stamp.
  • A mux without an installed stamp (tests, embedders) reports null, same as an unstamped build.
  • identify_and_ping_return_build_metadata now installs a known stamp and asserts its literal values in identify and ping.
  • A stamp-change build dropped from ~51.5 s to ~32.9 s wall time on the Linux pool, with cmux-tui-core staying Fresh.
  • cmux-relay has the same pattern but sits outside the cmux-tui bin graph, so it is unchanged here.