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

Split C++ code in 2 separate shared libraries #32

Merged
merged 2 commits into from
Jan 21, 2019
Merged

Conversation

tristan0x
Copy link
Member

Remove Basalt_BUILD_PYTHON_PACKAGE CMake option to choose if
the pure C++ library has to be built or the Python bindings.

Now CMake builds 2 shared libraries:

  • basalt which contain pure C++ code.
  • _basalt: built by pybind11, and depends on the first.
    a dirty workaround is required in basalt/__init__.py so that
    Python bindings can find the pure C++ code at runtime.

@ferdonline
Copy link

I like such kind of separation.
Maybe one suggestion would be to require linking with a static version so you only have one final library and avoid doing the python workaround.

@tristan0x
Copy link
Member Author

Thank you @ferdonline
I followed your advice, but used add_library(name OBJECT) instead of creating a static library, which just build a set of object files, that you can then reused elsewhere.

I still need to prevent building the other shared library (the one without bindings) during python setup.py build otherwise it is grabbed by distutils.
Thanks!

@ferdonline
Copy link

I still need to prevent building the other shared library (the one without bindings) during python setup.py build otherwise it is grabbed by distutils.

Some python packages put a leading underscore in the lib name if it's not expected to be used standalone. Maybe that's the case here?

@tristan0x
Copy link
Member Author

I still need to prevent building the other shared library (the one without bindings) during python setup.py build otherwise it is grabbed by distutils.

Some python packages put a leading underscore in the lib name if it's not expected to be used standalone. Maybe that's the case here?

Yes this module provides both Python and native code.
For instance here is the content of the wheel if I simply run the all make target:

 _basalt.cpython-36m-x86_64-linux-gnu.so
 libbasalt.so
 basalt/__init__.py
 basalt-0.0.1.dist-info/METADATA
 basalt-0.0.1.dist-info/WHEEL
 basalt-0.0.1.dist-info/top_level.txt
 basalt-0.0.1.dist-info/RECORD

This libbasalt.so is not required anymore because everything is shipped in _basalt..so

But I am fine to execute a more precise make target in setup.py as building libbasalt.so does not make sense in this context.

Copy link

@ferdonline ferdonline left a comment

Choose a reason for hiding this comment

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

I'm not following this very closely but I agree 100% with the separation of concepts and the new building rules.

Tristan Carel added 2 commits January 21, 2019 14:51
Remove `Basalt_BUILD_PYTHON_PACKAGE` CMake option to choose if
the pure C++ library has to be built or the Python bindings.

Now CMake builds 2 shared libraries:
* `basalt` which contain pure C++ code.
* `_basalt`: built by pybind11, and depends on the first.
  a dirty workaround is required in `basalt/__init__.py` so that
  Python bindings can find the pure C++ code at runtime.

Only build Python bindings during `python setup.py build` to
prevent including the pure C++ shared library in Python package.
Configuring CMake so that it creates a JSON file with command line of
every translation unit at cmake time. Then this file is given to clang-format
so that it has all include directories.
@tristan0x tristan0x merged commit 6341576 into master Jan 21, 2019
@tristan0x tristan0x deleted the compile-once branch January 21, 2019 14:25
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.

None yet

2 participants