bernedom / SI

A header only C++ library that provides type safety and user defined literals for physical units
https://si.dominikberner.ch/doc/
MIT License
486 stars 40 forks source link

Unable to build code from instructions: broken recipe (conan 2.0 issue?) #121

Closed chiphogg closed 1 year ago

chiphogg commented 1 year ago

Describe the bug I checked out the repo and tried to build the code and tests, so I could start playing with the library.

To Reproduce Steps to reproduce the behavior:

  1. On a clean system, install conan: pip install conan
  2. Follow these instructions (https://github.com/bernedom/SI#building--compatibility)
  3. The cmake .. step fails, complaining about missing CMAKE_BUILD_TYPE setting
  4. Run cmake -DCMAKE_BUILD_TYPE=Debug .. instead. Now it complains about not having a conan profile.
  5. Create a conan profile: conan profile detect --force
  6. Re-run the command in step 4. Now it complains the recipe is broken

Error message from step 3:

-- The CXX compiler identification is GNU 11.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Downloading conan.cmake from https://github.com/bernedom/cmake-conan
-- Conan: Automatic detection of conan settings from cmake
CMake Error at build/test/conan.cmake:82 (message):
  Please specify in command line CMAKE_BUILD_TYPE
  (-DCMAKE_BUILD_TYPE=Release)
Call Stack (most recent call first):
  build/test/conan.cmake:496 (conan_cmake_settings)
  test/CMakeLists.txt:21 (conan_cmake_run)

-- Configuring incomplete, errors occurred!
See also "/home/chogg/github/SI/build/CMakeFiles/CMakeOutput.log".

Error message from step 4:

-- Conan: Automatic detection of conan settings from cmake
-- Conan: Settings= -s;build_type=Debug;-s;compiler=gcc;-s;compiler.version=11;-s;compiler.libcxx=libstdc++11
-- Conan: checking conan executable
-- Conan: Found program /home/chogg/.local/bin/conan
-- Conan: Version found Conan version 2.0.7

-- Conan executing: /home/chogg/.local/bin/conan install /home/chogg/github/SI/test/conanfile.txt -s build_type=Debug -s compiler=gcc -s compiler.version=11 -s compiler.libcxx=libstdc++11 -g=cmake --build=missing
ERROR: The default build profile '/home/chogg/.conan2/profiles/default' doesn't exist.
You need to create a default profile (type 'conan profile detect' command)
or specify your own profile with '--profile:build=<myprofile>'
CMake Error at build/test/conan.cmake:402 (message):
  Conan install failed='1'
Call Stack (most recent call first):
  build/test/conan.cmake:497 (conan_cmake_install)
  test/CMakeLists.txt:21 (conan_cmake_run)

-- Configuring incomplete, errors occurred!
See also "/home/chogg/github/SI/build/CMakeFiles/CMakeOutput.log".

Subset of error message from step 6:

======== Computing dependency graph ========
catch2/2.13.6: Not found in local cache, looking in remotes...
catch2/2.13.6: Checking remote: conancenter
catch2/2.13.6: Downloaded recipe revision 83b861708ded6e779474712fec3c9382
Graph root
    conanfile.txt: /home/chogg/github/SI/test/conanfile.txt
*********************************************************
Recipe 'catch2/2.13.6' seems broken.
It is possible that this recipe is not Conan 2.0 ready
If the recipe comes from ConanCenter check: https://conan.io/cci-v2.html
If it is your recipe, check if it is updated to 2.0
*********************************************************

ERROR: Package 'catch2/2.13.6' not resolved: catch2/2.13.6: Cannot load recipe.
Error loading conanfile at '/home/chogg/.conan2/p/catchc541e95bb045a/e/conanfile.py': Unable to load conanfile in /home/chogg/.conan2/p/catchc541e95bb045a/e/conanfile.py
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/chogg/.conan2/p/catchc541e95bb045a/e/conanfile.py", line 3, in <module>
    from conans import ConanFile, CMake, tools
ImportError: cannot import name 'ConanFile' from 'conans' (/home/chogg/.local/lib/python3.10/site-packages/conans/__init__.py)
.
CMake Error at build/test/conan.cmake:402 (message):
  Conan install failed='1'
Call Stack (most recent call first):
  build/test/conan.cmake:497 (conan_cmake_install)
  test/CMakeLists.txt:21 (conan_cmake_run)

-- Configuring incomplete, errors occurred!
See also "/home/chogg/github/SI/build/CMakeFiles/CMakeOutput.log".

Expected behavior I expected the step to succeed, so I could run the following command and run the tests.

Screenshots N/A

Desktop (please complete the following information):

Smartphone (please complete the following information): N/A

Additional context I am not well versed in conan and cmake; I'm rather spoiled by bazel. It's possible that I'm making some basic mistake. However, it looks like this could be consistent with the upgrade to conan 2, which I know has broken a bunch of other packages, including mp-units.

bernedom commented 1 year ago

Thanks for raising the issue. It seems that conan 2.0 broke cmake-conan. https://github.com/conan-io/cmake-conan

I will adapt the CMake files accordingly.

bernedom commented 1 year ago

I'm currently fixing it in the following branch, if you want to try it out. https://github.com/bernedom/SI/tree/building/make-conan-2-compatible

To build without the tests (only install and packaging instructions will be generated as SI is header only)

cmake -S . -B build
cmake --build build

To build including the tests use:

conan install . --output-folder=build --build=missing --settings=build_type=Debug
cmake -B build -S . --toolchain ./build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug
cmake --build build -- -j $(nproc)
chiphogg commented 1 year ago

This worked for me! I was able to build all of the code. I changed one of the tests to make it fail, and I was able to figure out how to run the test, and saw that it failed.

bernedom commented 1 year ago

I updated the build instructions and CI pipeline to work with conan2