|
| 1 | +# for module compiling |
1 | 2 | import os |
2 | | -import sys |
3 | 3 | from building import * |
4 | 4 |
|
5 | 5 | cwd = GetCurrentDir() |
| 6 | +objs = [] |
| 7 | +list = os.listdir(cwd) |
6 | 8 |
|
7 | | -# Import helper utilities |
8 | | -sys.path.append(os.path.join(cwd, 'tools')) |
9 | | -from build_support import ( |
10 | | - detect_rust_target, |
11 | | - make_rustflags, |
12 | | - collect_features, |
13 | | - verify_rust_toolchain, |
14 | | - ensure_rust_target_installed, |
15 | | - cargo_build_staticlib, |
16 | | - clean_rust_build, |
17 | | -) |
| 9 | +for d in list: |
| 10 | + path = os.path.join(cwd, d) |
| 11 | + if os.path.isfile(os.path.join(path, 'SConscript')): |
| 12 | + objs = objs + SConscript(os.path.join(d, 'SConscript')) |
18 | 13 |
|
19 | | - |
20 | | -def _has(sym: str) -> bool: |
21 | | - try: |
22 | | - return bool(GetDepend([sym])) |
23 | | - except Exception: |
24 | | - return bool(GetDepend(sym)) |
25 | | - |
26 | | - |
27 | | -# Not enabled? Return empty group early |
28 | | -if not _has('RT_USING_RUST'): |
29 | | - group = [] |
30 | | - Return('group') |
31 | | - |
32 | | - |
33 | | -# Source files – MSH command glue |
34 | | -src = ['rust_cmd.c'] |
35 | | -LIBS = [] |
36 | | -LIBPATH = [] |
37 | | - |
38 | | -if GetOption('clean'): |
39 | | - # Register Rust artifacts for cleaning |
40 | | - rust_build_dir = clean_rust_build(Dir('#').abspath) |
41 | | - if os.path.exists(rust_build_dir): |
42 | | - print(f'Registering {rust_build_dir} for cleanup') |
43 | | - Clean('.', rust_build_dir) |
44 | | - else: |
45 | | - print('No rust build artifacts to clean') |
46 | | -else: |
47 | | - if verify_rust_toolchain(): |
48 | | - import rtconfig |
49 | | - |
50 | | - target = detect_rust_target(_has, rtconfig) |
51 | | - if not target: |
52 | | - print('Error: Unable to detect Rust target; please check configuration') |
53 | | - else: |
54 | | - print(f'Detected Rust target: {target}') |
55 | | - |
56 | | - # Optional hint if target missing |
57 | | - ensure_rust_target_installed(target) |
58 | | - |
59 | | - # Build mode and features |
60 | | - debug = bool(_has('RUST_DEBUG_BUILD')) |
61 | | - features = collect_features(_has) |
62 | | - |
63 | | - rustflags = make_rustflags(rtconfig, target) |
64 | | - rust_lib = cargo_build_staticlib( |
65 | | - rust_dir=cwd, target=target, features=features, debug=debug, rustflags=rustflags |
66 | | - ) |
67 | | - |
68 | | - if rust_lib: |
69 | | - LIBS = ['rt_rust'] |
70 | | - LIBPATH = [os.path.dirname(rust_lib)] |
71 | | - print('Rust library linked successfully') |
72 | | - else: |
73 | | - print('Warning: Failed to build Rust library') |
74 | | - else: |
75 | | - print('Warning: Rust toolchain not found') |
76 | | - print('Please install Rust from https://rustup.rs') |
77 | | - |
78 | | -# Collect examples build artifacts |
79 | | -examples_group = [] |
80 | | -examples_path = os.path.join(cwd, 'examples') |
81 | | -if os.path.exists(examples_path): |
82 | | - examples_sconscript = os.path.join(examples_path, 'SConscript') |
83 | | - if os.path.exists(examples_sconscript): |
84 | | - print('Building Rust examples...') |
85 | | - # Use variant_dir=None to avoid directory switching issues |
86 | | - examples_group = SConscript(examples_sconscript, variant_dir=None, duplicate=0) |
87 | | - if not examples_group: |
88 | | - examples_group = [] |
89 | | - |
90 | | -# Define component group for SCons |
91 | | -group = DefineGroup('rust', src, depend=['RT_USING_RUST'], LIBS=LIBS, LIBPATH=LIBPATH) |
92 | | - |
93 | | -# Combine main rust group with examples |
94 | | -if examples_group: |
95 | | - if isinstance(examples_group, list): |
96 | | - group = [group] + examples_group |
97 | | - else: |
98 | | - group = [group, examples_group] |
99 | | - |
100 | | -Return('group') |
| 14 | +Return('objs') |
0 commit comments