From 30af7388a4077354f6083082fee040595978bbac Mon Sep 17 00:00:00 2001 From: yan hu Date: Fri, 7 Aug 2026 18:05:09 +0800 Subject: [rust][tools] Fix Rust build example configuration handling Improve the Rust build integration across core, applications, components, and module examples. Fix build failure propagation, target and feature handling, linker flags, example configuration semantics, and add STM32 CI attach coverage. --- components/rust/examples/modules/SConscript | 37 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'components/rust/examples/modules/SConscript') diff --git a/components/rust/examples/modules/SConscript b/components/rust/examples/modules/SConscript index 98e57d1fd9..056501c057 100644 --- a/components/rust/examples/modules/SConscript +++ b/components/rust/examples/modules/SConscript @@ -32,6 +32,20 @@ def _has(sym: str) -> bool: except Exception: return bool(GetDepend(sym)) + +MODULE_CONFIG_MAP = { + 'example_lib': 'RT_RUST_MODULE_SIMPLE_MODULE', +} + + +def should_build_module(module_dir: str) -> bool: + if _has('RT_RUST_BUILD_ALL_EXAMPLES'): + return True + + config = MODULE_CONFIG_MAP.get(os.path.basename(module_dir)) + return bool(config and _has(config)) + + def detect_target_for_dynamic_modules(): """ Detect the appropriate Rust target for dynamic modules. @@ -68,7 +82,7 @@ def build_rust_module(module_dir, build_root): cargo_config = toml.load(f) module_name = cargo_config['package']['name'] - + # Detect target automatically based on the current configuration target = detect_target_for_dynamic_modules() print(f"Building Rust module '{module_name}' for target: {target}") @@ -121,7 +135,12 @@ def build_rust_module(module_dir, build_root): return [], [], "" # Check dependencies -if not _has('RT_RUST_BUILD_MODULES'): +if not _has('RT_USING_MODULE') and not GetOption('clean'): + Return([]) + +if not ( + _has('RT_RUST_BUILD_MODULES') or _has('RT_RUST_BUILD_ALL_EXAMPLES') +) and not GetOption('clean'): Return([]) build_root = os.path.join(Dir('#').abspath, "build", "rust_modules") @@ -142,7 +161,11 @@ else: modules_built = [] for item in os.listdir(cwd): item_path = os.path.join(cwd, item) - if os.path.isdir(item_path) and os.path.exists(os.path.join(item_path, 'Cargo.toml')): + if ( + os.path.isdir(item_path) + and os.path.exists(os.path.join(item_path, 'Cargo.toml')) + and should_build_module(item_path) + ): result = build_rust_module(item_path, build_root) if result[0]: modules_built.extend(result[0]) @@ -151,9 +174,9 @@ else: print(f"Successfully built {len(modules_built)} Rust dynamic module(s): {', '.join(modules_built)}") group = DefineGroup( - 'rust_modules', - [], - depend=['RT_RUST_BUILD_MODULES'] + 'rust_modules', + [], + depend=['RT_USING_RUST'] ) -Return('group') \ No newline at end of file +Return('group') -- cgit v1.3.1