Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Debug/Release compatibility for a shared library #15941

Closed
1 task
db4 opened this issue Mar 25, 2024 · 9 comments
Closed
1 task

[question] Debug/Release compatibility for a shared library #15941

db4 opened this issue Mar 25, 2024 · 9 comments
Assignees

Comments

@db4
Copy link
Contributor

db4 commented Mar 25, 2024

What is your question?

For one my recipe I need to make Debug/Release packages compatible. It's a shared library, embedding some static ones. For simplicity, something like this:

class PkgConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    package_type = "shared-library"
    ...

    def requirements(self):
        self.requires("opencv/4.5.3")

    def compatibility(self):
        if self.settings.build_type == "Debug":
            return [{"settings": [("build_type", "Release")]}]

The above doesn't work. opencv as an embedded dependency gets "full_mode" for its package_id, which is different for Debug and Release packages. What can be done to avoid this? I think setting "patch_mode" for all embedded dependencies of the given recipes could help, but how to achieve that? There are a lot of dependencies, including transitive ones, so I don't like to or can't specify package_id modes manually for all of them.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Mar 25, 2024
@memsharded
Copy link
Member

Hi @db4

Thanks for your question.

The above doesn't work.

What fails? I guess it is a "missing binary", but can you please confirm?

What combination do you really want? You want to depend on opencv as a shared library that links statically all its dependencies? Or would you like the dependencies to be shared as well? Do you want to link the dependencies in Debug mode or in Release mode?

@db4
Copy link
Contributor Author

db4 commented Mar 25, 2024

What fails? I guess it is a "missing binary", but can you please confirm?

Yes, "missing binary".

What combination do you really want? You want to depend on opencv as a shared library that links statically all its dependencies? Or would you like the dependencies to be shared as well? Do you want to link the dependencies in Debug mode or in Release mode?

I must not have been clear enough. I'm linking opencv, all its dependencies, and some other libs statically into my own shared library. And I need to make Debug and Release packages of my shared library compatible.

@db4
Copy link
Contributor Author

db4 commented Mar 25, 2024

adding

    def package_id(self):
        self.info.requires.patch_mode()

resolves compatibility issues, but it's too broad. I would prefer to change package_id mode for embedded dependencies only, but how to do that?

@memsharded
Copy link
Member

What would be the desired build type for dependencies? The main problem is that it is not univocally defined, because it depends on the consumer profile.

Also, do you really plan to build a Debug variant of your shared-library or not really, and it will always be only Release?

resolves compatibility issues, but it's too broad. I would prefer to change package_id mode for embedded dependencies only, but how to do that?

I am not sure if I understand this, I thought you actually want to have dependencies always embedded, that is, always static libraries not shared?

@db4
Copy link
Contributor Author

db4 commented Mar 25, 2024

I have an application (conan package) that depends on some shared libraries (also conan packages). Everything can be built as Release or Debug except one shared library, which is Release-only. All this library's dependencies are statically linked (fully embedded), API is build_type agnostic, so there is no problem using it with everything else built as Debug. I just need to assure Conan that it's compatible with both Debug and Release build of the application.

If this is still unclear, please let me know, I will create a standalone test case.

@memsharded
Copy link
Member

All this library's dependencies are statically linked (fully embedded), API is build_type agnostic, so there is no problem using it with everything else built as Debug

I think for this case, the easiest might be to do "settings erasure" Maybe something like this:

def build(self):
    cmake = CMake(self)
    cmake.configure(build_type="Release")  # hardcode this

def package_id(self):
    del self.info.settings.build_type

Have you considered this approach? It will still need the settings.build_type defined, because of dependencies, and it might be necessary for CMakeDeps to find the dependencies.
This will still generate 2 binaries, one when build_type=Debug and the other when build_type=Release, depending on which dependencies are you using, because the "embed" case will produce different binaries.

@db4
Copy link
Contributor Author

db4 commented Mar 25, 2024

Yes, I tried del self.info.settings.build_type but

This will still generate 2 binaries, one when build_type=Debug and the other when build_type=Release, depending on which dependencies are you using, because the "embed" case will produce different binaries.

due to that, Release package still has a different id and cannot be used in Debug build.

    def package_id(self):
        self.info.requires.patch_mode()

helps to get the same package_id, but it's too broad. Can I set package_id_embed_mode = "patch_mode", but for dependencies, not for the package itself? Or maybe iterate dependencies info, get the current mode, and change it accordingly?

@db4
Copy link
Contributor Author

db4 commented Mar 26, 2024

And one more related question. Conan 1.x had recipe_revision_mode that included dependency's RREV but not PREV into package id. Conan 2.x replaces it with full_mode that always includes both RREV and PREV. Why? What if I want to include RREV only (to make Release and Debug package ids the same or compatible)?

@db4
Copy link
Contributor Author

db4 commented Apr 19, 2024

Continued in #16114

@db4 db4 closed this as completed Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants