Skip to content

Commit

Permalink
capnproto: add lite_mode option
Browse files Browse the repository at this point in the history
Cap'n Proto's lite mode disables all reflection and I/O features, so
that a lean library for encoding and decoding messages remains. This
especially is required for targeting Android with API level 21,
because libkj-async requires API level 23 or later for sigtimedwait.

It may be necessary to additionally add a tool_requires("capnproto")
when using lite mode, just like when cross-compiling, so that capnpc
is available to the lite build of libcapnp and libkj.
  • Loading branch information
mologie committed Jan 2, 2025
1 parent f19a32f commit 4949ba4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions recipes/capnproto/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class CapnprotoConan(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"lite_mode": [True, False],
"with_openssl": [True, False],
"with_zlib": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"lite_mode": False,
"with_openssl": True,
"with_zlib": True,
}
Expand Down Expand Up @@ -114,7 +116,7 @@ def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTING"] = False
tc.variables["EXTERNAL_CAPNP"] = False
tc.variables["CAPNP_LITE"] = False
tc.variables["CAPNP_LITE"] = self.options.lite_mode
tc.variables["WITH_OPENSSL"] = self.options.with_openssl
tc.generate()
deps = CMakeDeps(self)
Expand All @@ -129,10 +131,12 @@ def generate(self):
yes_no = lambda v: "yes" if v else "no"
tc.configure_args.extend([
f"--with-openssl={yes_no(self.options.with_openssl)}",
"--enable-reflection",
f"--enable-reflection={yes_no(not self.options.lite_mode)}",
])
if Version(self.version) >= "0.8.0":
tc.configure_args.append(f"--with-zlib={yes_no(self.options.with_zlib)}")
if self.options.lite_mode:
tc.configure_args.append("--with-external-capnp")
# Fix rpath on macOS
if self.settings.os == "Macos":
tc.extra_ldflags.append("-Wl,-rpath,@loader_path/../lib")
Expand Down Expand Up @@ -204,15 +208,22 @@ def pthread():
def ws2_32():
return ["ws2_32"] if self.settings.os == "Windows" else []

components = {
components_lite = {
"capnp": {"requires": ["kj"]},
"kj": {"system_libs": libm() + pthread()},
"kj-test": {"requires": ["kj"]},
}

if self.options.lite_mode:
return components_lite

components = {
**components_lite,
"capnp-json": {"requires": ["capnp", "kj"]},
"capnp-rpc": {"requires": ["capnp", "kj", "kj-async"]},
"capnpc": {"requires": ["capnp", "kj"], "system_libs": libm() + pthread()},
"kj": {"system_libs": libm() + pthread()},
"kj-async": {"requires": ["kj"], "system_libs": libm() + pthread() + ws2_32()},
"kj-http": {"requires": ["kj", "kj-async"]},
"kj-test": {"requires": ["kj"]},
}

if self.options.get_safe("with_zlib"):
Expand Down

0 comments on commit 4949ba4

Please sign in to comment.