Features & vcpkg depend-info
Many libraries have optional parts: compression back-ends, TLS support, Python bindings. vcpkg models them as features: named parts of a port, each with extra dependencies. Conan models the same idea with options; vcpkg's features are always additive, which keeps the graph simple: if any port in your graph asks for curl[ssl], you get curl with SSL.
Features of a port
vcpkg search lists a port with its features, and the port's vcpkg.json shows which are on by default:
vcpkg search spdlog 2>&1 | grep -E '^spdlog'
echo "--- ports/spdlog/vcpkg.json"
python3 -c "
import json
m = json.load(open('$VCPKG_ROOT/ports/spdlog/vcpkg.json'))
print('default-features:', m.get('default-features'))
for name, f in m['features'].items():
deps = [d if isinstance(d, str) else d['name'] for d in f.get('dependencies', [])]
print(f' {name}: {f[\"description\"]} -> {deps}')
"spdlog 1.17.0#1 Very fast, header-only/compiled, C++ logging library.
spdlog[benchmark] Use google benchmark
spdlog[fmt] Use fmt library
spdlog[tz-offset] Omit %z timezone offset (use on platforms without tm_gmtoff)
spdlog[wchar] Build with wchar_t (Windows only)
--- ports/spdlog/vcpkg.json
default-features: ['fmt', 'tz-offset']
benchmark: Use google benchmark -> ['benchmark']
fmt: Use fmt library -> ['fmt']
tz-offset: Omit %z timezone offset (use on platforms without tm_gmtoff) -> []
wchar: Build with wchar_t (Windows only) -> []
Every port also has the implicit feature core (the port without optional parts). Selecting features in a manifest:
{
"dependencies": [
"spdlog", // core + default features
{ "name": "spdlog", "features": [ "wchar" ] }, // defaults + wchar
{ "name": "spdlog", "default-features": false }, // core only (if nothing else asks for more)
{ "name": "curl", "default-features": false, "features": [ "openssl", "http2" ] }
]
}(The comments are for this page; JSON manifests can't contain them.) "default-features": false only works if no other port in the graph depends on the defaults, because features are additive across the whole graph.
vcpkg depend-info
depend-info prints the dependency graph vcpkg computed, without installing. In manifest mode it reads your vcpkg.json:
mkdir -p app && cd app
echo '{ "builtin-baseline": "5d4a3dc90c0b3773f3bac81bf41297b54328f471", "dependencies": [ "spdlog", "catch2" ] }' > vcpkg.json
echo "--- list (the default)"
vcpkg depend-info 2>&1
echo "--- tree"
vcpkg depend-info --format=tree 2>&1
echo "--- dot"
vcpkg depend-info spdlog --classic --format=dot 2>&1--- list (the default)
vcpkg-cmake-config:
vcpkg-cmake:
fmt: vcpkg-cmake, vcpkg-cmake-config
catch2: vcpkg-cmake, vcpkg-cmake-config
spdlog[tz-offset, fmt]: fmt, vcpkg-cmake, vcpkg-cmake-config
--- tree
catch2
+-- vcpkg-cmake
+-- vcpkg-cmake-config
spdlog[tz-offset, fmt]
+-- fmt
| +-- vcpkg-cmake
| +-- vcpkg-cmake-config
+-- vcpkg-cmake
+-- vcpkg-cmake-config
--- dot
digraph G{ rankdir=LR; node [fontname=Sans]; edge [minlen=3]; overlap=false;
"vcpkg-cmake";
"vcpkg-cmake-config";
"fmt";
"fmt" -> "vcpkg-cmake";
"fmt" -> "vcpkg-cmake-config";
"spdlog";
"spdlog" -> "fmt";
"spdlog" -> "vcpkg-cmake";
"spdlog" -> "vcpkg-cmake-config";
"2 singletons...";
}
| Option | Effect |
|---|---|
--format=list / tree / dot / mermaid / dgml |
output style (mermaid pastes straight into GitHub Markdown) |
--show-depth |
add the depth of each port (list format) |
--sort=lexicographical / topological / reverse |
list order |
--max-recurse=N |
stop after N levels |
--classic <port> |
ask about a port without a manifest |
The list form shows the features that will be active (spdlog[tz-offset, fmt]) and the topological order: a port appears after everything it depends on, which is also the order vcpkg builds them in. The host-only helpers (vcpkg-cmake, vcpkg-cmake-config) appear because the ports need them to build, though nothing links them.
A runnable model: resolving features
Features add dependencies, and those dependencies can have default features of their own. vcpkg expands this until nothing changes; this model does the same for a made-up curl:
ports = {
"curl": {"default": ["ssl"], "features": {"ssl": ["openssl"], "http2": ["nghttp2"]}, "deps": ["zlib"]},
"openssl": {"default": [], "features": {}, "deps": []},
"nghttp2": {"default": [], "features": {}, "deps": []},
"zlib": {"default": [], "features": {}, "deps": []},
}
def resolve(requests):
wanted = {} # port -> set of features
todo = list(requests)
while todo:
name, feats, defaults = todo.pop()
port = ports[name]
new = {"core"} | set(feats) | (set(port["default"]) if defaults else set())
if new <= wanted.get(name, set()):
continue
wanted[name] = wanted.get(name, set()) | new
for dep in port["deps"]:
todo.append((dep, [], True))
for f in new - {"core"}:
for dep in port["features"][f]:
todo.append((dep, [], True))
return {p: sorted(f) for p, f in sorted(wanted.items())}
print(resolve([("curl", [], True)]))
print(resolve([("curl", ["http2"], False)]))
print(resolve([("curl", ["http2"], False), ("curl", [], True)])) # another port wants the defaults{'curl': ['core', 'ssl'], 'openssl': ['core'], 'zlib': ['core']}
{'curl': ['core', 'http2'], 'nghttp2': ['core'], 'zlib': ['core']}
{'curl': ['core', 'http2', 'ssl'], 'nghttp2': ['core'], 'openssl': ['core'], 'zlib': ['core']}
The third line is the additive rule at work: one request turned defaults off, another left them on, and the union wins.
Test yourself
Two ports in your graph depend on curl: one asks for curl[http2] with default features off, the other for plain curl. What do you get?
- Two curl builds
- curl with core, http2 and the default features: features are additive
- Only core
- An error
Which command prints the dependency graph of your manifest without installing?
- vcpkg list
- vcpkg depend-info
- vcpkg search
- vcpkg x-history
What is the core feature?
- A feature for multi-core builds
- The port without any optional features; always included
- The default feature set
- A host-only feature