Repository navigation
feat(daemon): run the daemon from the fbuild image by argv[0] (#1851 phase 1) - #1852
Conversation
…phase 1) Move the daemon's main body into the library as fbuild_daemon::entry::run(), keeping heap_profile::start_from_env() as the process's first statement (#1361). src/main.rs becomes a three-line shim; the #[global_allocator] stays in the bin where it belongs. fbuild-cli gains a multicall module that classifies argv[0] before the 8 MB stack trampoline, the dev-namespace hash, the tokio runtime and clap, and dispatches to entry::run() when the stem is fbuild-daemon. Separators and the final extension are handled textually so a Windows path classifies the same way on any host. The entry module lives at src/bin/entry/mod.rs (a library module, not a binary target): it is a program entry point, which is exactly the scope the ban_process_exit_outside_main and ban_env_var_set_after_import dylints exempt by path; neither allowlist is touched. Both binaries are still built and shipped in this phase. No packaging, wheel, service-definition or external-caller change. Refs #1851
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
Local gates on E2E: the same image renamed to |
What
Phase 1 of #1851: make the daemon runnable from the
fbuildimage itself, chosen byargv[0]— busybox-style, the way soldr does it. Both binaries are still built andshipped in this phase; no packaging, wheel or install change.
crates/fbuild-daemon/src/entry.rs(new) — the whole body of the oldasync fn main()isnow
pub fn run() -> i32.run()startsheap_profile::start_from_env()as its firststatement (the perf: adopt the mimalloc-pprof allocator for heap/leak profiling; verify on-CPU, off-CPU, and symbolization from running-process #1361 ordering, ahead of the tokio runtime it then builds) and blocks on the
same multi-thread runtime the
#[tokio::main]attribute used to create. Body moved verbatim;the two baseline
#[expect]s (too_many_lines,cognitive_complexity) carry over — clippyexempts a function literally named
mainfrom exactly these two lints, so they must beexplicitly expected at the new name and must not grow.
crates/fbuild-daemon/src/main.rs— 3-line shim:std::process::exit(fbuild_daemon::entry::run()).The
#[global_allocator]stays here, because it is a bin-level item and belongs to theexecutable that ships the profiler.
crates/fbuild-cli/src/multicall.rs(new) —classify_argv0/maybe_dispatch, recognisingonly
fbuild-daemon. Separators are stripped as text (/and\) and the final extension isremoved textually, so a Windows path (
C:\…\FBUILD-DAEMON.EXE) classifies identically on aUnix host — the dispatch rule must not depend on which platform runs it.
crates/fbuild-cli/src/main.rs— the hook is the first thing infn main(): before the 8 MBstack trampoline, before the dev-namespace hash, before the tokio runtime and clap. Anything
that is not the daemon stem falls through unchanged.
Why argv[0] (per the issue)
External callers (FastLED, scripts, service definitions, the running-process broker) exec
fbuild-daemonby name, and fbuild identifies its daemon by exe stem(
fbuild_paths::daemon_ownership::DAEMON_EXE_STEM). A hiddenfbuild __daemonsubcommand wouldgive the process the stem
fbuildand make it indistinguishable from a CLI invocation. Nothingexternal has to change in this phase or the next.
Verification (real output)
End-to-end, same image under two names (isolated
HOME, dev mode, free port):The last two lines are the point of the move: the profiler still starts before anything else
when the daemon is entered through the multicall path (#1361), and the health payload still
reports the exe it was launched as.
Scope note
Phases 2–4 of #1851 (self-relocation into the cache root, dropping the second link from the
wheel, alias creation at spawn,
restart_diagsource-vs-relocated reporting) are deliberatelynot in this PR. This one only proves the mechanism with both binaries still shipped, which
is the phase the issue asks to land first.
No new workspace crate, no new file lock, no packaging change.
Closes #1851 phase 1.
Dylint
Both crates pass the full lint set (run with the CI-pinned cargo-dylint 6.2.0; the
~/.venv/bin/soldr0.9.41 on this host defaults to 6.0.3, whose driver does not build onnightly-2026-08-15, so the gate must be invoked with the newer/usr/bin/soldron PATH):The entry module is a program entry point, so it sits at
src/bin/entry/mod.rs(a librarymodule — cargo only auto-discovers
src/bin/*/main.rs, so no binary target is created; verifiedwith
cargo metadata:[lib, containment_harness bin, fbuild-daemon bin, it test]). That is thepath scope
ban_process_exit_outside_mainandban_env_var_set_after_importalready exempt;neither
allowlist.txtis touched, since both say new files must not be added.