Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only prefer command line tools SDK on macOS over default MacOSX SDK #5828

Merged
merged 2 commits into from Nov 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 22 additions & 11 deletions setup.py
Expand Up @@ -404,6 +404,27 @@ def _remove_extension(self, name):
self.extensions.remove(extension)
break

def get_macos_sdk_path(self):
try:
sdk_path = (
subprocess.check_output(["xcrun", "--show-sdk-path"])
.strip()
.decode("latin1")
)
except Exception:
sdk_path = None
if (
not sdk_path
or sdk_path == "/Applications/Xcode.app/Contents/Developer"
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
):
commandlinetools_sdk_path = (
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
)
if os.path.exists(commandlinetools_sdk_path):
sdk_path = commandlinetools_sdk_path
return sdk_path

def build_extensions(self):

library_dirs = []
Expand Down Expand Up @@ -531,17 +552,7 @@ def build_extensions(self):
_add_directory(library_dirs, "/usr/X11/lib")
_add_directory(include_dirs, "/usr/X11/include")

# SDK install path
sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
if not os.path.exists(sdk_path):
try:
sdk_path = (
subprocess.check_output(["xcrun", "--show-sdk-path"])
.strip()
.decode("latin1")
)
except Exception:
sdk_path = None
sdk_path = self.get_macos_sdk_path()
if sdk_path:
_add_directory(library_dirs, os.path.join(sdk_path, "usr", "lib"))
_add_directory(include_dirs, os.path.join(sdk_path, "usr", "include"))
Expand Down