summaryrefslogtreecommitdiff
path: root/components/rust/examples/component/SConscript
blob: 40d11c0446907c0081248054ebce665079dc9fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
import os
import sys
from building import *

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_support import clean_rust_build

# Load feature configurations
try:
    from feature_config_component import setup_all_component_features
    setup_all_component_features()
except ImportError:
    print("Warning: Could not load component feature configurations")


def _has(sym: str) -> bool:
    """Helper function to check if a configuration symbol is enabled."""
    try:
        return bool(GetDepend([sym]))
    except Exception:
        return bool(GetDepend(sym))


# Early return if Rust or log component is not enabled
if not _has('RT_USING_RUST'):
    group = []
    Return('group')

if not _has('RUST_LOG_COMPONENT'):
    group = []
    Return('group')

# Source files – component glue code if needed
src = []
LIBS = []
LIBPATH = []
LINKFLAGS = ""

# Handle clean operation
if GetOption('clean'):
    comp_build_dir = clean_rust_build(Dir('#').abspath, "example_component")
    if os.path.exists(comp_build_dir):
        print(f'Registering {comp_build_dir} for cleanup')
        Clean('.', comp_build_dir)
    else:
        print('No example_component build artifacts to 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")
    )

# Define component group for SCons
group = DefineGroup(
    'example_component_log', 
    src, 
    depend=['RT_USING_RUST'], 
    LIBS=LIBS, 
    LIBPATH=LIBPATH, 
    LINKFLAGS=LINKFLAGS
)

Return('group')