|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +from common import append_path, capture, prepend_env_path, require_env, run, write_env |
| 8 | + |
| 9 | + |
| 10 | +def set_common_env(prefix: str, clang_path: str, clangxx_path: str) -> None: |
| 11 | + write_env("ITLABAI_CC", clang_path) |
| 12 | + write_env("ITLABAI_CXX", clangxx_path) |
| 13 | + write_env("ITLABAI_CMAKE_PREFIX_PATH", prefix) |
| 14 | + write_env("ITLABAI_SYCL_IMPLEMENTATION", "AdaptiveCpp") |
| 15 | + write_env("ITLABAI_ENABLE_OPENCV_APPS", "ON") |
| 16 | + write_env("ACPP_TARGETS", "omp.library-only") |
| 17 | + append_path(f"{prefix}/bin") |
| 18 | + |
| 19 | + |
| 20 | +def setup_macos() -> None: |
| 21 | + run(["brew", "install", "adaptivecpp"]) |
| 22 | + |
| 23 | + adaptivecpp_prefix = capture(["brew", "--prefix", "adaptivecpp"]) |
| 24 | + clang_path = capture(["xcrun", "--find", "clang"]) |
| 25 | + clangxx_path = capture(["xcrun", "--find", "clang++"]) |
| 26 | + |
| 27 | + set_common_env(adaptivecpp_prefix, clang_path, clangxx_path) |
| 28 | + |
| 29 | + |
| 30 | +def setup_linux() -> None: |
| 31 | + run(["sudo", "apt-get", "update"]) |
| 32 | + run( |
| 33 | + [ |
| 34 | + "sudo", |
| 35 | + "apt-get", |
| 36 | + "install", |
| 37 | + "-y", |
| 38 | + "build-essential", |
| 39 | + "clang-18", |
| 40 | + "cmake", |
| 41 | + "git", |
| 42 | + "libboost-context-dev", |
| 43 | + "libboost-fiber-dev", |
| 44 | + "libboost-filesystem-dev", |
| 45 | + "libboost-system-dev", |
| 46 | + "libboost-test-dev", |
| 47 | + "libclang-18-dev", |
| 48 | + "libomp-18-dev", |
| 49 | + "llvm-18-dev", |
| 50 | + "python3", |
| 51 | + ] |
| 52 | + ) |
| 53 | + |
| 54 | + runner_temp = Path(require_env("RUNNER_TEMP")) |
| 55 | + source_dir = runner_temp / "AdaptiveCpp" |
| 56 | + build_dir = runner_temp / "AdaptiveCpp-build" |
| 57 | + install_dir = runner_temp / "adaptivecpp-install" |
| 58 | + tag = require_env("ADAPTIVECPP_TAG") |
| 59 | + |
| 60 | + run( |
| 61 | + [ |
| 62 | + "git", |
| 63 | + "clone", |
| 64 | + "--branch", |
| 65 | + tag, |
| 66 | + "--depth", |
| 67 | + "1", |
| 68 | + "https://github.com/AdaptiveCpp/AdaptiveCpp.git", |
| 69 | + str(source_dir), |
| 70 | + ] |
| 71 | + ) |
| 72 | + run( |
| 73 | + [ |
| 74 | + "cmake", |
| 75 | + "-S", |
| 76 | + str(source_dir), |
| 77 | + "-B", |
| 78 | + str(build_dir), |
| 79 | + "-G", |
| 80 | + "Ninja", |
| 81 | + "-DCMAKE_BUILD_TYPE=Release", |
| 82 | + f"-DCMAKE_INSTALL_PREFIX={install_dir}", |
| 83 | + "-DCMAKE_C_COMPILER=clang-18", |
| 84 | + "-DCMAKE_CXX_COMPILER=clang++-18", |
| 85 | + "-DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm", |
| 86 | + "-DClang_DIR=/usr/lib/llvm-18/lib/cmake/clang", |
| 87 | + ] |
| 88 | + ) |
| 89 | + run(["cmake", "--build", str(build_dir), "--target", "install", "--parallel"]) |
| 90 | + |
| 91 | + set_common_env(str(install_dir), "/usr/bin/clang-18", "/usr/bin/clang++-18") |
| 92 | + prepend_env_path("LD_LIBRARY_PATH", f"{install_dir}/lib") |
| 93 | + prepend_env_path("LD_LIBRARY_PATH", "/usr/lib/llvm-18/lib") |
| 94 | + |
| 95 | + |
| 96 | +def main() -> None: |
| 97 | + runner_os = require_env("RUNNER_OS") |
| 98 | + if runner_os == "macOS": |
| 99 | + setup_macos() |
| 100 | + elif runner_os == "Linux": |
| 101 | + setup_linux() |
| 102 | + else: |
| 103 | + raise SystemExit(f"Unsupported RUNNER_OS for AdaptiveCpp setup: {runner_os}") |
| 104 | + |
| 105 | + |
| 106 | +if __name__ == "__main__": |
| 107 | + main() |
0 commit comments