|
2 | 2 | import os |
3 | 3 | import glob |
4 | 4 | import re |
| 5 | +import shutil |
5 | 6 |
|
6 | 7 | try: |
7 | 8 | from urllib.request import urlopen |
@@ -40,7 +41,7 @@ def preprocess(i): |
40 | 41 | env['MLC_ROCM_INSTALL_PREFIX'] = build_install_prefix |
41 | 42 |
|
42 | 43 | targets = 'AMDGPU;X86' |
43 | | - projects = 'clang;lld;clang-tools-extra' |
| 44 | + projects = 'clang;lld;clang-tools-extra;flang;compiler-rt' |
44 | 45 |
|
45 | 46 | q = "'" |
46 | 47 |
|
@@ -131,6 +132,14 @@ def postprocess(i): |
131 | 132 | env['MLC_ROMLC_INSTALLED_PATH'] = bin_dir |
132 | 133 | env['MLC_ROMLC_BIN_WITH_PATH'] = os.path.join(bin_dir, 'rocminfo') if os.path.isfile(os.path.join(bin_dir, 'rocminfo')) else clang_path |
133 | 134 | env['+PATH'] = [bin_dir] |
| 135 | + |
| 136 | + # Install cpulibs if requested |
| 137 | + if env.get('MLC_ROCM_INSTALL_CPULIBS', '') == 'yes': |
| 138 | + lib_dir = os.path.join(install_dir, 'lib') |
| 139 | + os.makedirs(lib_dir, exist_ok=True) |
| 140 | + _install_cpulibs(env, lib_dir) |
| 141 | + env['MLC_ROCM_CPULIBS_PATH'] = lib_dir |
| 142 | + |
134 | 143 | return {'return': 0} |
135 | 144 |
|
136 | 145 | install_prefix = env.get('MLC_ROCM_INSTALL_PREFIX', '/') |
@@ -182,4 +191,69 @@ def postprocess(i): |
182 | 191 | env['MLC_ROMLC_BIN_WITH_PATH'] = os.path.join(installed_path, "rocminfo") |
183 | 192 | env['+PATH'] = [installed_path] |
184 | 193 |
|
| 194 | + # Install cpulibs if requested |
| 195 | + if env.get('MLC_ROCM_INSTALL_CPULIBS', '') == 'yes': |
| 196 | + lib_dir = os.path.join(os.path.dirname(installed_path), 'lib') |
| 197 | + if os.path.isdir(lib_dir): |
| 198 | + _install_cpulibs(env, lib_dir) |
| 199 | + env['MLC_ROCM_CPULIBS_PATH'] = lib_dir |
| 200 | + |
185 | 201 | return {'return': 0} |
| 202 | + |
| 203 | + |
| 204 | +def _install_cpulibs(env, lib_dir): |
| 205 | + """Copy jemalloc and amdlibm libs into the compiler lib directory.""" |
| 206 | + |
| 207 | + copied = [] |
| 208 | + |
| 209 | + # Copy jemalloc libs |
| 210 | + jemalloc_lib_path = env.get('MLC_JEMALLOC_LIB_PATH', '') |
| 211 | + if jemalloc_lib_path and os.path.isdir(jemalloc_lib_path): |
| 212 | + for f in os.listdir(jemalloc_lib_path): |
| 213 | + if f.startswith('libjemalloc') and (f.endswith('.so') or f.endswith('.a') or '.so.' in f): |
| 214 | + src = os.path.join(jemalloc_lib_path, f) |
| 215 | + dst = os.path.join(lib_dir, f) |
| 216 | + if os.path.isfile(src) and not os.path.islink(src): |
| 217 | + shutil.copy2(src, dst) |
| 218 | + copied.append(f) |
| 219 | + elif os.path.islink(src): |
| 220 | + link_target = os.readlink(src) |
| 221 | + if os.path.exists(dst) or os.path.islink(dst): |
| 222 | + os.remove(dst) |
| 223 | + os.symlink(link_target, dst) |
| 224 | + copied.append(f'{f} -> {link_target}') |
| 225 | + # Create amdalloc -> jemalloc symlinks |
| 226 | + for ext in ['.so', '.a']: |
| 227 | + jemalloc_name = f'libjemalloc{ext}' |
| 228 | + amdalloc_name = f'libamdalloc{ext}' |
| 229 | + jemalloc_dst = os.path.join(lib_dir, jemalloc_name) |
| 230 | + amdalloc_dst = os.path.join(lib_dir, amdalloc_name) |
| 231 | + if os.path.isfile(jemalloc_dst) and not os.path.exists(amdalloc_dst): |
| 232 | + os.symlink(jemalloc_name, amdalloc_dst) |
| 233 | + copied.append(f'{amdalloc_name} -> {jemalloc_name}') |
| 234 | + print(f' Installed jemalloc libs: {copied}') |
| 235 | + else: |
| 236 | + print(f' WARNING: jemalloc lib path not found: {jemalloc_lib_path}') |
| 237 | + |
| 238 | + # Copy amdlibm (aocl-libm) libs |
| 239 | + amdlibm_copied = [] |
| 240 | + amdlibm_lib_path = env.get('MLC_AOCL_LIBM_LIB_PATH', '') |
| 241 | + if amdlibm_lib_path and os.path.isdir(amdlibm_lib_path): |
| 242 | + for f in os.listdir(amdlibm_lib_path): |
| 243 | + if (f.startswith('libalm') or f.startswith('libamdlibm')) and (f.endswith('.so') or f.endswith('.a') or '.so.' in f): |
| 244 | + src = os.path.join(amdlibm_lib_path, f) |
| 245 | + dst = os.path.join(lib_dir, f) |
| 246 | + if os.path.isfile(src) and not os.path.islink(src): |
| 247 | + shutil.copy2(src, dst) |
| 248 | + amdlibm_copied.append(f) |
| 249 | + elif os.path.islink(src): |
| 250 | + link_target = os.readlink(src) |
| 251 | + if os.path.exists(dst) or os.path.islink(dst): |
| 252 | + os.remove(dst) |
| 253 | + os.symlink(link_target, dst) |
| 254 | + amdlibm_copied.append(f'{f} -> {link_target}') |
| 255 | + print(f' Installed amdlibm libs: {amdlibm_copied}') |
| 256 | + else: |
| 257 | + print(f' WARNING: amdlibm lib path not found: {amdlibm_lib_path}') |
| 258 | + |
| 259 | + return copied + amdlibm_copied |
0 commit comments