This is a very experimental feature and it will have breaking changes in future releases.
VirtualEnv generator can be used by name in conanfiles:
class Pkg(ConanFile): generators = "VirtualEnv"
And it can also be fully instantiated in the conanfile
from conans import ConanFile from conan.tools.env import VirtualEnv class Pkg(ConanFile): settings = "os", "compiler", "arch", "build_type" requires = "zlib/1.2.11", "bzip2/1.0.8" def generate(self): ms = VirtualEnv(self) ms.generate()
VirtualEnv generator is used, calling
conan install will generate files containing environment variables information:
- conanbuildenv .bat or .sh scripts, that are automatically loaded if existing by the
self.run()recipes methods. conanbuildenv is the build time environment information. It is collected from the direct
build_requiresin “build” context recipes from the
self.buildenv_infodefinition plus the
self.runenv_infoof the transitive dependencies of those
- conanrunenv .bat or .sh scripts, that can be explicitly opted-in in
self.run()recipes methods with
self.run(..., env=["conanrunenv"]). conanrunenv is the runtime environment information, anything that is necessary in the environment to actually run the compiled executables and applications.
- In both cases, whenever the runtime environment information is necessary, it wil also be automatically deduced from the
self.cpp_infodefinition of the package, to define