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

bpo-37916: distutils: allow overriding of the RANLIB command on macOS (darwin) #15387

Closed
wants to merge 1 commit into from

Conversation

jpc
Copy link

@jpc jpc commented Aug 22, 2019

On a macOS hosts the system ranlib does not understand ELF
files so using the "ranlib" command causes errors during cross-compilations.

The simplest way to fix it is to pass the RANLIB parameter provided to setup.py through to the distutils compiler machinery. This is analogous to the way the C/C++ cross-compiler is configured.

This change was required to proceed with crosscompiling numpy. It should help with other packages too (if they use distutils and need ranlib).

https://bugs.python.org/issue37916

This is required to be able to crosscompile numpy (and probably some other
packages too) on a macOS host where the system ranlib does not understand ELF
files.
@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Aug 22, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@@ -232,7 +234,8 @@ def customize_compiler(compiler):
compiler_cxx=cxx,
linker_so=ldshared,
linker_exe=cc,
archiver=archiver)
archiver=archiver,
ranlib=ranlib)
Copy link
Contributor

@isuruf isuruf Nov 3, 2019

Choose a reason for hiding this comment

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

ranlib should be added here only if it is in compiler.executables. Otherwise this would be adding ranlib to other OS as well.

Copy link
Author

@jpc jpc Nov 8, 2019

Choose a reason for hiding this comment

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

Hey, thanks for the feedback. I may be misunderstanding something but this change would add ranlib only if it was explicitly passed as an environment variable (or set in the Python Makefile), right? If I am misunderstanding something I would love if you could sketch the code change since I know next to nothing about the distutils codebase (apart from what I have learned debugging this issue).

I think this change is really OS independent – it's just that it is easier to trigger the bug on macOS since it breaks many Linux-centric assumptions.

@jpc
Copy link
Author

jpc commented Dec 5, 2019

Hi, is there anything I could do to help get this merged?

@ned-deily
Copy link
Member

ned-deily commented Dec 9, 2019

Thanks for submitting the PR. I just had time to take a quick look at it and that raised some questions. First, to be complete, Lib/distutils/test/test_sysconfig.py should be modified to test this change. Second, the PR should be renamed since its effects are not limited to macOS. But, most importantly, I wonder if the root cause of seeing problems with cross-compiling on macOS is some code in Lib/distutils/unixccompiler.py which is where all these customizations are used. 005dbb2 way back in 2002 added:

 if sys.platform[:6] == "darwin":
         executables['ranlib'] = ["ranlib"]

with the explanation "on MacOSX/Darwin, use ranlib when building static libs.". So it appears that only on macOS is the use of ranlib forced. This was in the very early days of macOS so perhaps this is no longer needed. There are comments elsewhere associated with libtool that suggest ranlib might be needed for universal builds on macOS. I don't have a lot of experience with static libs on macOS so I really don't know whether this is still an issue or not. But before further complicating Distutils, we should figure out whether this forced use of ranlib is still necessary. I also note that the use of ranlib has been removed from the building of Python itself by bpo-31625 so that might be a clue. (@ronaldoussoren. any insights?)

@vstinner
Copy link
Member

vstinner commented Dec 9, 2019

Please open a new issue: https://bugs.python.org/issue31625 is closed.

@ned-deily
Copy link
Member

ned-deily commented Dec 9, 2019

@vstinner, check the title. This PR isn’t about bpo-31625. I’m guessing you saw this PR showing up on that issue thanks to one of our bots unhelpfully noticing that I mentioned it in passing in a comment above.

@vstinner
Copy link
Member

vstinner commented Dec 9, 2019

@vstinner, check the title. This PR isn’t about bpo-31625. I’m guessing you saw this PR showing up on that issue thanks to one of our bots unhelpfully noticing that I mentioned it in passing in a comment above.

Ooooh, my bad, sorry :-)

@merwok
Copy link
Member

merwok commented May 11, 2021

The ticket was closed with an explanation that the code moved to https://github.com/pypa/distutils/ and issues should be reported there.

@merwok merwok closed this May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants