Skip to content

Commit c135c3d

Browse files
committed
unix: use xcrun to find macOS SDK path
/usr/include doesn't exist in Catalina and you need to disable security features to symlink it. Let's use xcrun to find the macOS SDK.
1 parent 171378f commit c135c3d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cpython-unix/build.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import multiprocessing
99
import os
1010
import pathlib
11+
import subprocess
1112
import sys
1213
import tempfile
1314

@@ -47,6 +48,23 @@ def add_target_env(env, platform, build_env):
4748
env["TARGET_TRIPLE"] = "x86_64-apple-darwin18.7.0"
4849
env["PATH"] = "/usr/bin:/bin"
4950

51+
# macOS SDK has historically been in /usr courtesy of an
52+
# installer provided by Xcode. But with Catalina, the files
53+
# are now typically in
54+
# /Applications/Xcode.app/Contents/Developer/Platforms/.
55+
# The proper way to resolve this path is with xcrun, which
56+
# will give us the headers that Xcode is configured to use.
57+
res = subprocess.run(
58+
["xcrun", "--show-sdk-path"],
59+
check=True,
60+
capture_output=True,
61+
encoding="utf-8",
62+
)
63+
64+
sdk_path = res.stdout.strip()
65+
env["MACOS_SDK_PATH"] = sdk_path
66+
env["CPATH"] = "%s/usr/include" % sdk_path
67+
5068

5169
def archive_path(package_name: str, platform: str, musl=False):
5270
entry = DOWNLOADS[package_name]

0 commit comments

Comments
 (0)