Search code examples
conan

Conan cannot clone repo


I have my own repository where I keep all 3rd party libraries. Now, I want to add there NATS library as well. To do that I have created a recipe file:

from conans import CMake, tools
from conan import ConanFile
import os

class NatsConan(ConanFile):
    url = "https://github.com/nats-io/nats.c"
    license = "Apache-2.0"
    description = "NATS is a simple, secure and high-performance messaging system."
    name = "nats"
    
    version = "3.6.1"
    
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    short_paths = True
    options = {
        "shared": [True, False],
        "fPIC": [True, False],
        "nats_tls": [True, False],
        "nats_build_streaming": [True, False],
    }
    default_options = {
        "shared": False,
        "fPIC": True,
        "nats_tls": False,
        "nats_build_streaming": False
    }
    
    def source(self):
        self.output.info("downloading source...")
        
        git = tools.Git(folder = "nats")
        git.clone(url = "https://github.com/nats-io/nats.c.git", branch = "v3.6.1", shallow = True)

    def build(self):
        cmake = CMake(self)
        cmake.definitions["NATS_BUILD_STREAMING"] = self.options.nats_build_streaming
        cmake.definitions["NATS_BUILD_WITH_TLS"] = self.options.nats_tls
        cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
        cmake.configure(source_folder = os.path.join(self.source_folder, "nats.c"))
        cmake.build()

    def package(self):
        self.copy("*.h", dst = "include", src="nats.c/src")
        self.copy("*nats.lib", dst = "lib", keep_path = False)
        self.copy("*nats.dll", dst = "bin", keep_path = False)
        self.copy("*nats.so", dst = "lib", keep_path = False)
        self.copy("*nats.dylib", dst = "lib", keep_path = False)
        self.copy("*.a", dst = "lib", keep_path = False)

    def package_info(self):
        self.cpp_info.libs = ["nats"]

Recipe file is located under nats folder (see below folder structure):

-> nats (working directory)
     -> .git 
     -> nats
          -> conanfile.py
     -> ReadMe.md

When I am running conan install nats/conanfile.py from the working directory, it generates some files, like conaninfo.txt, conanbuildinfo.txt etc. After that I am running conan build nats/conanfile.py to clone and then build libraries, but I am getting this error:

Using lockfile: 'D:\...\nats/conan.lock'
Using cached profile from lockfile
conanfile.py (nats/3.6.1): Calling build()
CMake Error: The source directory "D:/.../nats/nats.c" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
ERROR: conanfile.py (nats/3.6.1): Error in build() method, line 43
        cmake.configure(source_folder = os.path.join(self.source_folder, "nats.c"))
        ConanException: Error 1 while executing cd D:\engage\nats && cmake -G "Visual Studio 17 2022" -A "x64" -DCONAN_LINK_RUNTIME="/MD" -DCONAN_IN_LOCAL_CACHE="OFF" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="17" -DCONAN_CXX_FLAGS="/MP16" -DCONAN_C_FLAGS="/MP16" -DBUILD_SHARED_LIBS="False" -DCMAKE_INSTALL_PREFIX="D:\engage\nats\package" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DNATS_BUILD_STREAMING="False" -DNATS_BUILD_WITH_TLS="False" -Wno-dev D:\engage\nats\nats\nats.c

The issue is that git tool just couldn't clone the given path from GitHub. When I am trying to clone it via git bash by just running git clone https://github.com/nats-io/nats.c.git, it works.


Solution

  • Can you specify which version of conan you are using? Also looking at the docs, you need to run conan source first: https://docs.conan.io/2/tutorial/developing_packages/local_package_development_flow.html.