 I'll show you Conan and how we use it to package C and C++ dependencies. But first, I'll introduce myself briefly. So I'm Théodore Rieu. I work at Tanker, based in Paris. And I use Conan a lot at work to package for Windows, every Mac OS, Linux, and Android and iOS. And I'm also a very proud one-time contributor, as you can see. So Tanker, we are doing an end-to-end encryption SDK. The first version is available in JavaScript. And we're currently actively developing the Android and iOS SDK. So when we decided to develop the native version, everyone in the team was really excited, because most of us are backend developers. But at one point, someone asked, well, what language should we use? And then, after a few days of constructive and intelligent discussions, we agreed on three key points that the language had to have. So the first of all is write once, run everywhere. Because we don't want to write everything in Swift, and then in Kotlin or Java, we wanted one code base. Then high performance, especially for mobile devices, and also great or at least good dependency management. And that's why we chose C++. Now I know what you're thinking, what the hell is this guy talking about? C++ and good dependency management don't do in the same slide. And it's true that usually it looks like this, for the usual C++ dependencies. I mean, who doesn't love to upgrade open SSL on Windows, for example, or Boost? But that was before Conan. So Conan is a C++ package manager. It works with other languages, but primarily designed around those. It's decentralized, so you can host your own server. That's what we do. It's open source, available on GitHub. And it's written in Python. In Python, compatible with two and three. So you can read it everywhere. So I have two parts now. I have one, the basic package creation, upload and retrieval. So package management aspect. And after that, I'll show you more how we use Conan as a cross build tool for Android. So first, there's the Conan create method, which allows you to create packages. So you have a recipe that I'll show in a bit. You can, Conan create will read the recipe, run it, and it will store the package in your local cache. After that, there's the Conan upload method, which will find local packages you want to upload, and then upload it to the remote of your choice. So here's how a recipe looks like. It's playing Python. So we import this Conan file from the Conan's Python module. So the Conan file is the basic framework we will use. So I have a small library called arithmetic, which exposes a NAT function. And so I derive my arithmetic Conan class. So there's a few attributes named the version. And then there's the settings. So the OS and arch that you see here are the operating system and the architecture on which the package will run. Build type, debug or release, and then compiler. Now we need to retrieve sources. So I will fetch the source from my GitHub account and simply run git clone. And then I will use the CMake helper in the build method to configure, build, and install my project. I will only use CMake during this presentation. Conan provides a lot of helper. You can work with Messon, Auto Tools, and a lot of others, English. And then we need to expose to our consumers some information. In this case, which library they need to link against. There's other attributes by default like the include directory, which is named include by default. So you don't have to specify that. So then to consume package, you need to use the Conan install method. So there's an error in the slides here. It's not for any recipe. It checks requirements. So there's a Conan file.txt that I show in the next slide where you declare your requirements. So Conan install will read that file, then try to fetch packages either in your local cache or in remotes. And then finally it will generate build information files. In this case, CMake. So it will generate a Conan build info.cmake file containing every include library directory, targets, et cetera, et cetera, like a PKG config file. So in our Conan file.txt, we have simply this section requires and we have to put references to our packages. In Conan, references are composed of the name of the package, its version, and then a user name and a channel. So the user name is usually the author of the recipe. In this case, me. And the channel can be compared to a git branch. So in Conan, by default, the stable branch, the stable channel is the master branch. And then we need to tell Conan we want a CMake file generated. Here you can put a lot of other things. So I said PKG config can use even Xcode files. Don't use that, but you can use that. And then one final thing to change to our project. So this is a CMake.txt that was written before the Conan integration. As you can see, we have our calculator project. We have a fine package. Then add executable. And finally, we link our executable to the package that we found. If you use fine package with Conan, there's only two lines to include. You have to include the file that Conan generated previously. And then you need to call this Conan basic set of macro. And that's it. If you like me and you don't like writing package files, you can simply use the target's argument to the Conan basic set of macro. And then Conan will create a namespace named ConanPKG and add a target for each of your dependencies. So here I replaced the arithmetic dot dot arithmetic by ConanPKG arithmetic. So time for a little demo. So I'm inside the arithmetic folder. And I will use ConanCreate to create the package. So ConanCreate, it needs two arguments. You pass to the recipe and the username and channel. So in the... So here you can see Conan is running the source method. So cloning in the GitHub. Now it's launching CMake to build the package, install, and done. And here we can see with the Conan search method. I will... Oh, arithmetic... And here we can see we have a package in our local cache with all those settings. So now I want to upload this package to my Bintree account. So I have one remote. Let's go for them. And then I rewrite this. You can see I upload the recipe. And then the package.gz. So now I will try to use my package. I will on purpose remove it from my local cache to show you the fetching from this server. So I'm going to remove... So I have my Conan file at txt in my CMake. There's only the two include lines like I showed you before. So let's create a build directory. And then run Conan install and give it the path to the Conan file at txt. So it tried to run on the default, the official repository, remotes. You didn't find anything. And so it found and enforced them to 2018. Download the package. And here generated the CMake file. Now all I need to do is CMake. Run CMake. Run Ninja and you can use our creator. Conan auto-detected my settings. But you can specify your own. Like here, let's say I have GCC7. And I want to use a really old version of GCC6. And I use the dash S options to specify the setting. So let's say we want to build for Clang5 with the newest GCCABI debug build. It gets a bit tricky because it's hard to type, it's long enough. So there's a solution. You can use profiles instead. And that's what you can use when you don't write any settings. It generates a default profile. So that's D1, generated on my machine, Linux, X64, GCC7, and quick PSA. By default, Conan will put the libstude C++, the old GCCABI, as a default. If you want the newest, you have to use libstude C++11. That's not something you want to discover after building 30 packages. Like me. So let's refactor our command line. And we'll use simply Clang version 5 with the newest GCCABI in debug mode. And now we'll simply rerun Conan create. Now with the double dash profile option and giving our profile. You can still use the dash S option to specify setting to override the default ones or the ones specified in your profile. So now I'll focus more on the cross building tool aspect and not so much the package management. To show you how we can use Conan packages to cross compile for Android quite simply. So we have a list of prerequisites for Android building. The NDK, of course. We will use standard on-drain tool chain. And we need a new Conan profile. But first I want to introduce build requirements. So if you have a package A which in its recipe is declaring set.onVinfo.foo equals bar. And that you have a package B that declares a build requirement on the package A. During the creation of package B, it will export the environment variable inside the environment of your shell. So inside package B you could do equal dollar foo and you have bar. Same thing with self-CPP info that we saw in the previous slide. If I declare self.cppinfo.sysroute equals the path to my Android sysroute, it will appear inside package B in the recipe as self.depthcppinfo.sysroute. And why is that useful? Because the CMake helper will be able to automatically detect that and set the sysroute accordingly. So what we'll do, we'll build a standard on-tool chain and have a build requirement on the NDK. And then we will throw the NDK and only use this tool chain. And here arithmetic will have also a build requirement on the tool chain. So before that, before showing you the recipes, there's our Android profile. As you can see the OS and Arch have been changed to Android, Arm V8. There's this OS API level that is specific to Android. And then we'll use Clang 5 with libc++. And there's two new settings that have been introduced in Conan Winepoint 0 to ease the development of build requirement packages. Because I want the NDK to run on my build platform, not on an Android device. And that's why OS build helps to make the difference. Otherwise you will get a libc++ compiler that can run on your mobile phone. You don't want to use that. So here OS build equals Linux and Arch build equals XZ4. So the NDK recipe, like before, same Conan file start. And then the settings, we only need OS build and Arch build. Because we will fetch the pre-compiled binary archive for Linux X64. Then this package method. I didn't use it in the previous slide because CMake installed already did the job. But here there's no CMake. And all we want to do is copy everything from the Android NDK uncompressed archive to our package folder. And then to be able to build a standalone tool chain, we need to have access to this build slash tools folder. That's why we put it in our set.onv4.path. So between in the standalone tool chain recipe, this build tools folder will be in the pass. And once this tool chain will be created, it will be removed. So the tool chain recipe, there's a problem in the slide. Same thing, we need OS build and Arch build. And then we declare our build requirement on the previous package that we built. In the build command, we only need this makes standalone tool chain.sh, which is located in the NDK tools folder. So we simply run it. And then in the package info, we set our sysroot. So build requirements can be specified in two ways, either in the recipe, but it's okay for a few packages. But here I want to use my tool chain each time that I want to cross compile. And I don't want to use it to add a build requirement in every recipe. So what I can do is add the build requires section in my profile and put it there. And now each time that I will use this profile, I will use this build requirement. So it's time for our final demo. I already don't need the NDK, so you won't have to watch the progress bar for ten minutes. So let's simply build the tool chain and enjoy it profile. I'm cheating a bit because I only handle one tool chain arm 64, and that's it for the sake of simplicity. And then I have my tool chain, so I can show you inside my local cache. Here I have everything already packaged. So let's go into our previous arithmetic folder, and you can create. So now we can see the Conan output. So here Conan tells us your course building from Linux 64 to Android arm 64. Same thing as before, and here there's a build requirement. So our tool chain has been correctly detected. Simply, we haven't changed the arithmetic recipe, which is great. And now CMake already finds everything, the API level, the ABI, etc. The compiler, everything gets built. So I can rerun Conan search, sorry. And now I have two packages. First one for my own machine, and here for Hatch and Android API 21. And that's it. So I added a few links, so our website, our documentation, our GitHub, and the Conan website, Conan GitHub. There's also a Slack channel on the CPP-length Slack. You can join the hashtag Conan. And I guess I'll take some questions from now. Yes? Does it work on the Windows? Does it work on the Windows? Yes, yes. Is it possible to directly build Dab or RPM packages from Conan? I know. So the question is, is this possible to build Dab or RPM packages directly from Conan? I don't know. I've only packaged C++ dependencies from... I have no knowledge in distribution package management, sorry. A bit of an intruder. But it might be possible. I don't know. I should check. Yes? How many packages are there, bring packages available already? How much did you need to do yourself? Okay. So the question is, how many packages are already available? Free packages. And how many I had to build myself? So I started to use Conan in the 0.20 version. So the focus was more on the code source and debugging, stabilization, et cetera. So there's more and more package on the Conan sender and the bin crafters repository for boost. There's a recipe for Android, iOS, et cetera, you can use. But I had to do lots myself. Yeah. Yes? Can you make a private repository or is it a standard? So can you make a private repository? We own our own Conan server on our server at work. And yeah, it's decentralized. So you can do whatever you want. You can host your own packages. That's what we do. Is Conan also useful in multi-language when there are also bindings involved? For example, if you have not only a C-library but also a quick backup. Okay. So the question is, does Conan only work on C and C++ binaries? You can package other languages, but the helpers are available. So the self.cppinfo, the CMake helper, et cetera, are more focused on C and C++. You can do that. I package GDK and I think it works also for Go. It doesn't really care about that. But maybe you have to use a different class than the Conan file. Let's say the Conan file framework is more designed around C and C++, but you could make your own for another language. Is this popular? Is there a dynamic behind this technology? Is there a competitor in the story? Is there competitors in this field? Is this dynamic? So there was previously an attempt for a C++ package manager. I think it was named BeCode and it's dead. But on their repository, the guys behind Conan are very reactive. They're backed by Jeff Frog and they work full-time on this. They're very welcoming. They post many issues and they will answer in the day. So how do we bootstrap so that it's decentralized and how do I know if there's already some channel out there which packages what I need? So how do I know if there's already packages for me on other remotes? So I use the Conan search method to search inside my own package. It's my own local cache. You could use it to look for remotes. By default you only have two or three remotes installed. But since I built everything almost myself, I had no use for Conan search, but I think it works great. You should try it then. Yes? I have a question. It's a bit the same, but is there a list of remotes or some sort of repository? Yes. So by default, sorry, the question is, is there a list of remotes that you can look for? By default, there's the Conan Center, really the stable master branch. The Conan Transit. And there's another organization, Minecrafters, that are making, they succeeded in making a modular boost installation. So I didn't think it was possible. They're doing a lot of packages. You can look for that. Yes? Is there any API for licensing? So is there any API for licensing? I haven't shown in the demo, but in the attributes you can use license. And I think it can be, yeah, a search in, I need to check, but it will surprise me if it didn't work. Yes? Is Conan relocation of the binaries? Sorry? Does Conan relocate the binaries to the downloads? So does Conan relocate the binaries in downloads? No, there's no, I don't think so. There's no, they don't touch the binaries once it's, so what do you mean exactly? I mean, how does it depend on where to find each other? Is that your responsibility? Ah, okay. So how does the packages find their own requirements? Well, you declared them. I haven't used that, but let's say I package Zlib and I want to depend on Zlib on another package. So I've shown the build requires attributes and there's also the requires attributes. Sure. So you just put, yes. It's linked, right? Yes. Do you put R paths or anything? Ah, for building for shell library, yeah, about R paths. So I mainly use static libraries at work, but for shell library you can, so yeah, okay, I get the, by default there's no R paths, R paths. For, on my course, they're all stripped, so you just have the name of the library and then it's your work to have some fun with install name tool, for example. So on that note, how do you deal with, suppose that you're on a system that has an older lib standard C++ and you build something with a newer lib standard C++, do you make the binary know where the new toolchain is or do you just, is that your responsibility too that you built this? So is that your responsibility to tell a binary where the C++ standard library is on the non-standard platform? So by default there's no R paths, but you can let them, you can, yeah, but I think I have to say in the toolchain, for example, for Android we want to build a tooling with the static lib C++, so we had to, in the toolchain, add link flags for every package built with that library and then it worked, but for shared I didn't use that, so it's quite a tricky question and maybe we can see after the talk, if you want. Yes? To avoid to mess up with like system libraries, there was a one like, if your package manager, like package manager, links or Spark, use a compiler or wrapper, do you do the same? So, in the, you mean in the Android toolchain? No, I mean when you compile software, let's say that I have boost installed locally on my system and I have to boost, you've got a lot of CMake, if they are badly done they are going to use the local one, they don't want that, so how do you deal when you have a library installed on your system and already and some, the same library installed with Conan? So if you use in your CMake file, the include that I've shown, it simply takes precedence over the system package. I don't remember exactly the CMake term, but it's the find module and, yeah. Yes, the CMake, if you just use find package or, yeah, for example, find package which would usually find the system library, then if you use find package and include the Conan line, it would find the Conan libraries. Yes. That's about all the time we've got. Yeah.