Skipped binaries
Conan always computes the complete dependency graph: every recipe of every dependency is resolved,
loaded and evaluated, and every node gets its package_id computed. But computing the graph doesn’t
mean that all the package binaries in that graph are necessary. Very often, a large part of
the dependencies binaries are not needed at all for the current command, and Conan avoids downloading,
building or installing them. These binaries are marked as skipped (Skip).
Skipping binaries is the default behavior, it is a deliberate optimization that can save a lot of download time, disk space and build time, and it is also one of the reasons why the graph package types and requirement traits are so important.
This section explains when and why Conan skips binaries, how to recognize it and how to change this behavior when needed.
Recognizing skipped binaries
Let’s use the following dependency graph as an example:
app/0.1is anapplicationthatrequires("openssl/0.1")openssl/0.1is ashared-librarythatrequires("zlib/0.1")zlib/0.1is astatic-librarythat has atool_requires("tool/0.1")(some build tool)
Installing the app/0.1 application, assuming that all the binaries have already been created:
$ conan install --requires=app/0.1
...
======== Computing necessary packages ========
Requirements
app/0.1#f285...:cba9...#c921... - Cache
openssl/0.1#b66c...:43fa...#0789... - Cache
Build requirements
Skipped host binaries
zlib/0.1
Skipped build binaries
tool/0.1
The “Computing necessary packages” step lists the binaries that are actually going to be used, and
then, in separate Skipped host binaries, Skipped test binaries and Skipped build binaries sections,
the packages whose binaries are not necessary. In this case:
The
zlibstatic library has been linked into theopensslshared library. Usingopenssldoesn’t require thezlibbinary at all, neither to buildappnor to run it.The
tool/0.1was only necessary to buildzlib. Aszlibis not being built from source, there is no need for thetool/0.1binary at all.
Skipped binaries are also visible in other places:
conan graph infoshowsbinary: Skipfor those nodes, and in its json output the"binary"field of the node will be"Skip". The requirement edges in the json output also contain a"skip"field.In recipes, generators and deployers, the dependencies whose binaries are skipped still exist in
self.dependencies, but theirpackage_folderisNone(see the dependencies reference). Theirpackage_info()method is not evaluated either.conan graph build-orderdoesn’t include skipped binaries.
When is a binary necessary?
Conan computes which binaries are necessary starting from the consumer (the conanfile being installed, or
the --requires given in the command line) and from the packages that are going to be built from source,
and following the requirement traits (headers, libs, run, build) that are propagated through the
graph. The rules are:
The direct dependencies of the consumer are always necessary, including its
tool_requiresandtest_requires.A package that is going to be built from source needs the binaries of all its direct dependencies, including its
tool_requiresandtest_requires.A transitive dependency binary is necessary only if some of its “files” are needed by a node that needs it, that is, if the requirement propagated to that node through the graph still has some of the
headers,libs,runorbuildtraits enabled. If all of them have been dropped along the way, the transitive dependency binary is skipped.Any binary that is not necessary according to the above rules is skipped.
The propagation of traits is derived from the package_type of the packages, and it follows the same
“embed” and “non-embed” cases explained in
the effect of dependencies on package_id. For a consumer
that depends on a direct-dep package, which in turn depends on a transitive-dep package:
consumer -> direct-dep -> transitive-dep
Embed mode: if
direct-depembedstransitive-dep(for example, a shared library or an application linking a static library, or a static library compiling a header-only library), thetransitive-departifacts are already contained inside thedirect-depbinary, so thetransitive-depbinary is skipped. This is the same reason whydirect-depneeds a newpackage_idfor every change oftransitive-dep(full_modeby default).Non-embed mode: if
direct-depdoesn’t embedtransitive-dep(for example, any library linking a shared library, or a static library linking another static library), theconsumerwill still need thetransitive-depbinary, to link it or to run it, so it is not skipped.If
direct-depis a header-only library, it doesn’t embed anything, so thetransitive-depbinary is necessary.The
tool_requiresandtest_requiresofdirect-depandtransitive-depare only necessary ifdirect-deportransitive-deprespectively are going to be built from source. Otherwise, they are skipped.
The traits can be modified explicitly in the requires() calls, like transitive_headers=True or
transitive_libs=True, and that will also change which binaries are necessary. See the
requirement traits reference.
Important
The correct definition of package_type (explicitly, or implicitly via the shared option)
is critical for this behavior. If the package types are unknown, Conan cannot know if a dependency
has been embedded or not, and will be conservative, propagating the traits and requiring
more binaries than necessary.
Skipped binaries and build modes
The skipping of binaries happens after Conan has decided which binaries exist and which need to be built, and it has some implications that are worth knowing:
A missing binary that is skipped is not an error. In the example above, if the
zlib/0.1binary doesn’t exist in the cache or in any remote,conan install --requires=app/0.1will still succeed, because that binary is not needed. Only the binaries that are necessary will raise a “missing binary” error.Build missing only builds necessary binaries. If the
zlib/0.1binary is missing, butappandopensslbinaries exist,conan install --requires=app/0.1 --build=missingwill not buildzlibfrom source, it will be skipped. The same applies to--build=missing:[pattern].Forced builds always build. Packages explicitly forced to be built with
--build="pkg/*"(or--build="*") are always built, even if their binaries wouldn’t be necessary otherwise. As they are built, their dependencies binaries become necessary too. In the example above,conan install --requires=app/0.1 --build="openssl/*" --build=missingwill buildopenssl, and as it needszlibto link,zlibwill also be built if its binary is missing, andtool/0.1will no longer be skipped, as it is needed to buildzlib.
$ conan install --requires=app/0.1 --build="openssl/*" --build=missing
...
Requirements
app/0.1#f285...:cba9...#c921... - Cache
openssl/0.1#b66c...:43fa... - Build
zlib/0.1#f6a2...:dcf6... - Build
Build requirements
tool/0.1#6cb7...:dcf6...#e018... - Cache
Note that the recipes of skipped packages are still necessary: they are downloaded (if not in the cache) and
evaluated to compute the dependency graph and the package_id of their consumers. Skipping is
only about the package binaries. Skipped packages are still part of the dependency graph, so they will also be
captured in lockfiles, and listed by conan graph info.
The tools.graph:skip_build and tools.graph:skip_test confs are a different thing: they make Conan not
expand tool_requires and test_requires at all, so not even their recipes are part of the graph.
In most cases they are not necessary, as Conan will already skip those binaries when they are not needed.
See the build_requirements() reference.
Disabling the skipping of binaries
The default behavior should be good for the vast majority of cases, but there are some situations in which all the binaries of the graph are needed, for example:
Deploying all the dependencies binaries with a deployer, including the ones that have been embedded in other binaries.
Collecting information that is only available in the package binaries of the whole graph, like licenses files.
Populating a cache or a server with all the binaries of a dependency graph, or building all of them.
There are a few mechanisms to modify the default behavior:
The
tools.graph:skip_binariesconf,Trueby default. Defining it asFalsewill make all binaries necessary:# Only the "host" context binaries, "tool_requires" binaries can still be skipped $ conan install --requires=app/0.1 -c tools.graph:skip_binaries=False # All binaries, both in the "host" and "build" contexts $ conan install --requires=app/0.1 -c:a tools.graph:skip_binaries=False
Important
The
-cargument only applies to the “host” context. To also avoid skipping the binaries of the “build” context, like thetool_requiresand their dependencies, use-c:a(all contexts) or-c:b, or define it in the[conf]section of the build profile.It can also be defined per-package using conf patterns, to avoid skipping only some specific packages binaries, like
-c "zlib/*:tools.graph:skip_binaries=False".If a package that would have been built only because of
--build=missingdefinestools.graph:skip_binaries=False, it will be built (and its dependencies binaries will be necessary), even if its binary would have been skipped otherwise.The no_skip=True requirement trait, defined in a recipe
requires(), forces the dependency binary to be necessary whenever the consumer binary is necessary. This should only be used in exceptional cases.If a dependency always needs to be available at runtime for all of its consumers, for example a
static-librarypackage that also contains some shared libraries, the package_type_traits attribute can be used in that dependency recipe to define"run": True, so theruntrait is propagated downstream and its binary will not be skipped.