Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Unreleased changes template.
* (deps) platforms 0.0.4 -> 0.0.11
* (py_wheel) Package `py_library.pyi_srcs` (`.pyi` files) in the wheel.
* (py_package) Package `py_library.pyi_srcs` (`.pyi` files) in `py_package`.
* (pypi) Use `xcrun xcodebuild --showsdks` to find XCode root.

{#v0-0-0-fixed}
### Fixed
Expand Down
47 changes: 39 additions & 8 deletions python/private/pypi/whl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,36 @@ def _get_xcode_location_cflags(rctx):
# This is a full xcode installation somewhere like /Applications/Xcode13.0.app/Contents/Developer
# so we need to change the path to to the macos specific tools which are in a different relative
# path than xcode installed command line tools.
xcode_root = "{}/Platforms/MacOSX.platform/Developer".format(xcode_root)
xcode_sdks_json = repo_utils.execute_checked(
rctx,
op = "LocateXCodeSDKs",
arguments = [
repo_utils.which_checked(rctx, "xcrun"),
"xcodebuild",
"-showsdks",
"-json",
],
environment = {
"DEVELOPER_DIR": xcode_root,
},
).stdout
xcode_sdks = json.decode(xcode_sdks_json)
potential_sdks = [
sdk
for sdk in xcode_sdks
if "productName" in sdk and
sdk["productName"] == "macOS" and
"darwinos" not in sdk["canonicalName"]
]

# Now we'll get two entries here (one for internal and another one for public)
# It shouldn't matter which one we pick.
xcode_sdk_path = potential_sdks[0]["sdkPath"]
else:
xcode_sdk_path = "{}/SDKs/MacOSX.sdk".format(xcode_root)

return [
"-isysroot {}/SDKs/MacOSX.sdk".format(xcode_root),
"-isysroot {}".format(xcode_sdk_path),
]

def _get_toolchain_unix_cflags(rctx, python_interpreter, logger = None):
Expand Down Expand Up @@ -158,19 +185,23 @@ def _create_repository_execution_environment(rctx, python_interpreter, logger =
Dictionary of environment variable suitable to pass to rctx.execute.
"""

# Gather any available CPPFLAGS values
cppflags = []
cppflags.extend(_get_xcode_location_cflags(rctx))
cppflags.extend(_get_toolchain_unix_cflags(rctx, python_interpreter, logger = logger))

env = {
"PYTHONPATH": pypi_repo_utils.construct_pythonpath(
rctx,
entries = rctx.attr._python_path_entries,
),
_CPPFLAGS: " ".join(cppflags),
}

# Gather any available CPPFLAGS values
#
# We may want to build in an environment without a cc toolchain.
# In those cases, we're limited to --download-only, but we should respect that here.
is_wheel = rctx.attr.filename and rctx.attr.filename.endswith(".whl")
if not (rctx.attr.download_only or is_wheel):
cppflags = []
cppflags.extend(_get_xcode_location_cflags(rctx))
cppflags.extend(_get_toolchain_unix_cflags(rctx, python_interpreter))
env[_CPPFLAGS] = " ".join(cppflags)
return env

def _whl_library_impl(rctx):
Expand Down