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

[spdlog] Add support for Conan v2 #11981

Merged
merged 29 commits into from
Aug 25, 2022

Conversation

uilianries
Copy link
Member

@uilianries uilianries commented Jul 30, 2022

Some point are still missing:

  • When building with Conan 2.0.0-beta2, the test_package is not able to find fmt:
$ conan create . --version 1.10.0
...
-------- Testing the package --------
spdlog/1.10.0 (test package): Generator 'CMakeDeps' calling 'generate()'
spdlog/1.10.0 (test package): Generator 'CMakeToolchain' calling 'generate()'
spdlog/1.10.0 (test package): Calling generate()
spdlog/1.10.0 (test package): Aggregating env generators

-------- Testing the package: Building --------
spdlog/1.10.0 (test package): Calling build()
spdlog/1.10.0 (test package): CMake command: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/."
spdlog/1.10.0 (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/."
Capturing current environment in /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/generators/deactivate_conanbuildenv-release-armv8.sh
Configuring environment variables
-- Using Conan toolchain: /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'spdlog::libspdlog'
-- Conan: Target declared 'spdlog::spdlog'
-- Conan: Component target declared 'fmt::fmt'
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/Release
spdlog/1.10.0 (test package): CMake command: cmake --build "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/Release" -- -j10
spdlog/1.10.0 (test package): RUN: cmake --build "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/Release" -- -j10
Capturing current environment in /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_output/build/generators/deactivate_conanbuildenv-release-armv8.sh
Configuring environment variables
[ 50%] Building CXX object CMakeFiles/test_package.dir/test_package.cpp.o
In file included from /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/test_package.cpp:21:
In file included from /Users/uilian/.conan2/p/9bf6e779e3a5d9e5/p/include/spdlog/spdlog.h:12:
In file included from /Users/uilian/.conan2/p/9bf6e779e3a5d9e5/p/include/spdlog/common.h:45:
/Users/uilian/.conan2/p/9bf6e779e3a5d9e5/p/include/spdlog/fmt/fmt.h:27:14: fatal error: 'fmt/core.h' file not found
#    include <fmt/core.h>
             ^~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/test_package.dir/test_package.cpp.o] Error 1
make[1]: *** [CMakeFiles/test_package.dir/all] Error 2
make: *** [all] Error 2
ERROR: spdlog/1.10.0 (test package): Error in build() method, line 30
	cmake.build()
	ConanException: Error 2 while executing
  • The validate method needs self.info.options which has support to get_safe on Conan 2.0, but it's not supported by Conan 1.51.0. Thus, validate does not work with self.info.clear() under the package_id:
 % conan create . 1.10.0@ -o spdlog:header_only=True
Exporting package recipe
spdlog/1.10.0 exports: File 'conandata.yml' found. Exporting it...
spdlog/1.10.0 exports: Copied 1 '.yml' file: conandata.yml
spdlog/1.10.0: A new conanfile.py version was exported
spdlog/1.10.0: Folder: /Users/uilian/.conan/data/spdlog/1.10.0/_/_/export
spdlog/1.10.0: Using the exported files summary hash as the recipe revision: 6906d80bd4a6937dbe4803736aa6d493 
spdlog/1.10.0: Exported revision: 6906d80bd4a6937dbe4803736aa6d493
Configuration:
[settings]
arch=armv8
arch_build=armv8
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
os_build=Macos
[options]
spdlog:header_only=True
[build_requires]
[env]
[conf]
tools.build.cross_building:can_run=True

fmt/8.1.1: Main binary package 'f6f0bd9a24061ce292df409b9e672062a0b73d15' missing. Using compatible package '2ab5e7a71f81ed7ec68723743c780f2a172fdd49'
ERROR: Traceback (most recent call last):
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/errors.py", line 34, in conanfile_exception_formatter
    yield
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/client/graph/graph_binaries.py", line 420, in _compute_package_id
    conanfile.validate_build()
  File "/Users/uilian/.conan/data/spdlog/1.10.0/_/_/export/conanfile.py", line 68, in validate_build
    if self.options.shared and is_msvc_static_runtime(self):
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/model/options.py", line 569, in __getattr__
    return getattr(self._package_options, attr)
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/model/options.py", line 447, in __getattr__
    self._ensure_exists(field)
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/model/options.py", line 443, in _ensure_exists
    raise ConanException(option_not_exist_msg(field, list(self._data.keys())))
