Skip to content

Commit 2988635

Browse files
committed
Drop from _sysconfig
1 parent f53f599 commit 2988635

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

cpython-unix/build-cpython.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,14 @@ def replace_in_all(search, replace):
627627
replace_in_file(MAKEFILE, search, replace)
628628
replace_in_file(SYSCONFIGDATA, search, replace)
629629
630-
# Replace the XCode path with a generic value.
630+
# Remove the Xcode path from the compiler flags.
631+
#
632+
# CPython itself will drop this from `sysconfig.get_config_var("CFLAGS")` and
633+
# similar calls, but _not_ if `CFLAGS` is set in the environment (regardless of
634+
# the `CFLAGS` value). It will almost always be wrong, so we drop it unconditionally.
631635
xcode_path = os.getenv("APPLE_SDK_PATH")
632636
if xcode_path:
633-
replace_in_all(xcode_path, "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
637+
replace_in_all("-isysroot %s" % xcode_path, "")
634638
635639
# -fdebug-default-version is Clang only. Strip so compiling works on GCC.
636640
replace_in_all("-fdebug-default-version=4", "")

cpython-unix/build.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,29 @@ def add_target_env(env, build_platform, target_triple, build_env):
165165
# non-system (e.g. Homebrew) executables from being used.
166166
env["PATH"] = "/usr/bin:/bin"
167167

168-
sdk_path = os.environ["APPLE_SDK_PATH"]
168+
if "APPLE_SDK_PATH" in os.environ:
169+
sdk_path = os.environ["APPLE_SDK_PATH"]
170+
else:
171+
# macOS SDK has historically been in /usr courtesy of an
172+
# installer provided by Xcode. But with Catalina, the files
173+
# are now typically in
174+
# /Applications/Xcode.app/Contents/Developer/Platforms/.
175+
# The proper way to resolve this path is with xcrun, which
176+
# will give us the headers that Xcode is configured to use.
177+
res = subprocess.run(
178+
["xcrun", "--sdk", sdk_platform, "--show-sdk-path"],
179+
check=True,
180+
capture_output=True,
181+
encoding="utf-8",
182+
)
183+
184+
sdk_path = res.stdout.strip()
169185

170186
if not os.path.exists(sdk_path):
171187
raise Exception("macOS SDK path %s does not exist" % sdk_path)
172188

189+
env["APPLE_SDK_PATH"] = sdk_path
190+
173191
# Grab the version from the SDK so we can put it in PYTHON.json.
174192
sdk_settings_path = pathlib.Path(sdk_path) / "SDKSettings.json"
175193
with sdk_settings_path.open("rb") as fh:
@@ -801,11 +819,6 @@ def build_cpython(
801819
if "lto" in parsed_build_options:
802820
env["CPYTHON_LTO"] = "1"
803821

804-
sdk_path = os.environ["APPLE_SDK_PATH"]
805-
if not os.path.exists(sdk_path):
806-
raise Exception("macOS SDK path %s does not exist" % sdk_path)
807-
env["APPLE_SDK_PATH"] = sdk_path
808-
809822
add_target_env(env, host_platform, target_triple, build_env)
810823

811824
build_env.run("build-cpython.sh", environment=env)

0 commit comments

Comments
 (0)