Skip to content

Commit 3b9bdd8

Browse files
authored
[Build] Use brew clang compiler on mac (#8704)
Issue: # ### Brief Summary Use brew clang compiler on mac copilot:summary ### Walkthrough When building on latest Macs, e.g. Sequoia, the system clang is 16.0.0, or 17.0.0, depending on whether using XCode (16.0.0), or command line tools (17.0.0). Either way, the bytecode generated at python/taichi/_lib/runtime/runtime_arm64.bc is not loadable by llvm 15. Trying to load the clang-15/16 compiled runtime_arm64.bc with llvm 15 gives an error about unknown attribute (86). llvm 15 is the version of llvm used by taichi currently. therefore, building using system clang on macos sequoia prevents taichi from loading/running. Example failure: https://github.com/taichi-dev/taichi/actions/runs/14742813933/job/41384420135?pr=8688 ![Screenshot 2025-04-30 at 7 28 39 AM](https://github.com/user-attachments/assets/9fe577b6-1879-4bc8-b99c-cf9909565083) To fix this, we use the clang from the brew installed llvm@15 instead. This then runs ok. We assume in compile.py that brew has already been used earlier in the script to install llvm@15. We use brew config to locate brew, and then assume the clang path as `{HOMEBREW_PREFIX}/opt/llvm@15/bin/clang`, and similarly for clang++. copilot:walkthrough
1 parent e8fd57b commit 3b9bdd8

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

.github/workflows/scripts/ti_build/compiler.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# -- stdlib --
44
from pathlib import Path
55
import os
6+
from os.path import join
67
import json
78
import platform
89
import shutil
910
import tempfile
1011
import sys
12+
import subprocess
1113

1214
# -- third party --
1315
# -- own --
@@ -17,14 +19,20 @@
1719
from .tinysh import powershell
1820

1921

22+
def grep(value, target):
23+
for line in target.split("\n"):
24+
if value in line:
25+
return line
26+
27+
2028
# -- code --
2129
@banner("Setup Clang")
2230
def setup_clang(as_compiler=True) -> None:
2331
"""
2432
Setup Clang.
2533
"""
2634
u = platform.uname()
27-
if u.system in ("Linux", "Darwin"):
35+
if u.system == "Linux":
2836
for v in ("", "-14", "-13", "-12", "-11", "-10"):
2937
clang = shutil.which(f"clang{v}")
3038
if clang is not None:
@@ -34,7 +42,13 @@ def setup_clang(as_compiler=True) -> None:
3442
else:
3543
error("Could not find clang of any version")
3644
return
37-
45+
elif u.system == "Darwin":
46+
brew_config = subprocess.check_output(["brew", "config"]).decode("utf-8")
47+
print("brew_config", brew_config)
48+
brew_prefix = grep("HOMEBREW_PREFIX", brew_config).split()[1]
49+
print("brew_prefix", brew_prefix)
50+
clang = join(brew_prefix, "opt", "llvm@15", "bin", "clang")
51+
clangpp = join(brew_prefix, "opt", "llvm@15", "bin", "clang++")
3852
elif (u.system, u.machine) == ("Windows", "AMD64"):
3953
out = get_cache_home() / "clang-14-v2"
4054
url = "https://github.com/taichi-dev/taichi_assets/releases/download/llvm15/clang-14.0.6-win-complete.zip"

0 commit comments

Comments
 (0)