Commit 0777baf
refactor(paths) + fix(symbols): BuildLayout single-source + PT_LOAD bloat filter (#455)
* refactor(paths): make BuildLayout the single source of truth for the build dir
Closes the FastLED-shaped path bug #432: a project staged
at `<repo>/.build/pio/<board>/` and built with `env == board` was
yielding `.build/pio/<board>/.fbuild/build/<board>/release/firmware.hex`
— the board name appearing twice and the path deep enough to threaten
Windows' 260-char MAX_PATH limit.
Two related issues fixed together:
1. **`BuildParams.build_dir` was dead code.** The daemon HTTP handlers
carefully computed it via `get_project_build_root(&project_dir)` and
passed it through, but `pipeline/context.rs` ignored that field and
re-derived the build dir via `Cache::new(project_dir).get_build_dir
(env, profile)`. Zero `params.build_dir` references in
`crates/fbuild-build/src/**` confirmed the field was load-bearing
only in name. HTTP callers had no way to actually override the
build dir.
2. **No collapse rule for the `<env>` segment.** `compile_many.rs`
separately hard-coded `.fbuild/build/<env>/<profile>` instead of
going through `fbuild-paths`. Different code paths drifted.
Changes:
- `fbuild-paths::BuildLayout`: single resolver with precedence
`override_root` > `FBUILD_BUILD_DIR` > `<project>/.fbuild/build`,
plus the `<env>/<profile>` append. Drops the `<env>` segment when
`flatten_env` is set or auto-detects when `project_dir.file_name()
== env_name` — the FastLED `.build/pio/<board>/` case is now fixed
with zero consumer-side change.
- `pipeline/context.rs:120` now reads `params.build_dir` directly
instead of re-deriving via `Cache`. The build_dir field is finally
load-bearing.
- `Cache::get_build_dir`, `compile_many::project_build_dir`, and
`fbuild-paths::find_firmware` route through `BuildLayout` so layout
decisions live in exactly one place.
- HTTP request models (`BuildRequest`, `DeployRequest`, `TestEmuRequest`)
gained `build_dir_override` + `flatten_env`. Embedders (FastLED) can
opt in over HTTP.
- Per-platform integration tests migrated from
`tmp.path().join(".fbuild/build")` to the explicit
`<env>/<profile>` shape that matches the new contract. Regression
tests added: `find_firmware_in_collapsed_layout_when_basename_matches_env`
in `fbuild-paths` and `project_build_dir_collapses_when_sketch_basename_matches_env`
in `fbuild-build`.
Workspace verification:
- `soldr cargo clippy --workspace --all-targets -- -D warnings` clean.
- `soldr cargo test --workspace` — 52 test crates, zero failures.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(symbols): drop symbols outside PT_LOAD regions from bloat report
`fbuild bloat`/`fbuild symbols` was reporting nm's full symbol-table
view, including linker-script boundary markers whose nm-computed
"size" is the address gap to the next symbol — which can be multiple
gigabytes. On an nrf52840 firmware with a real `.text` of 32,740 B,
the bloat report claimed flash = 8,052,240,525 B (~8 GB), with
`__flash_arduino_end` (4 GB) and `__StackTop` (3.5 GB) topping the
list. Those are linker markers, not bytes in the final binary.
Fix:
- New `fbuild_core::symbol_analysis::LoadedRegion` representing a
PT_LOAD program-header range. `FineGrainedSymbolMap::retain_loaded_symbols`
filters the symbol list to those whose `[addr, addr + size)` fits
strictly inside some loaded region, then recomputes totals.
- Strict-lower-bound containment (`addr < region.end`) so size-0
boundary symbols at the end-of-segment (the `__StackTop` case)
are excluded.
- `fbuild_build::symbol_analyzer::read_pt_load_regions` parses PT_LOAD
segments from the ELF via the `object` crate (already a dev-dep;
promoted to a regular dep). Supports ELF32 + ELF64. Failures
degrade to a `tracing::warn!` plus unfiltered output rather than
erroring — the bloat report should still surface useful data on a
corrupt or non-ELF input.
- `analyze_elf` calls `retain_loaded_symbols` after building the map,
so every consumer of `fbuild symbols` / `fbuild bloat` benefits
automatically.
After the fix on the same nrf52840 ELF:
- 520 → 519 symbols
- total_flash 8 GB → 33,083 B (within 1 % of readelf's `.text` =
32,740 B; small overshoot from weak symbols counted twice by nm).
- `__flash_arduino_end` and `__StackTop` no longer appear.
- `__HeapBase` correctly remains under RAM (its address is inside
the RAM PT_LOAD range; the 227 KB number reflects the .heap
region's NOBITS allocation).
Unit tests:
- `loaded_region_strict_containment`: covers strict lower bound,
end-aligned upper bound, overflow guard.
- `retain_loaded_symbols_drops_boundary_markers`: pins the fix
against synthetic `__StackTop` / `__flash_arduino_end` /
oversized inputs.
- `retain_loaded_symbols_no_op_when_regions_empty`: defensive case
for PT_LOAD probe failure (don't empty the map).
Workspace verification:
- `soldr cargo clippy --workspace --all-targets -- -D warnings` clean.
- `soldr cargo test --workspace` — 52 test crates, zero failures.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(deploy): inline override-root build to keep deploy.rs under 1000 LOC
The BuildLayout migration in this branch pushed the file from 998 →
1002 LOC, tripping the workspace's `Reject .rs files over 1000 LOC`
gate. Compress the override-root resolution into a single chained
expression — same behavior, three fewer lines.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(daemon): extract resolve_build_dir helper so deploy.rs stays under 1000 LOC
The previous BuildLayout migration duplicated the
`override > FBUILD_BUILD_DIR > default + flatten_env` resolution in
deploy.rs and build.rs. rustfmt's preferred form pushed deploy.rs to
1002 LOC, tripping the workspace's per-file gate.
Lift the resolution into `common::resolve_build_dir` so:
- deploy.rs drops back to 998 LOC.
- Both HTTP handlers share one implementation of the precedence
rules, so future changes can't drift between them.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 24b7de4 commit 0777baf
27 files changed
Lines changed: 1083 additions & 69 deletions
File tree
- crates
- fbuild-build
- src
- pipeline
- tests
- fbuild-core/src/symbol_analysis
- fbuild-daemon
- src
- handlers
- emulator
- operations
- tests
- fbuild-packages/src
- fbuild-paths
- src
- tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 97 | + | |
103 | 98 | | |
104 | 99 | | |
105 | 100 | | |
| |||
833 | 828 | | |
834 | 829 | | |
835 | 830 | | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
836 | 849 | | |
837 | 850 | | |
838 | 851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
113 | 120 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
117 | 124 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
22 | 105 | | |
23 | 106 | | |
24 | 107 | | |
| |||
181 | 264 | | |
182 | 265 | | |
183 | 266 | | |
184 | | - | |
| 267 | + | |
185 | 268 | | |
186 | 269 | | |
187 | 270 | | |
188 | 271 | | |
189 | 272 | | |
190 | 273 | | |
191 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
192 | 299 | | |
193 | 300 | | |
194 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | | - | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
175 | | - | |
| 177 | + | |
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
| |||
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
261 | | - | |
| 263 | + | |
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
| |||
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
438 | | - | |
| 440 | + | |
439 | 441 | | |
440 | 442 | | |
441 | 443 | | |
| |||
467 | 469 | | |
468 | 470 | | |
469 | 471 | | |
470 | | - | |
| 472 | + | |
471 | 473 | | |
472 | 474 | | |
473 | 475 | | |
| |||
512 | 514 | | |
513 | 515 | | |
514 | 516 | | |
515 | | - | |
| 517 | + | |
516 | 518 | | |
517 | 519 | | |
518 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | | - | |
| 390 | + | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
| 454 | + | |
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
552 | | - | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
553 | 558 | | |
554 | 559 | | |
555 | 560 | | |
| |||
640 | 645 | | |
641 | 646 | | |
642 | 647 | | |
643 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
644 | 654 | | |
645 | 655 | | |
646 | 656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
0 commit comments