summaryrefslogtreecommitdiff
path: root/components/rust/examples/application/SConscript
blob: fc50bc282560de2d1dea829b379253837c6ae291 (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
72
73
74
import os
import sys
from building import *

cwd = GetCurrentDir()

# Import usrapp build module and build support
sys.path.append(os.path.join(cwd, '../../tools'))
from build_usrapp import UserAppBuildError, build_example_usrapp
from build_support import clean_rust_build


def _has(sym: str) -> bool:
    try:
        return bool(GetDepend([sym]))
    except Exception:
        return bool(GetDepend(sym))


def load_extended_feature_configs():
    """
    Load extended feature configurations if available.
    This allows users to add custom configuration mappings.
    """
    try:
        from feature_config_examples import setup_all_example_features
        setup_all_example_features()
        print("Extended feature configurations loaded successfully.")
    except ImportError:
        print("Using default feature configurations.")

group = []

if not (_has('RT_RUST_BUILD_APPLICATIONS') or _has('RT_RUST_BUILD_ALL_EXAMPLES')) and not GetOption('clean'):
    Return('group')

# Load extended feature configurations
load_extended_feature_configs()

src = []
LIBS = []
LIBPATH = []
LINKFLAGS = ""

if GetOption('clean'):
    app_build_dir = clean_rust_build(Dir('#').abspath, "example_usrapp")
    if os.path.exists(app_build_dir):
        print(f'Registering {app_build_dir} for cleanup')
        Clean('.', app_build_dir)
    else:
        print('No example_usrapp build artifacts to clean')
else:
    import rtconfig
    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', 
    src, 
    depend=['RT_USING_RUST'], 
    LIBS=LIBS, 
    LIBPATH=LIBPATH, 
    LINKFLAGS=LINKFLAGS
)

Return('group')