diff options
Diffstat (limited to 'components/rust/examples')
7 files changed, 64 insertions, 34 deletions
diff --git a/components/rust/examples/application/SConscript b/components/rust/examples/application/SConscript index c6c4de3db8..fc50bc2825 100644 --- a/components/rust/examples/application/SConscript +++ b/components/rust/examples/application/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() # Import usrapp build module and build support sys.path.append(os.path.join(cwd, '../../tools')) -from build_usrapp import build_example_usrapp +from build_usrapp import UserAppBuildError, build_example_usrapp from build_support import clean_rust_build @@ -31,7 +31,7 @@ def load_extended_feature_configs(): group = [] -if not _has('RT_RUST_BUILD_APPLICATIONS'): +if not (_has('RT_RUST_BUILD_APPLICATIONS') or _has('RT_RUST_BUILD_ALL_EXAMPLES')) and not GetOption('clean'): Return('group') # Load extended feature configurations @@ -51,12 +51,16 @@ if GetOption('clean'): print('No example_usrapp build artifacts to clean') else: import rtconfig - LIBS, LIBPATH, LINKFLAGS = build_example_usrapp( - cwd=cwd, - has_func=_has, - rtconfig=rtconfig, - build_root=os.path.join(Dir('#').abspath, "build", "example_usrapp") - ) + try: + LIBS, LIBPATH, LINKFLAGS = build_example_usrapp( + cwd=cwd, + has_func=_has, + rtconfig=rtconfig, + build_root=os.path.join(Dir('#').abspath, "build", "example_usrapp") + ) + except UserAppBuildError as e: + print(f'Error: {e}') + sys.exit(1) group = DefineGroup( 'example_usrapp', @@ -67,4 +71,4 @@ group = DefineGroup( LINKFLAGS=LINKFLAGS ) -Return('group')
\ No newline at end of file +Return('group') diff --git a/components/rust/examples/application/fs/Cargo.toml b/components/rust/examples/application/fs/Cargo.toml index 2556b5f0a4..40c2e01ffa 100644 --- a/components/rust/examples/application/fs/Cargo.toml +++ b/components/rust/examples/application/fs/Cargo.toml @@ -12,6 +12,6 @@ default = [] enable-log = ["em_component_log/enable-log"] [dependencies] -rt-rust = { path = "../../../core" } +rt-rust = { path = "../../../core", features = ["fs"] } rt_macros = { path = "../../../rt_macros" } -em_component_log = { path = "../../component/log"}
\ No newline at end of file +em_component_log = { path = "../../component/log"} diff --git a/components/rust/examples/application/loadlib/Cargo.toml b/components/rust/examples/application/loadlib/Cargo.toml index 1e1065f91a..66c7abfb91 100644 --- a/components/rust/examples/application/loadlib/Cargo.toml +++ b/components/rust/examples/application/loadlib/Cargo.toml @@ -8,5 +8,5 @@ name = "em_loadlib" crate-type = ["staticlib"] [dependencies] -rt-rust = { path = "../../../core" } -rt_macros = { path = "../../../rt_macros" }
\ No newline at end of file +rt-rust = { path = "../../../core", features = ["libdl"] } +rt_macros = { path = "../../../rt_macros" } diff --git a/components/rust/examples/component/SConscript b/components/rust/examples/component/SConscript index 40d11c0446..ccfa01673b 100644 --- a/components/rust/examples/component/SConscript +++ b/components/rust/examples/component/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() # Import component build module and build support sys.path.append(os.path.join(cwd, '../../tools')) -from build_component import build_example_component +from build_component import ComponentBuildError, build_example_component from build_support import clean_rust_build # Load feature configurations @@ -25,12 +25,11 @@ def _has(sym: str) -> bool: return bool(GetDepend(sym)) -# Early return if Rust or log component is not enabled -if not _has('RT_USING_RUST'): +if not _has('RT_USING_RUST') and not GetOption('clean'): group = [] Return('group') -if not _has('RUST_LOG_COMPONENT'): +if not (_has('RT_RUST_BUILD_COMPONENTS') or _has('RT_RUST_BUILD_ALL_EXAMPLES')) and not GetOption('clean'): group = [] Return('group') @@ -51,12 +50,16 @@ if GetOption('clean'): else: # Build the component using the extracted build module import rtconfig - LIBS, LIBPATH, LINKFLAGS = build_example_component( - cwd=cwd, - has_func=_has, - rtconfig=rtconfig, - build_root=os.path.join(Dir('#').abspath, "build", "example_component") - ) + try: + LIBS, LIBPATH, LINKFLAGS = build_example_component( + cwd=cwd, + has_func=_has, + rtconfig=rtconfig, + build_root=os.path.join(Dir('#').abspath, "build", "example_component") + ) + except ComponentBuildError as e: + print(f'Error: {e}') + sys.exit(1) # Define component group for SCons group = DefineGroup( @@ -68,4 +71,4 @@ group = DefineGroup( LINKFLAGS=LINKFLAGS ) -Return('group')
\ No newline at end of file +Return('group') 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') diff --git a/components/rust/examples/modules/example_lib/Cargo.toml b/components/rust/examples/modules/example_lib/Cargo.toml index e44aae2848..6a490acad8 100644 --- a/components/rust/examples/modules/example_lib/Cargo.toml +++ b/components/rust/examples/modules/example_lib/Cargo.toml @@ -9,4 +9,4 @@ edition = "2024" crate-type = ["cdylib"] [dependencies] -rt-rust = { path = "../../.." }
\ No newline at end of file +rt-rust = { path = "../../../core" }
\ No newline at end of file diff --git a/components/rust/examples/modules/example_lib/src/lib.rs b/components/rust/examples/modules/example_lib/src/lib.rs index 79fe384e6a..8b86c593cd 100644 --- a/components/rust/examples/modules/example_lib/src/lib.rs +++ b/components/rust/examples/modules/example_lib/src/lib.rs @@ -11,7 +11,7 @@ /* Bring rt-rust's println! macro into scope */ use rt_rust::println; use core::ffi::{c_char, CStr}; -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn rust_mylib_println(s: *const c_char) { if s.is_null() { println!(""); @@ -24,7 +24,7 @@ pub extern "C" fn rust_mylib_println(s: *const c_char) { } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn rust_mylib_add(a: usize, b: usize) -> usize { a + b } |
