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

Fix cmake install #3228

Closed
wants to merge 13 commits into from
Closed

Fix cmake install #3228

wants to merge 13 commits into from

Conversation

junghans
Copy link
Member

@junghans junghans commented Oct 2, 2019

Supersedes #3226

Description of changes:

  • fix the CMake build system to include libraries in the list of installed files and test it in a dedicated CI job
  • fix the versioning of Cython .so shared objects
  • simplify the CMake tests

@codecov
Copy link

codecov bot commented Oct 2, 2019

Codecov Report

Merging #3228 into 4.1 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##             4.1   #3228   +/-   ##
=====================================
  Coverage     85%     85%           
=====================================
  Files        530     530           
  Lines      26025   26025           
=====================================
  Hits       22157   22157           
  Misses      3868    3868

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ffa392...4035463. Read the comment docs.

@mkuron
Copy link
Member

mkuron commented Oct 2, 2019

Needs cherry pick into master branch too.

@junghans
Copy link
Member Author

junghans commented Oct 2, 2019

Needs cherry pick into master branch too.

The merge seems to work as well.

@junghans
Copy link
Member Author

Ping

@jngrad jngrad added this to the Espresso 4.1.1 milestone Oct 11, 2019
Copy link
Member

@jngrad jngrad left a comment

Choose a reason for hiding this comment

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

Please edit the original post to explain what this PR is achieving.

"${PROJECT_VERSION}")
if(NOT ${SOVERSION} MATCHES "^[1-9]+$")
message(FATAL_ERROR "Could not determine SOVERSION from ${PROJECT_VERSION}")
endif(NOT ${SOVERSION} MATCHES "^[1-9]+$")
Copy link
Member

Choose a reason for hiding this comment

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

Why is SOVERSION not needed anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

All libraries get to installed in the python site-packages directory and in there so versioning isn’t required anymore. Plus half of the new library miss it anyhow.

@@ -1,3 +1,4 @@
add_library(mpiio SHARED mpiio.cpp)
target_include_directories(mpiio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(mpiio PRIVATE EspressoConfig EspressoCore MPI::MPI_CXX)
install(TARGETS mpiio LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd)
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of the new install() line here and in the other submodules?

Copy link
Member Author

Choose a reason for hiding this comment

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

These libraries were missing from the installation and hence made the espressomd module unusable.

@jngrad
Copy link
Member

jngrad commented Oct 13, 2019

@junghans Thanks for reporting this issue. I will add a test to detect this type of regression.

@mkuron While trying to reproduce the issue on Ubuntu, I found another flaw in the build system: the CMAKE_INSTALL_RPATH is not updated when the user provides a custom DESTDIR during installation. This should have been caught by our CMake tests, unfortunately I did not configure the destdir test properly. I've investigated the issue further and came to the conclusion that we cannot actually use make install DESTDIR="path/to/install" and should warn the user explicitly against using that command, and only use cmake .. -DCMAKE_INSTALL_PREFIX="path/to/install". Here is a MWE:

# with DESTDIR and no CMAKE_INSTALL_PREFIX, PATH is right but RPATH is wrong
cmake ..
make -j$(nproc)
make install DESTDIR="/tmp/espresso-1"
-- Installing: /tmp/espresso-1/usr/local/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so
-- Set runtime path of "/tmp/espresso-1/usr/local/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so" to "/usr/local/lib/python3.6/site-packages/espressomd"
# with no DESTDIR and CMAKE_INSTALL_PREFIX, PATH is right and RPATH is right
cmake .. -DCMAKE_INSTALL_PREFIX="/tmp/espresso-2"
make -j$(nproc)
make install
-- Installing: /tmp/espresso-2/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so
-- Set runtime path of "/tmp/espresso-2/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so" to "/tmp/espresso-2/lib/python3.6/site-packages/espressomd"
# with DESTDIR and CMAKE_INSTALL_PREFIX, PATH is wrong and RPATH is wrong
cmake .. -DCMAKE_INSTALL_PREFIX="/tmp/espresso-3"
make -j$(nproc)
make install DESTDIR="/tmp/espresso-4"
-- Installing: /tmp/espresso-4/tmp/espresso-3/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so
-- Set runtime path of "/tmp/espresso-4/tmp/espresso-3/lib/python3.6/site-packages/espressomd/EspressoScriptInterface.so" to "/tmp/espresso-3/lib/python3.6/site-packages/espressomd"

When RPATH is wrong, we get the following error message:

$> ls /tmp/espresso-1/usr/local/lib/python3.6/site-packages/espressomd/EspressoCore.so 
/tmp/espresso-1/usr/local/lib/python3.6/site-packages/espressomd/EspressoCore.so
$> /tmp/espresso-1/usr/local/bin/pypresso 
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import espressomd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/espresso-1/usr/local/lib/python3.6/site-packages/espressomd/__init__.py", line 23, in <module>
    import espressomd._init
ImportError: EspressoCore.so: cannot open shared object file: No such file or directory

@jngrad
Copy link
Member

jngrad commented Oct 13, 2019

I have written most of the logic for the new test, however I can't install 4.1.1rc with or without this PR:

cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests
make -j$(nproc)
make install
./pypresso -c 'from espressomd.cluster_analysis import ClusterStructure;print("ok1")'
/tmp/espresso-unit-tests/bin/pypresso -c 'import espressomd;from espressomd.cluster_analysis import ClusterStructure;print("ok2")'
ok1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_cluster_analysis)

The cluster_analysis.so file is a C++ shared object, which is not meant to be imported from Python. To access its classes, we use the ScriptInterfaceHelper in cluster_analysis.py. In the build folder, the .so and .py files are in different folders so there is no name collision. However, when we install espresso, the .so and .py end up in the same folder and Python thinks the .so file is a Cython shared object, which is expected to have a PyInit_* function. When I rename cluster_analysis.py to e.g. clusters_analysis.py, there is no import error.

@KaiSzuttor could this be a regression of our efforts to restructure the core folders?

@mkuron
Copy link
Member

mkuron commented Oct 13, 2019

@mkuron While trying to reproduce the issue on Ubuntu, I found another flaw in the build system: the CMAKE_INSTALL_RPATH is not updated when the user provides a custom DESTDIR during installation.

Just get rid of DESTDIR. That's non-standard anyway and everyone should use CMAKE_INSTALL_PREFIX instead.

Installing ESPResSo with `make install DESTDIR="/path/to/es"` will
install files in the wrong folder and set an incorrect runtime path
in Cython shared objects, causing import errors. See full report:
espressomd#3228 (comment)
When installing ESPResSo, the C++ shared objects and Cython shared
objects are stored in the same folder. Since they have the same .so
extension, when importing espressomd.cluster_analysis, the file
cluster_analysis.py is loaded and the file cluster_analysis.so is
automatically considered a Cython shared object, and Python fails
to find the Cython-specific symbol PyInit_cluster_analysis. This
is remediated by giving a different name to the C++ shared object.
@junghans
Copy link
Member Author

DESTDIR is really only for packaging, i.e. to make a tarball with a certain RPATH encoded without installing it there, so don't use it here.

I would replace make install by cmake --install to allow for testing with ninja as well.

@jngrad
Copy link
Member

jngrad commented Oct 14, 2019

I would replace make install by cmake --install to allow for testing with ninja as well.

Nice feature! But this seems to be CMake 3.15-specific, which has been released very recently. We still support 3.4, and consider bumping to 3.10 in the next release.

Install the files in a different directory and check the python and
tutorials/samples tests can still run with the installed files.
Please note that pypresso will experience a major slowdown in CI
when located outside the build directory, hence the 3h timeout.
This job is meant to be run only during releases and in PRs that
add new core modules.
@junghans
Copy link
Member Author

I would replace make install by cmake --install to allow for testing with ninja as well.

Nice feature! But this seems to be CMake 3.15-specific, which has been released very recently. We still support 3.4, and consider bumping to 3.10 in the next release.

Then if clause it depending on the CMale version, in CMake-3.4 you could at least use cmake --build instead of make all.

Takes more than 1 hour to run in CI when pypresso is located
outside the build directory.
jngrad added a commit to jngrad/espresso that referenced this pull request Oct 15, 2019
Installing ESPResSo with `make install DESTDIR="/path/to/es"` will
install files in the wrong folder and set an incorrect runtime path
in Cython shared objects, causing import errors. See full report:
espressomd#3228 (comment)
bors bot added a commit that referenced this pull request Oct 15, 2019
3248: Fix cmake install on dev branch r=KaiSzuttor a=jngrad

Porting #3228 to the dev branch

Description of changes:
- fix the CMake build system to include libraries in the list of installed files and test it in a dedicated CI job
- fix the versioning of Cython .so shared objects
- simplify the CMake tests


3251: Particle data r=jngrad a=fweik

Fixes #3157.

Description of changes:
 - Split definition of `struct Particle` from rest of particle data.


Co-authored-by: Christoph Junghans <[email protected]>
Co-authored-by: Jean-Noël Grad <[email protected]>
Co-authored-by: Florian Weik <[email protected]>
The installed files only exist if the Python bindings are enabled.
The clang:6.0 job fails due to undefined ASAN symbols.
The logic to fix that error is in the pypresso wrapper.
jngrad added a commit to jngrad/espresso that referenced this pull request Oct 15, 2019
3228: Fix cmake install

Description of changes:
- fix the CMake build system to include libraries in the list of installed files and test it in a dedicated CI job
- fix the versioning of Cython .so shared objects
- simplify the CMake tests
@jngrad
Copy link
Member

jngrad commented Oct 15, 2019

This PR was merged into the open PR for the 4.1.1 release candidate.

@jngrad jngrad closed this Oct 15, 2019
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.

3 participants