MCPcopy
hub / github.com/MaaEnd/MaaEnd / build_cpp_algo

Function build_cpp_algo

tools/build_and_install.py:356–551  ·  view source on GitHub ↗

构建 C++ Algo Agent(使用 CMake Presets)

(
    root_dir: Path,
    install_dir: Path,
    target_os: str | None = None,
    target_arch: str | None = None,
    ci_mode: bool = False,
)

Source from the content-addressed store, hash-verified

354
355
356def build_cpp_algo(
357 root_dir: Path,
358 install_dir: Path,
359 target_os: str | None = None,
360 target_arch: str | None = None,
361 ci_mode: bool = False,
362) -> bool:
363 """构建 C++ Algo Agent(使用 CMake Presets)"""
364 if not check_cmake_environment():
365 return False
366
367 cpp_algo_dir = root_dir / "agent" / "cpp-algo"
368 if not cpp_algo_dir.exists():
369 print(f" {t('error')} {t('cpp_source_not_found')}: {cpp_algo_dir}")
370 return False
371
372 build_type = "RelWithDebInfo"
373
374 # 确定目标操作系统
375 if target_os:
376 resolved_os = target_os # win, macos, linux
377 else:
378 system = platform.system().lower()
379 resolved_os = {"windows": "win", "darwin": "macos"}.get(system, "linux")
380
381 # 确定目标架构
382 if target_arch:
383 resolved_arch = target_arch # x86_64, aarch64
384 else:
385 machine = platform.machine().lower()
386 if machine in ("x86_64", "amd64"):
387 resolved_arch = "x86_64"
388 elif machine in ("aarch64", "arm64"):
389 resolved_arch = "aarch64"
390 else:
391 resolved_arch = machine
392
393 # 根据平台选择 configure preset,参考 MaaFramework build.yml
394 configure_preset_candidates: list[str]
395 if resolved_os == "win":
396 if resolved_arch == "aarch64":
397 configure_preset_candidates = ["MSVC 2026 ARM", "MSVC 2022 ARM"]
398 else:
399 # 兼容仅安装 VS2022 的环境:优先尝试 2026,失败时自动回退 2022
400 configure_preset_candidates = ["MSVC 2026", "MSVC 2022"]
401 elif resolved_os == "linux":
402 if resolved_arch == "aarch64":
403 configure_preset_candidates = ["NinjaMulti Linux arm64"]
404 else:
405 configure_preset_candidates = ["NinjaMulti Linux x64"]
406 else:
407 # macOS
408 configure_preset_candidates = ["NinjaMulti"]
409
410 # 构建 MAADEPS_TRIPLET: maa-{x64|arm64}-{windows|linux|osx}
411 arch_part = "x64" if resolved_arch == "x86_64" else "arm64"
412 os_part = {"win": "windows", "macos": "osx", "linux": "linux"}.get(
413 resolved_os, resolved_os

Callers 1

mainFunction · 0.85

Calls 6

check_cmake_environmentFunction · 0.85
cleanup_cmake_cacheFunction · 0.85
warnMethod · 0.80
errMethod · 0.80
tFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected