SConscript 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. from building import *
  3. cwd = GetCurrentDir()
  4. sys.path.append(os.path.join(cwd, '../tools'))
  5. from build_support import (
  6. detect_rust_target,
  7. make_rustflags,
  8. collect_features,
  9. verify_rust_toolchain,
  10. ensure_rust_target_installed,
  11. cargo_build_staticlib,
  12. clean_rust_build,
  13. )
  14. def _has(sym: str) -> bool:
  15. try:
  16. return bool(GetDepend([sym]))
  17. except Exception:
  18. return bool(GetDepend(sym))
  19. # Source files – MSH command glue
  20. src = ['rust_cmd.c']
  21. LIBS = []
  22. LIBPATH = []
  23. if GetOption('clean'):
  24. # Register Rust artifacts for cleaning
  25. rust_build_dir = clean_rust_build(Dir('#').abspath)
  26. if os.path.exists(rust_build_dir):
  27. print(f'Registering {rust_build_dir} for cleanup')
  28. Clean('.', rust_build_dir)
  29. else:
  30. print('No rust build artifacts to clean')
  31. else:
  32. if verify_rust_toolchain():
  33. import rtconfig
  34. target = detect_rust_target(_has, rtconfig)
  35. if not target:
  36. print('Error: Unable to detect Rust target; please check configuration')
  37. else:
  38. print(f'Detected Rust target: {target}')
  39. # Optional hint if target missing
  40. ensure_rust_target_installed(target)
  41. # Build mode and features
  42. debug = bool(_has('RUST_DEBUG_BUILD'))
  43. features = collect_features(_has)
  44. rustflags = make_rustflags(rtconfig, target)
  45. rust_lib = cargo_build_staticlib(
  46. rust_dir=cwd, target=target, features=features, debug=debug, rustflags=rustflags
  47. )
  48. if rust_lib:
  49. LIBS = ['rt_rust']
  50. LIBPATH = [os.path.dirname(rust_lib)]
  51. print('Rust library linked successfully')
  52. else:
  53. print('Warning: Failed to build Rust library')
  54. else:
  55. print('Warning: Rust toolchain not found')
  56. print('Please install Rust from https://rustup.rs')
  57. # Define component group for SCons
  58. group = DefineGroup('rust', src, depend=['RT_USING_RUST'], LIBS=LIBS, LIBPATH=LIBPATH)
  59. Return('group')