Skip to content

Conversation

@goldsborough
Copy link
Contributor

@goldsborough goldsborough commented Nov 16, 2018

When using setuptools to build a Python extension, setuptools will automatically add an ABI suffix like cpython-37m-x86_64-linux-gnu to the shared library name when using Python 3. This is required for extensions meant to be imported as Python modules. When we use setuptools to build shared libraries not meant as Python modules, for example libraries that define and register TorchScript custom ops, having your library called my_ops.cpython-37m-x86_64-linux-gnu.so is a bit annoying compared to just my_ops.so, especially since you have to reference the library name when loading it with torch.ops.load_library in Python.

This PR fixes this by adding a with_options class method to the torch.utils.cpp_extension.BuildExtension which allows configuring the BuildExtension. In this case, the first option we add is no_python_abi_suffix, which we then use in get_ext_filename (override from setuptools.build_ext) to throw away the ABI suffix.

I've added a test setup.py in a no_python_abi_suffix_test folder.

Fixes #14188

@t-vi @fmassa @soumith

@t-vi
Copy link
Collaborator

t-vi commented Nov 17, 2018 via email

@goldsborough
Copy link
Contributor Author

Fixes #14188

@goldsborough
Copy link
Contributor Author

@soumith can you take a look?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@goldsborough is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

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.

[C++ Extensions] Accepted compilers doesn't handle Python 2

5 participants