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] The usage of runenv #17757

Closed
1 task done
aiyolo opened this issue Feb 12, 2025 · 6 comments
Closed
1 task done

[question] The usage of runenv #17757

aiyolo opened this issue Feb 12, 2025 · 6 comments
Assignees

Comments

@aiyolo
Copy link

aiyolo commented Feb 12, 2025

What is your question?

This link https://github.com/conan-io/conan-center-index/blob/master/recipes/spdlog/all/conanfile.py shows the recipe of spdlog.

I found that although there's no runenv relative setting in package_info() method, but when I built my app with shared spdlog dependency, after I activated the runenv script , the spdlog bin folder can still be added to PATH. Why?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Feb 12, 2025
@memsharded
Copy link
Member

The bindirs of the packages is always automatically added to the runenv scripts in form of PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH environment variables.

@aiyolo
Copy link
Author

aiyolo commented Feb 13, 2025

Thanks for you reply! This page https://docs.conan.io/2/reference/conanfile/methods/package_info.html says that bindirs will automatically added to the runenv scripts, and the default bindirs is ['bin']. It seems that when I package my prebuilt binaries, there is no need to explicitly set the self.cpp_info.bindirs property.

Question:
My following recipe won't auto add runenv to PATH, if I comment self.runenv_info.append_path("PATH", os.path.join(self.package_folder, "bin")), It seems that self.cpp_info.bindirs not works here?

import os
from conan import ConanFile
from conan.tools.files import copy


class helloRecipe(ConanFile):
    name = "opencv_enhanced"
    version = "0.2"
    settings = "build_type"

    def layout(self):
        self.folders.build = "opencv_enhanced" 
        self.folders.source = self.folders.build
        self.cpp.source.includedirs = ["include"]
        self.cpp.build.libdirs = ["x64/vc16/lib"]
        self.cpp.build.bindirs = ["x64/vc16/bin"]

    def package(self):
        local_include_folder = os.path.join(self.source_folder, self.cpp.source.includedirs[0])
        local_lib_folder = os.path.join(self.build_folder, self.cpp.build.libdirs[0])
        local_bin_folder = os.path.join(self.build_folder, self.cpp.build.bindirs[0])
        copy(self, "*.h", local_include_folder, os.path.join(self.package_folder, "include"), keep_path=True)
        copy(self, "*.hpp", local_include_folder, os.path.join(self.package_folder, "include"), keep_path=True)
        if self.settings.build_type == "Debug":
            copy(self, "*d.lib", local_lib_folder, os.path.join(self.package_folder, "lib"), keep_path=True)
            copy(self, "*d.dll", local_bin_folder, os.path.join(self.package_folder, "bin"), keep_path=True)
        else:
            copy(self, "*[!d].lib", local_lib_folder, os.path.join(self.package_folder, "lib"), keep_path=True)
            copy(self, "*[!d].dll", local_bin_folder, os.path.join(self.package_folder, "bin"), keep_path=True)

    def package_info(self):
        # self.buildenv_info.append_path("PATH", os.path.join(self.package_folder, "bin"))
        # self.runenv_info.append_path("PATH", os.path.join(self.package_folder, "bin"))
        # print("My Package folder: " + self.package_folder)

        if self.settings.build_type == "Debug":
            self.cpp_info.libs = ["opencv_world3414d"]
        else:
            self.cpp_info.libs = ["opencv_world3414"]

@aiyolo
Copy link
Author

aiyolo commented Feb 13, 2025

It seems that both dep.runenv_info and require.run are false for my requirements.

        for require, dep in list(host_req.items()) + list(test_req.items()):
            if dep.runenv_info:
                self._runenv.compose_env(dep.runenv_info)
            if require.run:  # Only if the require is run (shared or application to be run)
                _os = self._conanfile.settings.get_safe("os")
                self._runenv.compose_env(runenv_from_cpp_info(dep, _os))

@aiyolo
Copy link
Author

aiyolo commented Feb 13, 2025

I figured it out.

I have to explicitly set run=True when I use my created "opencv_enhanced" package. For spdlog, if I set options={"shared"=True}, it will automatically set run=True. But for my created "opencv_enhanced" package, there is no such option can be set in recipe.

   def requirements(self):
        self.requires("opencv_enhanced/0.2", run=True)

@memsharded
Copy link
Member

The package_type is very important, and it is not being defined in the name = "opencv_enhanced". If your opencv is a shared lib by default, you need to define package_type = "shared-library". This kind of knowledge is already in the ConanCenter recipe.
If you define it, it will not be necessary to define the run=True.

Likewise, other side feedback: settings = "build_type" is most likely incorrect for many case. At least os and arch should be there.

@aiyolo
Copy link
Author

aiyolo commented Feb 15, 2025

The package_type is very important, and it is not being defined in the name = "opencv_enhanced". If your opencv is a shared lib by default, you need to define package_type = "shared-library". This kind of knowledge is already in the ConanCenter recipe.
If you define it, it will not be necessary to define the run=True.

Likewise, other side feedback: settings = "build_type" is most likely incorrect for many case. At least os and arch should be there.

I understand now. thank you.

@aiyolo aiyolo closed this as completed Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants