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

setup.py based installation can mix universal and CPython ABI #322

Closed
steve-s opened this issue May 10, 2022 · 3 comments · Fixed by #338
Closed

setup.py based installation can mix universal and CPython ABI #322

steve-s opened this issue May 10, 2022 · 3 comments · Fixed by #338

Comments

@steve-s
Copy link
Contributor

steve-s commented May 10, 2022

When installing a HPy extension by using python setup.py --hpy-abi=ABI install, the build directory is not cleared between builds. If the user installs the extension with different ABIs and does not clean the build directory in between, then both myextension.hpy.so and myextension.cpython-38-...so are installed and the later takes precedence when the extension is loaded. Unless one knows how HPy works internally figuring out what's going on and why universal mode does not work can be bad first user experience.

@steve-s steve-s changed the title setup.py based installation can mixe universal and CPython ABI setup.py based installation can mix universal and CPython ABI May 10, 2022
@antocuni
Copy link
Collaborator

Good catch.
I think that the proper solution is to teach distutils to use a different build directory depending on the selected hpy abi. On my machine, if you build a non-hpy module, you get the two folloing directories:

$ ls build/
lib.linux-x86_64-3.8/  temp.linux-x86_64-3.8/

Probabily, we want to use something like lib.linux-x86_64-3.8-hpy-universal or similar when --hpy-abi=universal.

Moreover, we have another related problem. If you have only hpy_ext_modules, all the files are put in build/lib instead of build/lib.linux-x86_64-3.8: this is because distutils explicitly check the presence of self.distribution.ext_modules to determine whether it's a "pure" o "plat" build:
https://github.com/python/cpython/blob/eb0004c27163ec089201c81eb9ece470700be6c7/Lib/distutils/command/build.py#L101-L108

            if self.distribution.ext_modules:
                self.build_lib = self.build_platlib
            else:
                self.build_lib = self.build_purelib

I don't know whether this might cause problems or not, to be honest.

I thought it was a quick fix and I've started a branch, but it seems more messy than expected.

@antocuni
Copy link
Collaborator

antocuni commented Aug 1, 2022

Moreover, we have another related problem. If you have only hpy_ext_modules, all the files are put in build/lib instead of build/lib.linux-x86_64-3.8

An update on this. It seems to depend on the version of setuptools:

  • newer versions of setuptools automatically monkey-patch distutils, so that import distutils gets an improved version (without the bug)
  • older versions of setuptools seems to NOT automatically monkey-patch, so that hpy patches the stdlib version of distutils, which have bugs. This happens by default if you e.g. you do python3.8 -m venv.

I think that hpy.devel should check that import distutils gives the one provided by setuptools and fail early if it doesn't.

@hodgestar
Copy link
Contributor

Failing with older setuptools makes a lot of sense -- that one can obtain two possible versions of distutils already causes other difficulties too and the Python distutils is deprecated and scheduled for removal in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants