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

Upgrade to Conan 2 #747

Merged
merged 15 commits into from
Feb 19, 2024
Merged

Upgrade to Conan 2 #747

merged 15 commits into from
Feb 19, 2024

Conversation

kyllingstad
Copy link
Member

@kyllingstad kyllingstad commented Nov 20, 2023

This fixes issue #718, “Conan v2 compatibility”. (Note that it also destroys Conan 1.x compatibility – it was simply too difficult to maintain support for both major versions.)

Some collateral changes warrant further explanation:

  • The modified <gsl/util> includes and various changes from int to std::size_t are a consequence of using a newer version of MS GSL. I changed the dependency version so we can use an upstream CMake package configuration file which is compatible with the one generated by Conan 2's CMakeDeps generator. This should enable us to use the same find_package() commands and target names regardless of whether the build is running under Conan or not.
  • I've modified the “non-Conan” CI workflow to build in a clean Docker container like the Conan CI workflow. I've based the container on Debian Bookworm, whose packages for our dependencies are new enough that all provide CMake package configuration files which match those generated by CMakeDeps, which was my main motivation. The MS GSL package mentioned in the previous point is one such. (Also, the GitHub runners are such a noisy and unpredictable build environment that I figured this would be more efficient than try to fix compatibility issues there.)
  • I've had to remove the option to run Conan from within CMake, because upstream hasn't released a version of the cmake-conan helper script with full support for all Conan 2 features yet. (Notably, support for the CMakeToolchain generator is missing.)

The pull request depends on open-simulation-platform/proxy-fmu#92, which should be merged first. Then, the osp/testing-… channel should be replaced in the proxyfmu requirement specification in conanfile.py before merging the present PR.

Incidentally, this PR also fixes issue #702.

This fixes issue #718 (and incidentally fixes #702 too).

The modified `<gsl/util>` imports and various changes from `int` to
`std::size_t` are a consequence of using a newer version of MS GSL. I
changed the dependency version so we can use an upstream CMake package
configuration file which is compatible with the one generated by Conan
2's `CMakeDeps` generator. This should enable us to use the same
`find_package()` commands and target names regardless of whether the
build is running under Conan or not.

This also removes the ability to run Conan from within CMake, because
upstream hasn't released a version of the cmake-conan helper script with
full support for all Conan 2 features yet. (Notably, support for the
`CMakeToolchain` generator is missing.)
@kyllingstad kyllingstad added the enhancement New feature or request label Nov 20, 2023
@kyllingstad kyllingstad self-assigned this Nov 20, 2023
This was linked to issues Nov 21, 2023
@kyllingstad kyllingstad linked an issue Nov 21, 2023 that may be closed by this pull request
@kyllingstad kyllingstad linked an issue Nov 21, 2023 that may be closed by this pull request
@kyllingstad
Copy link
Member Author

Seems like this PR closes several build-related issues. I linked them now.

self.options["xerces-c"].shared = self.options.shared
if self.options.shared:
self.options.rm_safe("fPIC")
self.options["*"].shared = self.options.shared
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for setting shared option for all dependencies? Also can you check if ["*"] is correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, it's the same as setting the top-level attribute

default_options = {"*:shared": True}

It's a suggestion for what the shared option for all dependencies (that have such an option) should be, but it can be overridden by the user or superseded by other packages in the dependency tree.

Copy link
Member Author

Choose a reason for hiding this comment

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

And it is correct, it was taken from an example on this page of the Conan docs: https://docs.conan.io/2.0/reference/conanfile/methods/configure.html

Comment on lines +46 to +48
self.requires("boost/[~1.81]", transitive_headers=True) # Required by Thrift
else:
self.requires("boost/[>=1.71]", transitive_headers=True)
Copy link
Contributor

@davidhjp01 davidhjp01 Dec 6, 2023

Choose a reason for hiding this comment

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

It seems libcosim consumers need to explicitly declare self.requires("boost/[~1.81]") to use boost in their code, for example boost::timer. Otherwise linking fails.

I probably not fully understand the "traits" from the conan doc yet, but may be transitive_libs allows the consumers to link boost declared here? So that "downstream" (e.g. libcosim consumers) can also use the same boost version in their code, without accidentally declaring mismatching boost version.

Copy link
Member Author

Choose a reason for hiding this comment

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

The way I see it, consumers who use Boost directly in their own code should list it as an explicit dependency and not rely on the indirect dependency from libcosim. However, if they only need Boost to be able to link with libcosim, then it should be handled automatically. I'm actually not sure whether transitive_libs is required in that case; I'll try to find out.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the reason I specified transitive_headers is because libcosim headers include some Boost headers, so client code must have them on the include path.

Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out you were right about this, @davidhjp01. Since we use Boost in some libcosim headers, and more specifically Boost libraries that have binary components (i.e., are not header-only), such as Boost.Log, then we need to have transitive_libs=True here. Otherwise, client code won't have access to those binary components for linking. I'll make a new pull request.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be resolved by #753.

… the `package_info` method.

This is because otherwise CMakeDeps incorrectly generates the dependency in the target cmake file as `libcosim::libcosim`. (i.e. <consumer>-Target-release.cmake, see https://docs.conan.io/2/reference/tools/cmake/cmakedeps.html#generated-files). This would not be found via `find_package(libcosim REQUIRED)`.
@davidhjp01
Copy link
Contributor

davidhjp01 commented Feb 14, 2024

@kyllingstad @restenb

  • Wondering if we should remove Debug builds because it seems the case for the most of the libraries in conan2 public repository (to avoid lengthy github action builds).
  • Also for some reason conan2 tries to rebuild some of the libraries for the Release builds, i guess due to some mismatching conan2 options?

Edit
It is because there are no gcc-9 builds available in conancenter

gcc9 builds are not available from conancenter. Built libraries are uploaded to osp jfrog.
@davidhjp01
Copy link
Contributor

I have addressed the most of the issues related to the failing builds. I suggest to merge and release libcosim and proxyfmu so that other projects dependent on conan2 library can consume them.

@davidhjp01 davidhjp01 merged commit bce2132 into master Feb 19, 2024
20 checks passed
@davidhjp01 davidhjp01 deleted the feature/conan-2 branch February 19, 2024 12:33
@kyllingstad
Copy link
Member Author

@davidhjp01, sorry for dropping the ball on this at the end of last year, and huge thanks to you for picking it up! It's really good to finally get this merged.

@kyllingstad
Copy link
Member Author

Following up on your question (too late for this PR, unfortunately):

Wondering if we should remove Debug builds because it seems the case for the most of the libraries in conan2 public repository (to avoid lengthy github action builds).

Yes, I think that sounds like a good idea. I don't think I can remember a case where the release builds succeeded while the debug builds failed or vice versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants