We we want to create packages from two recipes:
libfoo
: includes a compiled protobuf message. The protobuf compiler (build context) needs to be invoked at build time, and the library with the compiled.pb.cc
file needs to be linked against the protobuf library (host context). This dependency is expressed like:
def requirements(self):
self.requires("protobuf/3.18.1", transitive_headers=True)
def build_requirements(self):
self.tool_requires("protobuf/3.18.1")
consumer
: is an executable that links against protobuf, but does not invoke the protobuf compiler at build time - so it has a simple a requirement. The consumer wishes to use a newer version of Protobuf,3.21.9
, and uses theoverride=True
property.
Creating a package for the consumer
will require a package of libfoo
where protobuf is overridden to 3.21.9
- we can get this passing --build missing
when creating consumer
.
When this variant of libfoo
is built, the protobuf in the host context is overridden to 3.21.9
, but the one in the build context stays in 3.18.1
: the mismatch causes pb.cc
and pb.h
files to be generated by protobuf-compiler 3.18.1
which is incompatible when creating binaries for the host context using Protobuf 3.21.9
- this gives us a compiler error due to the checks performed by protobuf at compile time.
git clone https://github.com/jcar87/conan-tool-require-override.git
cd conan-tool-require-override
docker build -f docker/Dockerfile -t conan/protobuf-override docker
docker run -v$(pwd):/repro --rm -ti luis/protobuf-override /bin/bash
cd /repro
conan create libfoo -pr gcc-armv8 --build=missing # this will create the package for libfoo with protobuf 3.18.1
conan create consumer -pr gcc-armv8 --build=missing # this will eventually attempt to create package for libfoo with protobuf 3.21.9, and fail
This should lead to the following error when running the last command. We can see that the protobuf for the build context is an earlier version, and thus, the protobuf compiler generates files that are not compatible with the overridden version in the host context.
libfoo/1.0: Calling build()
libfoo/1.0: WARN: Protobuf HOST/BUILD versions: 3.21.9/3.18.1
(clipped for brevity)
[ 75%] Building CXX object CMakeFiles/libfoo.dir/addressbook.pb.cc.o
In file included from /root/.conan2/p/t/libfo1189538ff5043/b/build/Release/addressbook.pb.cc:4:
/root/.conan2/p/t/libfo1189538ff5043/b/build/Release/addressbook.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
17 | #error This file was generated by an older version of protoc which is
| ^~~~~
/root/.conan2/p/t/libfo1189538ff5043/b/build/Release/addressbook.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
18 | #error incompatible with your Protocol Buffer headers. Please
| ^~~~~
/root/.conan2/p/t/libfo1189538ff5043/b/build/Release/addressbook.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
19 | #error regenerate this file with a newer version of protoc.
| ^~~~~