Search code examples
gitconanimgui

Is it possible to use a github branch in conan package manager?


I would like to use imguis docking branch. The problem I am trying to figure out is using conan package manager is it possible to ask for a specific branch or would I need to write a custom script to target a specific branch from a package? I am able to get the main imgui package but have not found anything on targeting branches.

I am using cmake and conanfile.txt currently.

This is currently my conanfile.txt

[requires]
imgui/1.76

Solution

  • Conan recipes (conanfile.py) can be implemented to fetch any branch, commit, tag, or download a .zip archive. What it is not possible is to make an arbitrary recipe, implemented by others to do a different thing that it does, because it is defeating the whole purpose of versioning and reproducibility.

    When imgui/1.76 is in a conanfile (either .txt or .py), it is fetching the imgui package existing in ConanCenter, details in the imgui package and the full recipe can be found in the conan-center-index github repo, the repo that is used to build all packages in ConanCenter

    In that recipe, the sources() method is implemented as:

    def source(self):
       tools.get(**self.conan_data["sources"][self.version])
       extracted_dir = self.name + "-" + self.version
       os.rename(extracted_dir, self._source_subfolder)
    

    The conan_data attribute is the data from the conandata.yml file

    sources:
      "1.74":
        url: "https://github.com/ocornut/imgui/archive/v1.74.tar.gz"
        sha256: "2f5f2b789edb00260aa71f03189da5f21cf4b5617c4fbba709e9fbcfc76a2f1e"
      "1.75":
        url: "https://github.com/ocornut/imgui/archive/v1.75.tar.gz"
        sha256: "1023227fae4cf9c8032f56afcaea8902e9bfaad6d9094d6e48fb8f3903c7b866"
      "1.76":
        url: "https://github.com/ocornut/imgui/archive/v1.76.tar.gz"
        sha256: "e482dda81330d38c87bd81597cacaa89f05e20ed2c4c4a93a64322e97565f6dc"
      "1.77":
        url: "https://github.com/ocornut/imgui/archive/v1.77.tar.gz"
        sha256: "c0dae830025d4a1a169df97409709f40d9dfa19f8fc96b550052224cbb238fa8"
    

    The sources used for the recipe are the releases corresponding to the version, and when you are using the packages, that cannot be changed.

    What is possible is to copy/fork the recipe, adapt it to the needs, like changing the source() method, or changing the conandata.yml file, to create packages for the specific commits, tags or branches (it would probably be recommended to change the version, to differentiate the package from the official release version). It is also recommended to create packages under username/channel like imgui/version@myteam/stable, to differentiate it from the ConanCenter one. Artifactory CE is completely free too and can be used to host your own packages privately.