ConanCenter
Declare a ConanCenter package in crossbind.config.js and import its headers with the conan: prefix. crossbind builds the package from source, links it statically and binds the header like a port's.
What you need
With the default Docker runner, web, Android, Linux and Windows builds need nothing installed: the images carry Conan. iOS and macOS packages build on your Mac with Xcode on any runner, so they need Conan 2.19 or later and CMake on the PATH. The first build of a package needs the network.
Under RUNNER=LOCAL, web builds need Conan 2.19 or later, Emscripten and CMake on the PATH; Android, Linux and Windows packages cannot build there.
Declare the package
packages.conanholds whatconan:imports. The key is the Conan package name; the value is a version, a Conan version range, or{ version, options }with the recipe's options as strings, numbers or booleans.sharedcannot be set: every package links statically.
Import a header
conan:<package>/<header> names a header in the package's include folder, subfolders included: conan:libxml2/libxml/parser.h. Importing a package that packages.conan does not declare fails the build. A package another one requires (zlib under libpng) is built and linked either way; declare it to import it too.
The header binds like any library header. Without a bundler, Node.js resolves conan: imports through the hooks crossbind build -e node writes (Node.js).
Through your own header
Every package's headers are on your native include path, so your own header can use them. That is also how to reach what cannot bind directly, such as templates and header-only libraries:
An exception thrown inside a package, such as libfmt's fmt::format_error, reaches your catch. Your sources compile with the defines a recipe declares for its users, such as libcurl's CURL_STATICLIB on Windows.
React Native and Node.js
The same imports work in a React Native app on Android and iOS. Android packages build for API level 33: in an app with a lower minSdkVersion, a package that calls a newer libc function fails to link. iOS packages build for iOS 15.1, device and simulator; run pod install again after you change packages.conan.
A Node.js addon for macOS, Linux or Windows links the packages for its target, with the system libraries their recipes ask for. Their symbols stay inside the addon, so they never clash with the zlib and OpenSSL that Node.js exports.
What a build does
ConanCenter publishes no binaries for these toolchains, so the first build of a package compiles it from source. Built packages stay in ~/.crossbind/cache/conan/store, shared by every project (~/.crossbind/cache/conan-local/store for iOS, macOS and RUNNER=LOCAL). A target installs again only when packages.conan, the toolchain or conan.lock changes. A debug build links the release archives.
Each install writes Conan's whole log to .crossbind/conan/logs/<target>.log; a failed one also prints its end.
What a recipe can reach
A recipe is Python that runs the package's own build system, so crossbind fences it in as far as the runner allows:
- Each
conan installgets a work directory and a Conan home of its own, deleted when it ends: plugins, hooks, remotes or settings a recipe writes never reach the next install. - In the default Docker runner the container sees the package store and that work directory, not your project, and every path it reports back is checked before anything is copied. A remote runner sends back only the built packages.
- The store is shared and writable, so a recipe built for one project can change what another later takes from it. Delete
~/.crossbind/cache/conan/storeto build every package again. - Under
RUNNER=LOCAL, and for iOS and macOS on any runner, recipes run on your machine with your permissions.
The lockfile
The first install writes conan.lock next to crossbind.config.js. It pins the version and recipe revision of every package: commit it. Later installs follow it; delete it to resolve every version again.
TypeScript
Each conan: import is typed by a declaration in .crossbind/conan/types/, which @crossbind/typescript-config includes; a tsconfig with its own include needs .crossbind/conan/types/**/*.d.ts in it. The types list every function of the header, but only the ones you import are compiled in.
Licenses
crossbind licenses lists every Conan package of the build with its license, source and license texts. It reads what the last build installed, so on a fresh checkout build first (CLI).
Limits
- No WASI: Conan has no WASI target. While
packages.conandeclares a package, name your platforms with-psocrossbind buildskips WASI. - A recipe that does not build for Emscripten, the NDK, iOS, macOS, a Linux sysroot or llvm-mingw fails with Conan's own error; its options can often switch the failing part off.
- Web and React Native builds link a package's own archives only: the system libraries and Apple frameworks its recipe asks for are not added.
- A header binds as far as a port's does: C APIs bind, variadic functions when imported by name, templates do not.
- Packages come from ConanCenter only; another remote, or a login to one, is not supported.