cmake: support narrowly constrained lite-only runtime builds#27407
cmake: support narrowly constrained lite-only runtime builds#27407dudantas wants to merge 2 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@esrauchg sorry, I'm not familiar with this repository checks. Do you need anything else from me? |
|
Tests seem to be passing (there may have been a spurious failure earlier), @esrauchg will review with comments if additional action is needed. |
Ok, thanks. |
esrauchg
left a comment
There was a problem hiding this comment.
Thanks for iterating on this!
Summary
Implements the narrowly constrained lite-only runtime build discussed in #27231.
This adds one new CMake option:
The default behavior remains unchanged. With defaults, Protobuf still builds and installs both
libprotobuf-liteandlibprotobuf.When
protobuf_BUILD_LIBPROTOBUF=OFF, the build is only accepted in a strict target-side lite-only configuration:protobuf_BUILD_PROTOC_BINARIES=OFFprotobuf_BUILD_LIBPROTOC=OFFprotobuf_BUILD_LIBUPB=OFFprotobuf_BUILD_TESTS=OFFprotobuf_BUILD_CONFORMANCE=OFFprotobuf_BUILD_EXAMPLES=OFFIn that mode, CMake still builds, installs, and exports
protobuf::libprotobuf-lite, but does not build/install/exportprotobuf::libprotobuf,libprotoc,protoc, orlibupb.Motivation
Some downstream/package-manager workflows use host
protocfor code generation while the target package only needs the lite C++ runtime.For example, generated C++ sources may use:
and the target consumer only links:
This PR does not try to support every possible CMake combination. It only adds a strict lite-only target-runtime mode where the full runtime and compiler-side artifacts are explicitly disabled.
Scope
This PR intentionally does not:
protobuf_BUILD_LIBPROTOBUF_LITE;protoc,libprotoc, tests, conformance, examples, orlibupbwhenprotobuf_BUILD_LIBPROTOBUF=OFF.CONFIG mode is the primary validated contract:
Implementation notes
CMakeLists.txtprotobuf_BUILD_LIBPROTOBUF, defaulting toON.libprotobuf-liteincluded wheneverprotobuf_BUILD_PROTOBUF_BINARIES=ON.libprotobuf.cmakeonly whenprotobuf_BUILD_LIBPROTOBUF=ON.FATAL_ERRORmessages.cmake/install.cmakeprotobuf-lite.pconly whenlibprotobuf-liteexists.protobuf.pconly whenlibprotobufexists.upb.pconly whenlibupbexists.Validation
Validated locally on Windows/MSVC.
Default build
Default install contained:
libprotobuflibprotobuf-litelibprotocprotoclibupbprotobuf.pcprotobuf-lite.pcupb.pcLite-only build
Lite-only install contained:
libprotobuf-liteprotobuf-lite.pcLite-only install did not contain:
libprotobuflibprotocprotoclibupbprotobuf.pcCONFIG consumer
A minimal external consumer passed with:
The consumer included:
Invalid configuration checks
All expected invalid combinations failed at configure time with clear
FATAL_ERRORmessages:protobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_PROTOC_BINARIES=ONprotobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_TESTS=ONprotobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_CONFORMANCE=ONprotobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_EXAMPLES=ONprotobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_LIBUPB=ONprotobuf_BUILD_LIBPROTOBUF=OFF + protobuf_BUILD_LIBPROTOC=ONLocal PoC measurements
The earlier local PoC measured the following on Windows/MSVC:
The lite-only configure step was slower in that local run, but the build step dominated the total time and dropped from
508.063sto55.648s.Related
Resolves #27231