Creating a Conan-agnostic deploy of dependencies for developer use

With the full_deploy deployer it is possible to create a Conan-agnostic copy of dependencies that can be used by developers without even having Conan installed in their computers.

The common and recommended flow for most cases is using Conan packages directly from the Conan cache:

../../../../_images/packages_from_cache.png

However, in some situations, it might be useful to be able to deploy a copy of the dependencies into a user folder, so the dependencies can be located there instead of in the Conan cache. This is possible using the Conan deployers.

Let’s see it with an example. All the source code is in the examples2.0 Github repository

  1. $ git clone https://github.com/conan-io/examples2.git
  2. $ cd examples2/examples/extensions/deployers/development_deploy

In the folder we can find the following conanfile.txt:

  1. [requires]
  2. zlib/1.2.13
  3. [tool_requires]
  4. cmake/3.25.3
  5. [generators]
  6. CMakeDeps
  7. CMakeToolchain
  8. [layout]
  9. cmake_layout

The folder also contains a standard CMakeLists.txt and a main.cpp source file that can create an executable that links with zlib library.

We can install the Debug and Release dependencies, and deploy a local copy of the packages with:

  1. $ conan install . --deployer=full_deploy --build=missing
  2. $ conan install . --deployer=full_deploy -s build_type=Debug --build=missing

This will create the following folders:

  1. ├──src
  2. ├──build
  3. ├──generators
  4. | └── ZLibConfig.cmake
  5. ├──full_deploy
  6. ├──build
  7. └──cmake
  8. └──3.25.3
  9. └──x86_64
  10. ├──bin
  11. └──host
  12. └──zlib
  13. └──1.2.13
  14. ├──Debug
  15. └──x86_64
  16. ├──include
  17. ├──lib
  18. └──Release
  19. └──x86_64
  20. ├──include
  21. ├──lib

(Note that you could use the --deployer-folder argument to change the base folder output path for the deployer)

This folder is fully self-contained. It contains both the necessary tools (like cmake executable), the headers and compiled libraries of zlib and the necessary files like ZLibConfig.cmake in the build/generators folder, that point to the binaries inside full_deploy with a relative path.

../../../../_images/independent_dependencies_deploy.png

The Conan cache can be removed, and even Conan uninstalled, then the folder could be moved elsewhere in the computer or copied to another computer, assuming it has the same configuration of OS, compiler, etc.

  1. $ cd ..
  2. $ cp -R development_deploy /some/other/place
  3. $ cd /some/other/place

And the files could be used by developers as:

Windows

  1. $ cd build
  2. # Activate the environment to use CMake 3.25
  3. $ generators\conanbuild.bat
  4. $ cmake --version
  5. cmake version 3.25.3
  6. # Configure, should match the settings used at install
  7. $ cmake .. -G \"Visual Studio 17 2022\" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake
  8. $ cmake --build . --config Release
  9. $ Release\compressor.exe
  10. ZLIB VERSION: 1.2.13

The environment scripts in Linux and OSX are not relocatable, because they contain absolute paths and the sh shell does not have any way to provide access to the current script directory for sourced files.

This shouldn’t be a big blocker, as a “search and replace” with sed in the generators folder can fix it:

Linux

  1. $ cd build/Release/generators
  2. # Fix folders in Linux
  3. $ sed -i 's,{old_folder},{new_folder},g' *
  4. # Fix folders in MacOS
  5. $ sed -i '' 's,{old_folder},{new_folder},g' *
  6. $ source conanbuild.sh
  7. $ cd ..
  8. $ cmake --version
  9. cmake version 3.25.3
  10. $ cmake ../.. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
  11. $ cmake --build .
  12. $ ./compressor
  13. ZLIB VERSION: 1.2.13

Note

Best practices

The fact that this flow is possible doesn’t mean that it is recommended for the majority of cases. It has some limitations:

  • It is less efficient, requiring an extra copy of dependencies

  • Only CMakeDeps and CMakeToolchain are relocatable at this moment. For other build system integrations, please create a ticket in Github

  • Linux and OSX shell scripts are not relocatable and require a manual sed

  • The binary variability is limited to Release/Debug. The generated files are exclusively for the current configuration, changing any other setting (os, compiler, architecture) will require a different deploy

In the general case, normal usage of the cache is recommended. This “relocatable development deployment” could be useful for distributing final products that looks like an SDK, to consumers of a project not using Conan.