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

RSDK-7861 Conan dependencies #283

Merged
merged 46 commits into from
Sep 19, 2024
Merged

Conversation

lia-viam
Copy link
Contributor

@lia-viam lia-viam commented Aug 19, 2024

Dependency management with conan--provides a recipe for packaging the SDK with conan and some examples/docs to support

Currently tested on mac as well as bullseye docker container, featuring configuration options listed in the options of the conanfile.py

TBD:

  • building in CI
  • test_package that assesses if static builds are working

@lia-viam lia-viam requested a review from acmorrow August 19, 2024 21:14
@lia-viam lia-viam requested a review from a team as a code owner August 19, 2024 21:14
@lia-viam lia-viam requested review from njooma and purplenicole730 and removed request for a team August 19, 2024 21:14
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

This looks like a great start, various questions and suggestions.

CMakeLists.txt Outdated Show resolved Hide resolved
conanfile.txt Outdated Show resolved Hide resolved
src/viam/api/CMakeLists.txt Outdated Show resolved Hide resolved
src/viam/api/config/invoke_buf_generate.cmake.in Outdated Show resolved Hide resolved
src/viam/api/CMakeLists.txt Outdated Show resolved Hide resolved
@acmorrow
Copy link
Member

@lia-viam - Is this ready for another round of review?

@lia-viam
Copy link
Contributor Author

lia-viam commented Sep 9, 2024

@acmorrow still needs work! last commits were just what I managed to fit in before vacation

@lia-viam
Copy link
Contributor Author

lia-viam commented Sep 10, 2024

@acmorrow just re-requested a review, this is now in a state I'm more proud of. Before merging I would like to think about doing some of the following in CI

  1. Using conan create . to make sure the package and its test package build successfully
  2. Building a second version of the CMake example project in CI
  3. Possibly for releases only? Testing conan create . with the full CI matrix

The possible pain point here is that we are already building from source, but then conan create . will build the world anew, but this is needed to test the example project which I think we want to be doing to prevent code rot like with the previous examples.

During development on this I kept wishing for RSDK-4735 so it might be nice to get that in soon, and would make it a bit less onerous to do the double build if that's the route we go.

We also could just make it so conan stuff is a separate CI job which only gets built on releases.

@purplenicole730 purplenicole730 removed their request for review September 11, 2024 20:00
@@ -148,6 +148,121 @@ an installation tree under `build/install`.

If the build did not succeed, please see the next section.

## Building with `conan`
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know what conan is. I think it would be nice to add a docs link closer to the beginning (maybe hyperlinked to its first mention) so users can familiarize themselves with the 3rd party pkg

(I initially read canon like James' docker thing haha)

BUILDING.md Outdated
while using `conan` to get dependencies instead of your system package
manager. Note that Option 1 implies a superset of Option 2.

### Creating and consuming the SDK `conan` package.
Copy link
Member

Choose a reason for hiding this comment

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

This is option 1 right? Can we do Option 1: Creating and consuming the SDK conan package.

BUILDING.md Outdated
or look at the [`test_package/conanfile.py`](test_package/conanfile.py)
which is the test package recipe.

### Using `conan` to manage the SDK dependencies
Copy link
Member

Choose a reason for hiding this comment

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

Same thing for Option 2:

Comment on lines +217 to +220
Note that this can be done with the same `CMakeLists.txt` from the
[example project](src/viam/examples/project/cmake/CMakeLists.txt): it is
agnostic of the use of `conan` to package the SDK as opposed to the SDK
having been built and installed manually.
Copy link
Member

Choose a reason for hiding this comment

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

Is this due to the flexibility of using find_package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty much yeah! In the snippet above when you do cmake --preset=conan-release that's where conan makes it so that find_package will know about the packages it has installed, but all of that takes place on the command line rather than intrusively in the CMakeLists.txt itself

@lia-viam
Copy link
Contributor Author

@hexbabe thanks for the doc comments, I've pushed some changes!

Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

This looks really good. All small things / questions and a few small suggestions. My only real concern is re the hardcoded version numbers.

CMakeLists.txt Outdated Show resolved Hide resolved
src/viam/api/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
conanfile.py Outdated

class ViamCppSdkRecipe(ConanFile):
name = "viam-cpp-sdk"
version = "0.0.10"
Copy link
Member

Choose a reason for hiding this comment

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

There will need to be something in the release process to advance this number, or it will surely drift. Can we derive it somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this was bugging me as well and I stumbled on this in the old 1.x conan docs:
https://docs.conan.io/en/1.4/howtos/capture_version.html
Going to ask online if this is still considered acceptable

Copy link
Member

Choose a reason for hiding this comment

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

If there isn't a good way, we can always doc it in the release process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: turns out set_version does what I needed

conanfile.py Show resolved Hide resolved
conanfile.py Show resolved Hide resolved
@@ -0,0 +1,6 @@
[requires]
viam-cpp-sdk/0.0.10
Copy link
Member

Choose a reason for hiding this comment

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

Ditto re version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so this part I think we might not be able to derive the version programatically. In keeping with the spirit that stuff in the examples/project directory should be usable as starter code, a conanfile.txt is the easiest way to get started with a conan project that depends on the SDK.

A conanfile.py could in theory get the version like the root conanfile.py as sketched above, but then this would be grabbing a version from ../../../../CMakeLists.txt which would probably merit an all-caps warning comment to delete that in your own project and write in an explicit version.

We could specify a version range like viam-cpp-sdk/[>=0.0.12] (or whichever release this lands in) but I don't love that.

I think the last option is that if the SDK release instructions say "manually bump the version in the CML.txt and also the example project conanfile.txt" which might not be so terrible

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I hadn't really caught that this was in the example. I just saw a hardcoded version and the usual reflexes kicked in. I don't know: I sort of find the viam-cpp-sdk/[>=0.0.12] sort of intuitively appealing? Can you elaborate on why you don't love it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it might be fine actually, looking at https://docs.conan.io/2/tutorial/versioning/version_ranges.html it seems like it will prefer to use the newer one if available, just trying to imagine a situation where the user is accidentally getting an old version because they hadn't yet built a new one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to using a version range!

@@ -237,6 +237,8 @@ target_link_libraries(viamsdk
PRIVATE absl::strings
PRIVATE viam_rust_utils
PRIVATE Threads::Threads
PRIVATE $<$<PLATFORM_ID:Linux>:dl>
Copy link
Member

Choose a reason for hiding this comment

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

Not that it matters, but I'd bet a shiny nickel these are needed on, say, BSD. Is there a more general platform tag than Linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to ask you about that, it comes up in the conanfile too. It seems to be idiomatic to do the following:
https://github.com/conan-io/conan-center-index/blob/master/recipes/grpc/all/conanfile.py#L302
And I figured we may as well do the same even if we don't claim in the README to support BSD. But yes I can do a Linux || BSD clause here and in the conanfile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the sdk/CML.txt we do an if (APPLE) to link -framework Security so I may just spell this as an if (NOT APPLE)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the reason for that -framework Security is interesting, btw: https://github.com/viamrobotics/viam-cpp-sdk/pull/146/files#r1334516668.

Essentially, it is viam_rust_utils that has a dependency on the Security framework on macOS. However, since we don't obtain viam_rust_utils via a find_package like thing, there is no way for it to express its transitive dependencies.

I'm not particularly happy about needing to do that, but I don't have a better answer.

Regarding your suggestion to make this just be "not apple", I think that makes sense. Maybe do "not apple and not windows?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh that explains a lot, I think that's why I ended up needing to add librt and libdl too, I was getting linker errors from viam_rust_utils on the static build without them.

As for not windows, I don't think there is currently any mention of windows in our build files, are we hoping to be able to offer it down the road?

CMakeLists.txt Show resolved Hide resolved
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

LGTM!

@lia-viam lia-viam changed the title Draft: RSDK-7861 Conan dependencies RSDK-7861 Conan dependencies Sep 19, 2024
@lia-viam lia-viam merged commit fe83db6 into viamrobotics:main Sep 19, 2024
3 checks passed
@lia-viam lia-viam deleted the feature/conan-deps branch September 19, 2024 19:47
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.

3 participants