conan-clion-plugin icon indicating copy to clipboard operation
conan-clion-plugin copied to clipboard

[feature] Support for Docker Toolchain

Open andreya108 opened this issue 4 years ago • 2 comments
trafficstars

Please add support for the new Docker Toolchain feature introduced in CLion 2021.3. It is currently not possible to use the Conan plugin with it because the Conan setup step must be done inside the Docker container, not on the host.

andreya108 avatar Oct 08 '21 05:10 andreya108

I second this, support for this would be great!

Thomspoon avatar Feb 07 '22 23:02 Thomspoon

As far is i understand, this problem is caused by the Jetbrains Docker Toolchain Plugin and has nothing to do with conan itself.

I tried to get conan and docker working without the conan plugin and failed as well due to the steps the docker toolchain is executing for a build. The cmake files are generated in a different execution step, than the actual build AND new containers are used for every step. This means, the conan dependencies are installed into the first container, which is used for cmake file generation. In the second step, a new container is used to build the cmake project from the project dir, but now the dependencies from the first step are missing, since it is a new container.

To verify this, i attached myself to a persistent container and build the project manually inside the container, which worked as expected. Unfortunately it's really hard to debug this, since there is no way to configure how the docker plugin is dealing with its containers. It's probably worth to have a look into the Jetbrains Issue tracker.

In general the CLion port of the Docker Plugin still looks pretty alpha, since only a few options are actually working, so i guess there is a good chance this will be fixed soon.

EDIT//

I just found a more or less dirty workaround which might not work for every use case. After noodling around a bit, i came to the conclusion that you just need to make your conan cache persistent - and since the cmake binary folder is used by all docker containers used during build, it seems like a good location for it, depending how one is using conan inside the project. Since i configure everything using cmake files it works pretty well for me. Minimal viable example attached:

PROJECT(MVP)

# search cmake files in cmake binary dir, since conan will be installed there
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

# change the conan user home (containing the cache) to cmake binary dir as well, to make it persistent
set(ENV{CONAN_USER_HOME} ${CMAKE_BINARY_DIR})

# use conan cmake wrapper
include(bin/conan.cmake)

conan_add_remote(<your remote options>)

conan_cmake_configure()

# set user
# for this to work the user password must be set to env var CONAN_PASSWORD_<your remote>
execute_process(COMMAND conan user <youruser> -p -r <your remote>)

# install deps
conan_cmake_install(
    PATH_OR_REFERENCE <path to your conanfile.py, relative to cmake binary dir>
    BUILD <your build polilcy>
    REMOTE <your remote>
)

...

cmasdf avatar Apr 08 '22 18:04 cmasdf