Skip to content

fix: Fix up search path of bootstrapped Python toolchain dylib #2089

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

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ A brief description of the categories of changes:
It would work well in cases to reduce merge conflicts.

### Fixed
* (rules) Fixes build targets linking against `@rules_python//python/cc:current_py_cc_libs`
in host platform builds on macOS, by editing the `LC_ID_DYLIB` field of the hermetic interpreter's
`libpython3.x.dylib` using `install_name_tool`, setting it to its absolute path under Bazel's
execroot.
* (rules) Signals are properly received when using {obj}`--bootstrap_impl=script`
(for non-zip builds).
([#2043](https://github.com/bazelbuild/rules_python/issues/2043))
Expand Down
16 changes: 16 additions & 0 deletions python/private/python_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ def _python_repository_impl(rctx):
elif rctx.attr.distutils_content:
rctx.file(distutils_path, rctx.attr.distutils_content)

if "darwin" in platform and "osx" == repo_utils.get_platforms_os_name(rctx):
# Fix up the Python distribution's LC_ID_DYLIB field.
# It points to a build directory local to the GitHub Actions
# host machine used in the Python standalone build, which causes
# dyld lookup errors. To fix, set the full path to the dylib as
# it appears in the Bazel workspace as its LC_ID_DYLIB using
# the `install_name_tool` bundled with macOS.
dylib = "lib/libpython{}.dylib".format(python_short_version)
full_dylib_path = rctx.path(dylib)
repo_utils.execute_checked(
rctx,
op = "python_repository.FixUpDyldIdPath",
arguments = [repo_utils.which_checked(rctx, "install_name_tool"), "-id", full_dylib_path, dylib],
logger = logger,
)

# Make the Python installation read-only. This is to prevent issues due to
# pycs being generated at runtime:
# * The pycs are not deterministic (they contain timestamps)
Expand Down
12 changes: 7 additions & 5 deletions tests/cc/current_py_cc_libs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ current_py_cc_libs_test_suite(name = "current_py_cc_libs_tests")
cc_test(
name = "python_libs_linking_test",
srcs = ["python_libs_linking_test.cc"],
# Mac and Windows fail with linking errors, but its not clear why; someone
# with more C + Mac/Windows experience will have to figure it out.
# Windows fails with linking errors, but its not clear why; someone
# with more C + Windows experience will have to figure it out.
# - rickeylev@
target_compatible_with = [
"@platforms//os:linux",
],
target_compatible_with = select({
"@platforms//os:linux": [],
"@platforms//os:osx": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
"@rules_python//python/cc:current_py_cc_headers",
"@rules_python//python/cc:current_py_cc_libs",
Expand Down