conans.errors.ConanException: option 'shared' doesn't exist
Possible options are ['header_only', 'wchar_support', 'wchar_filenames', 'no_exceptions']
  • If I move validate to validate_build and, follow old fashion way, without self.info, it works, but during the package, it's not able to find its targets:
$ conan create . 1.10.0@ -o spdlog:header_only=True
...
spdlog/1.10.0 (test package): CMake command: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/build/generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/."

----Running------
> cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/build/generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/."
-----------------
-- Using Conan toolchain: /Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/build/generators/conan_toolchain.cmake
-- Conan: Component target declared 'spdlog::libspdlog'
-- Conan: Target declared 'spdlog::spdlog_header_only'
-- Conan: Component target declared 'fmt::fmt'
-- Configuring done
CMake Error at CMakeLists.txt:14 (target_link_libraries):
  Target "test_package" links to:

    spdlog::spdlog

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.



-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
ERROR: Traceback (most recent call last):
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/errors.py", line 34, in conanfile_exception_formatter
    yield
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/client/conanfile/build.py", line 16, in run_build_method
    conanfile.build()
  File "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/conanfile.py", line 29, in build
    cmake.configure()
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conan/tools/cmake/cmake.py", line 97, in configure
    self._conanfile.run(command)
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/model/conan_file.py", line 443, in run
    raise ConanException("Error %d while executing %s" % (retcode, command))
conans.errors.ConanException: Error 1 while executing cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/build/generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/Users/uilian/Development/conan/conan-center-index/recipes/spdlog/all/test_package/."

This same error occurs with the fmt package.


  • I've read the guidelines for contributing.
  • I've followed the PEP8 style guides for Python code in the recipes.
  • I've used the latest Conan client version.
  • I've tried at least one configuration locally with the conan-center hook activated.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

prince-chrismc
prince-chrismc previously approved these changes Aug 5, 2022
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries uilianries removed the blocked Affected by an external issue and waiting until it is solved label Aug 5, 2022
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot

This comment has been minimized.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries uilianries marked this pull request as draft August 5, 2022 08:49
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@conan-center-bot
Copy link
Collaborator

All green in build 24 (aa09a8291c16fceba3acbd82be2144ddbf288d1e):

  • spdlog/1.8.5@:
    All packages built successfully! (All logs)

  • spdlog/1.9.2@:
    All packages built successfully! (All logs)

  • spdlog/1.10.0@:
    All packages built successfully! (All logs)

Comment on lines +112 to +113
cmake_deps = CMakeDeps(self)
cmake_deps.generate()
Copy link
Contributor

Choose a reason for hiding this comment

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

CMakeDeps not needed if header_only

Copy link
Member Author

Choose a reason for hiding this comment

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

True!

elif tools.Version(self.version) >= "1.5.0":
self.requires("fmt/6.2.1")
# TODO: Remove in Conan 2.0 - 1.x self.requires does not support transitive_headers
requires = lambda ref: self.requires(ref, transitive_headers=True) if Version(conan_version) >= "2.0.0-beta" else self.requires(ref)
Copy link
Contributor

@SpaceIm SpaceIm Aug 25, 2022

Choose a reason for hiding this comment

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

What does transitive_headers=True mean? Ok: https://docs.conan.io/en/2.0/reference/conanfile/methods.html?highlight=transitive_headers#transitive-headers, some sort of PRIVATE vs INTERFACE. It's not clear in the documentation what is the default value, nor if it's as smart as PRIVATE/PUBLIC/INTERFACE CMake properties.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, I needed to ask Conan devs to understand. The fmt header is required in a public spglog header, but on the test package, fmt headers are not available by default, so to avoid the failure, we need trasitive_headers.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll be working on the docs more and more.
Best reference as of know I think is this talk https://www.youtube.com/watch?v=kKGglzm5ous&t=2025

My understanding is it should be the "same" as CMake's at least in concept 🤞

Copy link
Contributor

@SpaceIm SpaceIm Aug 28, 2022

Choose a reason for hiding this comment

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

conan 1.52 will allow these arguments in self.requires (see conan-io/conan#11934), but my understanding is that it will be a no-op in conan v1 mode (everything is always public), it's just a way to ease the migration of recipes to conan v2, since the default value of transitive_* arguments is False.

Copy link
Contributor

Choose a reason for hiding this comment

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

That pr is directly from this work #11981 (comment)

Which is why this migration is super important

Once 1.52 is available we cam clean this one up 👍

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.

4 participants