forked from ROCm/TheRock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_configure.py
More file actions
114 lines (95 loc) · 3.59 KB
/
build_configure.py
File metadata and controls
114 lines (95 loc) · 3.59 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
This script runs the Linux and Windows build configurations
Required environment variables:
- amdgpu_families
- package_version
- extra_cmake_options
- BUILD_DIR
Optional environment variables:
- VCToolsInstallDir
- GITHUB_WORKSPACE
"""
import argparse
import logging
import os
from pathlib import Path
import platform
import shlex
import subprocess
logging.basicConfig(level=logging.INFO)
THIS_SCRIPT_DIR = Path(__file__).resolve().parent
THEROCK_DIR = THIS_SCRIPT_DIR.parent.parent
PLATFORM = platform.system().lower()
cmake_preset = os.getenv("cmake_preset")
amdgpu_families = os.getenv("amdgpu_families")
package_version = os.getenv("package_version")
extra_cmake_options = os.getenv("extra_cmake_options")
build_dir = os.getenv("BUILD_DIR")
vctools_install_dir = os.getenv("VCToolsInstallDir")
github_workspace = os.getenv("GITHUB_WORKSPACE")
platform_options = {
"windows": [
f"-DCMAKE_C_COMPILER={vctools_install_dir}/bin/Hostx64/x64/cl.exe",
f"-DCMAKE_CXX_COMPILER={vctools_install_dir}/bin/Hostx64/x64/cl.exe",
f"-DCMAKE_LINKER={vctools_install_dir}/bin/Hostx64/x64/link.exe",
"-DTHEROCK_BACKGROUND_BUILD_JOBS=4",
],
}
def build_configure(manylinux=False):
logging.info(f"Building package {package_version}")
cmd = [
"cmake",
"-B",
build_dir,
"-GNinja",
".",
]
if cmake_preset:
cmd.extend(["--preset", cmake_preset])
cmd.extend(
[
f"-DTHEROCK_AMDGPU_FAMILIES={amdgpu_families}",
f"-DTHEROCK_PACKAGE_VERSION='{package_version}'",
"-DCMAKE_C_COMPILER_LAUNCHER=ccache",
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
"-DBUILD_TESTING=ON",
]
)
# Adding platform specific options
cmd += platform_options.get(PLATFORM, [])
# Adding manylinux Python executables if --manylinux is set
if manylinux:
python_executables = (
"/opt/python/cp38-cp38/bin/python;"
"/opt/python/cp39-cp39/bin/python;"
"/opt/python/cp310-cp310/bin/python;"
"/opt/python/cp311-cp311/bin/python;"
"/opt/python/cp312-cp312/bin/python;"
"/opt/python/cp313-cp313/bin/python"
)
cmd.append(f"-DTHEROCK_DIST_PYTHON_EXECUTABLES={python_executables}")
cmd.append("-DTHEROCK_ENABLE_SYSDEPS_AMD_MESA=ON")
cmd.append("-DTHEROCK_ENABLE_ROCDECODE=ON")
cmd.append("-DTHEROCK_ENABLE_ROCJPEG=ON")
if PLATFORM == "windows":
# VCToolsInstallDir is required for build. Throwing an error if environment variable doesn't exist
if not vctools_install_dir:
raise Exception(
"Environment variable VCToolsInstallDir is not set. Please see https://github.com/ROCm/TheRock/blob/main/docs/development/windows_support.md#important-tool-settings about Windows tool configurations. Exiting."
)
# Splitting cmake options into an array (ex: "-flag X" -> ["-flag", "X"]) for subprocess.run
cmake_options_arr = extra_cmake_options.split()
cmd += cmake_options_arr
logging.info(shlex.join(cmd))
subprocess.run(cmd, cwd=THEROCK_DIR, check=True)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run build configuration")
parser.add_argument(
"--manylinux",
action="store_true",
help="Enable manylinux build with multiple Python versions",
)
args = parser.parse_args()
# Support both command-line flag and environment variable
manylinux = args.manylinux or os.getenv("MANYLINUX") in ["1", "true"]
build_configure(manylinux=manylinux)