Skip to content

Commit d088072

Browse files
zackeesclaude
andauthored
fix(stm32): discover Arduino_Core_STM32 framework libraries (SPI, Wire, ...) (#203)
The STM32 orchestrator installs the STM32duino core but never walked libraries/*/ to surface bundled libraries to sketches. Any sketch that transitively included <SPI.h> (e.g. FastLED's STM32 fastspi path) failed with "fatal error: SPI.h: No such file or directory" despite SPI living right there in the cache. Mirror PR #164's Teensy fix: - Add a shared FrameworkLibrary model + discover_framework_libraries() walker in fbuild-packages, used by both TeensyCores and Stm32Cores. - Extract the #include-scanning / transitive-closure resolver out of the Teensy orchestrator into crate::framework_libs so both platforms share one code path. - Wire Stm32Cores::get_framework_libraries() + get_framework_library_include_dirs() into the STM32 orchestrator after SrcWrapper so the resolver picks up SPI/Wire/EEPROM/... on demand and their include dirs reach the sketch compile command. Fixes #202 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a5ed36a commit d088072

8 files changed

Lines changed: 661 additions & 528 deletions

File tree

crates/fbuild-build/src/framework_libs.rs

Lines changed: 417 additions & 0 deletions
Large diffs are not rendered by default.

crates/fbuild-build/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod compiler;
1414
pub mod esp32;
1515
pub mod esp8266;
1616
pub mod flag_overlay;
17+
pub mod framework_libs;
1718
pub mod generic_arm;
1819
pub mod linker;
1920
pub mod nrf52;

crates/fbuild-build/src/stm32/orchestrator.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use fbuild_core::{Platform, Result};
2020
use fbuild_packages::{Framework, Toolchain};
2121

2222
use crate::compile_database::TargetArchitecture;
23+
use crate::framework_libs::resolve_framework_library_sources;
2324
use crate::generic_arm::{ArmCompiler, ArmLinker};
2425
use crate::pipeline;
2526
use crate::source_scanner::SourceCollection;
@@ -103,6 +104,22 @@ impl BuildOrchestrator for Stm32Orchestrator {
103104
.extend(scanner.scan_core_sources(&srcwrapper_src));
104105
}
105106

107+
// Walk Arduino_Core_STM32's libraries/ (SPI, Wire, EEPROM, ...) and
108+
// pull in any the sketch transitively #includes. Without this, sketches
109+
// that include <SPI.h> fail with "No such file or directory" because
110+
// STM32duino only exposes bundled libraries via this framework-level
111+
// discovery (PlatformIO's LDF does the same for `framework = arduino`).
112+
let framework_libs = framework.get_framework_libraries();
113+
let framework_library_sources =
114+
resolve_framework_library_sources(&framework_libs, &params.project_dir, &ctx.src_dir);
115+
if !framework_library_sources.is_empty() {
116+
tracing::info!(
117+
"STM32 framework library sources added: {}",
118+
framework_library_sources.len()
119+
);
120+
sources.core_sources.extend(framework_library_sources);
121+
}
122+
106123
tracing::info!(
107124
"sources: {} sketch, {} core, {} variant",
108125
sources.sketch_sources.len(),
@@ -173,6 +190,9 @@ impl BuildOrchestrator for Stm32Orchestrator {
173190
}
174191
include_dirs.push(ctx.src_dir.clone());
175192
pipeline::discover_project_includes(&params.project_dir, &mut include_dirs);
193+
// Bundled framework library headers (SPI, Wire, EEPROM, ...) so
194+
// sketches can `#include <SPI.h>` etc.
195+
include_dirs.extend(framework.get_framework_library_include_dirs());
176196

177197
// STM32duino system includes (CMSIS device, HAL drivers, etc.)
178198
let system_dir = framework.get_system_dir();

0 commit comments

Comments
 (0)