Skip to content

Fix Python build#1278

Merged
mwoehlke-kitware merged 2 commits into
Kitware:masterfrom
mwoehlke-kitware:fix-python-build
Apr 20, 2021
Merged

Fix Python build#1278
mwoehlke-kitware merged 2 commits into
Kitware:masterfrom
mwoehlke-kitware:fix-python-build

Conversation

@mwoehlke-kitware

Copy link
Copy Markdown
Member

Several places are failing entirely to add the includes for PyBind11, and those places that do are adding them via include_directories. Instead, link the pybind11::pybind11 target in all places that need PyBind11.

This fixes trying to build with a PyBind11 that is not in an include directory that is already being used for some other reason.

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@johnwparent johnwparent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. This approach seems more in line with the conventions used in the PyBind11 docs as well.

@dstoup dstoup left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The only thing that stands out to me is that sometimes pybind11::pybind11 is being added to the PUBLIC link interface and sometime to PRIVATE and when neither is specified, PUBLIC is the default. It would be good if those links were consistent and correct. The general rule I follow is, if your headers are including the headers of the library being linked, they should be PUBLIC since you're adding it to your public interface. If their headers are not in .h file, e.d. .cxx or other, then the links should be PRIVATE so we don't expose the dependencies to user.

Several places are failing entirely to add the includes for PyBind11,
and those places that do are adding them via include_directories.
Instead, link the pybind11::pybind11 target in all places that need
PyBind11.

This fixes trying to build with a PyBind11 that is not in an include
directory that is already being used for some other reason.
@mwoehlke-kitware

Copy link
Copy Markdown
Member Author

@dstoup, I think for most of the python bindings, the distinction is academic, as these are expected to be leaf targets. I did, however, tweak one spot so that ${PYTHON_LIBRARIES} and pybind11::pybind11 always have the same (PUBLIC/PRIVATE) linkage.

Are you asking me to also audit the linkage of ${PYTHON_LIBRARIES} everywhere?

Modify Python binding leaf libraries (but not utility libraries such as
vital_python_util), which we don't expect that anything will ever link
anyway, to always use PRIVATE linking. This improves consistency, as
most were already PRIVATE, but some for no apparent reason used PUBLIC
or even a mix of linking types.
@mwoehlke-kitware

Copy link
Copy Markdown
Member Author

Jenkins test this please

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@dstoup

dstoup commented Apr 19, 2021

Copy link
Copy Markdown
Collaborator

@dstoup, I think for most of the python bindings, the distinction is academic, as these are expected to be leaf targets. I did, however, tweak one spot so that ${PYTHON_LIBRARIES} and pybind11::pybind11 always have the same (PUBLIC/PRIVATE) linkage.

Are you asking me to also audit the linkage of ${PYTHON_LIBRARIES} everywhere?

No, I think if it's not relevant since they are all leaf targets, we can ignore this comment. I made the comment mostly because it's a touch confusing to have such inconsistency in how the link targets are added but I don't think it's worth any wide-spread audit.

@mwoehlke-kitware

Copy link
Copy Markdown
Member Author

@dstoup, well, if you note the second commit, you'll see I went ahead and cleaned it up anyway 🙂. BTW, I know for sure vital_python_util should link PyBind11 as PUBLIC, as that is how at least modules_python picks it up (note in this PR the removal of include_directories for that with no corresponding link change). Also, it seems the purpose of that library is largely or entirely "enhancing" PyBind11 for KWIVER's use, i.e. PyBind11 is clearly part of that library's public API.

@kwcvrobot

Copy link
Copy Markdown
Collaborator

@dstoup dstoup left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@mwoehlke-kitware mwoehlke-kitware merged commit 053f5aa into Kitware:master Apr 20, 2021
@mwoehlke-kitware mwoehlke-kitware deleted the fix-python-build branch April 20, 2021 12:45
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.

5 participants