Skip to content

Conversation

nicholasjng
Copy link
Contributor

Previously, //tests/cc/current_py_cc_libs::python_libs_linking_test failed on macOS because the bootstrapped toolchain's dylib had an incorrect LC_ID_DYLIB field set, pointing to a local directory on the Python standalone build host machine.

To fix, add a small conditional to the Python repository rule patching the LC_ID_DYLIB field of the bootstrapped Python's dylib with its fully qualified file system path. Patching is carried out with macOS's own install_name_tool, which is part of the standard macOS dynamic linking toolchain.

Qualifies the mentioned test as executable on Mac, now only Windows linker errors are left to fix.

@nicholasjng nicholasjng force-pushed the mac-dyldpath-fixup branch 2 times, most recently from 476bd7d to 078f566 Compare July 26, 2024 05:59
Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you please add a line in CHANGELOG to say that this behaviour was fixed?

@rickeylev, could you PTAL and see if something is missing from your point of view? IMHO this is good to merge as is, because there was a test and things started working better than they used to before the change.

Previously, `//tests/cc/current_py_cc_libs::python_libs_linking_test`
failed on macOS because the bootstrapped toolchain's dylib had an
incorrect LC_ID_DYLIB field set, pointing to a local directory on the
Python standalone build host machine.

To fix, add a small conditional to the Python repository rule patching
the LC_ID_DYLIB field of the bootstrapped Python's dylib with its fully
qualified file system path. Patching is carried out with macOS's own
`install_name_tool`, which is part of the standard macOS dynamic linking
toolchain.

Since this needs macOS to be the host platform, restrict this change to
macOS host systems only by checking the host OS name.

Qualifies the mentioned test as executable on Mac, now only Windows
linker errors are left to fix.
@nicholasjng
Copy link
Contributor Author

I added a note to the changelog in the latest revision. Thanks for the speedy review!

@nicholasjng nicholasjng requested a review from aignas August 9, 2024 19:38
@nicholasjng
Copy link
Contributor Author

Any more issues on your end @aignas @rickeylev ?

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@aignas aignas added this pull request to the merge queue Aug 14, 2024
Merged via the queue into bazel-contrib:main with commit 4f97f1a Aug 14, 2024
@keith
Copy link
Member

keith commented Sep 26, 2024

Doesn't setting this to an absolute path mean you get a non-hermetic build if you link this dylib?

@keith
Copy link
Member

keith commented Sep 26, 2024

#2256

@brentleyjones
Copy link

brentleyjones commented Aug 28, 2025

This change breaks multi-platform builds. The contents of libpython.dylib differ depending on which host machine runs the build, since if "darwin" in platform and "osx" == repo_utils.get_platforms_os_name(rctx) checks the host machine not the execution platform. This change, if it has to happen conditionally, needs to happen in a build target instead.

$ diffoscope /tmp/local.libpython3.11.dylib /tmp/remote.libpython3.11.dylib 
--- /tmp/local.libpython3.11.dylib
+++ /tmp/remote.libpython3.11.dylib
├── arm64
│ ├── otool -arch arm64 -h {}
│ │ @@ -1,3 +1,3 @@
│ │  Mach header
│ │        magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
│ │ - 0xfeedfacf 16777228          0  0x00           6    32       4544 0x00100085
│ │ + 0xfeedfacf 16777228          0  0x00           6    32       4552 0x00100085
│ ├── otool -arch arm64 -L {}
│ │ @@ -1,8 +1,8 @@
│ │ -   @rpath/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
│ │ +   /install/lib/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
│ │     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)
│ │     /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
│ │     /usr/lib/libpanel.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
│ │     /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2202.0.0)
│ │     /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
│ │     /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1296.60.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants