Sharing your Conan packages is now easier than ever
Feb 09, 2024
I'm a big fan of the Conan package manager, but one of the biggest pain points is sharing your custom Conan packages with other people. Your options for doing so are generally one of these:
- Put it on Conan Center
- Put it on your own Conan server
- Put the recipe in a git repo, and tell users to manually clone and build/export it into their Conan cache
Option 1 is laborious and time consuming, and isn't possible (nor desirable) for a lot of use cases. There are only so many volunteers working on Conan Center, so it's unreasonable for them to accept every package. And regardless, packages on Conan Center need to meet certain requirements that make sense for the common case, but not necessarily for every use case (e.g. modified forks of existing packages).
Option 2 is neither easy nor cheap. Of course, the Conan server software is free and open source, and there's even a free version of Artifactory that has a lot more features. However, it requires you to install and maintain an application server and worry about costs, security, etc if you expose it to the public.
And finally, Option 3 is just annoying for users. Not only do they have to manually execute
git clone ... and
conan export ..., they also need to compile the package binaries themselves.
Redirectory is a project I discovered recently that aims to make it easier to share Conan packages. Basically, it implements the Conan server API, but uses Github Releases to upload and download packages. This lets you distribute your Conan binary packages for free using Github's powerful network!
Not only that, but the developer graciously offers his own free instance of the server that you can use without having to setup your own. That means you can start using it right now with this single command:
That's it! There's no need to login or anything. When you want to use a package, you just need to add
@github/username to the package reference.
Here's an example of how to access one of the packages on my Github account:
1 2 3
Side note: you wouldn't actually use wafgenerator in a conanfile.txt, this is just for demonstation purposes!
conan install with that conanfile will just work. Conan won't find anything with the
@github/alexramallo user/channel on Conan Center, so it will look in the other remotes. The redirectory server will respond to it, and return a download link that matches the given Github user and repo.
Uploading your own packages
Uploading your own packages is easy, but the paranoid may want to host their own server rather than use the public redirectory one. To upload a package, you need to login to redirectory with a github personal access token that has read/write access to your repos.
I have no reason to doubt the Redirectory dev's trustworthiness (on the contrary; his Github profile has a real identity, which is always a good sign), however as a general principle it's not a good idea to share access tokens like this, especially if your Github account has access to your employer's repos.
Note: redirectory doesn't store your token after it uses it; your Conan client stores it locally with all your other credentials
Regardless of what you do, once you have your token it's easy to start uploading packages:
Then just execute
conan upload -rredirectory ... like you normally would. The Redirectory server will create a github release in the repo that matches the package name.
Even though Conan Center is a great resource, it's not easy or possible to get everything on there. Having this alternative could be a good way to increase adoption of Conan among open source users since it greatly reduces the barriers to entry for people making packages.
© Alejandro Ramallo 2024