Skip to content

Commit 9975e3e

Browse files
committed
Add -isysroot flag to compilation database on macOS
Include SDK path in compilation database commands on macOS to properly resolve system headers and prevent clang++ from finding conflicting or incomplete header definitions.
1 parent 3933128 commit 9975e3e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,24 @@ def set_compilation_db(filenames):
7777
cdb = "["
7878
clang_location = shutil.which("clang")
7979
file_dir = os.path.dirname(os.path.abspath(filenames[0]))
80+
# On macOS, get SDK path for proper system header resolution
81+
sdk_flags = ""
82+
if sys.platform == "darwin":
83+
sdk_path_result = sp.run(["xcrun", "--show-sdk-path"], stdout=sp.PIPE, stderr=sp.PIPE)
84+
if sdk_path_result.returncode == 0:
85+
sdk_path = sdk_path_result.stdout.decode().strip()
86+
sdk_flags = f" -isysroot {sdk_path}"
8087
for f in filenames:
8188
file_base = os.path.basename(f)
8289
clang_suffix = ""
8390
if f.endswith("cpp"):
8491
clang_suffix = "++"
8592
cdb += """\n{{
8693
"directory": "{0}",
87-
"command": "{1}{2} {3} -o {3}.o",
94+
"command": "{1}{2} {3}{4} -o {3}.o",
8895
"file": "{3}"
8996
}},""".format(
90-
file_dir, clang_location, clang_suffix, os.path.join(file_dir, file_base)
97+
file_dir, clang_location, clang_suffix, os.path.join(file_dir, file_base), sdk_flags
9198
)
9299
cdb = cdb[:-1] + "]" # Subtract extra comma and end json
93100
# Required for clang-tidy

0 commit comments

Comments
 (0)