Skip to content

Commit 8bfba3b

Browse files
zackeesclaude
andauthored
fix(teensy): derive map_path from elf_path to fix output_dir scope error (#316)
`build_link_args` was added by #313 (CMSIS-DSP auto-link refactor) but a hold-over from #305 still referenced `output_dir.join("firmware.map")`, which doesn't exist as a parameter of `build_link_args` (it takes `elf_path: &Path`, not `output_dir`). The workspace failed to compile with: error[E0425]: cannot find value `output_dir` in this scope --> crates/fbuild-build/src/teensy/teensy_linker.rs:93:24 Every PR opened against main since #313 has been red because of this. Derive the map path from `elf_path.with_extension("map")`, which is equivalent to `output_dir.join("firmware.map")` since `elf_path = output_dir.join("firmware.elf")` at the only call site. Adds `test_teensy_link_command_emits_linker_map_next_to_elf` so the regression is caught locally next time. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3cf0eed commit 8bfba3b

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

crates/fbuild-build/src/teensy/teensy_linker.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl TeensyLinker {
9090
args.extend(["-o".to_string(), elf_path.to_string_lossy().to_string()]);
9191

9292
// Always emit a linker map next to firmware.elf for debugging (#305).
93-
let map_path = output_dir.join("firmware.map");
93+
let map_path = elf_path.with_extension("map");
9494
args.push(format!("-Wl,-Map={}", map_path.to_string_lossy()));
9595

9696
// Sketch objects first
@@ -325,6 +325,37 @@ mod tests {
325325
);
326326
}
327327

328+
/// Regression test: `build_link_args` always emits `-Wl,-Map=` next to
329+
/// the elf path so debug builds can inspect link decisions. Reverted
330+
/// previously by an out-of-scope `output_dir` reference (see #313 hotfix).
331+
#[test]
332+
fn test_teensy_link_command_emits_linker_map_next_to_elf() {
333+
let linker = TeensyLinker::new(
334+
PathBuf::from("/bin/arm-none-eabi-gcc"),
335+
PathBuf::from("/bin/arm-none-eabi-ar"),
336+
PathBuf::from("/bin/arm-none-eabi-objcopy"),
337+
PathBuf::from("/bin/arm-none-eabi-size"),
338+
LinkerScripts::single(PathBuf::from("/teensy4"), "imxrt1062_t41.ld"),
339+
crate::teensy::mcu_config::get_teensy_config_for_mcu("imxrt1062").unwrap(),
340+
BuildProfile::Release,
341+
Some(8126464),
342+
Some(524288),
343+
None,
344+
false,
345+
);
346+
let args = linker.build_link_args(
347+
&[],
348+
&[],
349+
&PathBuf::from("/build/firmware.elf"),
350+
&LinkExtraArgs::default(),
351+
);
352+
assert!(
353+
args.iter().any(|a| a == "-Wl,-Map=/build/firmware.map"),
354+
"expected -Wl,-Map=/build/firmware.map next to firmware.elf. Args: {:?}",
355+
args
356+
);
357+
}
358+
328359
/// Boards that do not declare a CMSIS-DSP lib (e.g. user override clears
329360
/// it) must not have a spurious `-l` argument appended.
330361
#[test]

0 commit comments

Comments
 (0)