Skip to content

ipc: Fix mpgen capnp tool path for vcpkg/Windows builds#317

Open
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/win-cmake
Open

ipc: Fix mpgen capnp tool path for vcpkg/Windows builds#317
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/win-cmake

Conversation

@ryanofsky

Copy link
Copy Markdown
Collaborator

It seems that in the vcpkg capnproto package, the capnp code generator can't be found in <capnp_PREFIX>/bin/capnp but is in another path that needs to be read from the cmake configuration, so this change adds cmake code to handle that.

Unfortunately the previous code using <capnp_PREFIX>/bin can't be removed because the llbcapnp-dev 1.0.1 package in Ubuntu Noble is buggy and specifies the wrong executable path in its cmake information. (If this problem is fixed, the old capnp_PREFIX code could be dropped.)

This change is needed to get MSVC builds working in bitcoin/bitcoin#32387

Error seen (MSVC native build):
  mpgen error: mp\util.cpp:332: failed: CreateProcessA(...): bitcoin-core#2 The system
  cannot find the file specified.

Problem: mpgen constructs capnp tool paths as capnp_PREFIX + "/bin/capnp"
and capnp_PREFIX + "/bin/capnpc-c++". capnp_PREFIX is derived from the
capnproto include directory parent, so on a vcpkg install it resolves to
something like vcpkg_installed/x64-windows-release. But vcpkg installs
executables under tools/capnproto/, not bin/, so the constructed path
does not exist and CreateProcessA fails with ERROR_FILE_NOT_FOUND.

Fix: in CMakeLists.txt, when cmake has CapnProto::capnp_tool and
CapnProto::capnpc_cpp imported executable targets with valid
IMPORTED_LOCATION paths, pass those paths as CAPNP_EXECUTABLE and
CAPNPC_CXX_EXECUTABLE compile definitions to mpgen. gen.cpp uses them
via #ifdef, falling back to the capnp_PREFIX construction when they are
not defined.

The EXISTS check before setting the define is important: Ubuntu Noble's
libcapnp-dev 1.0.1 has a packaging bug where the cmake config file is
installed under /usr/lib/x86_64-linux-gnu/cmake/ but _IMPORT_PREFIX is
only computed up 3 directory levels to /usr/lib instead of 4 to /usr, so
IMPORTED_LOCATION is set to /usr/lib/bin/capnp which doesn't exist. The
EXISTS check catches this, leaves CAPNP_EXECUTABLE undefined, and gen.cpp
falls back to capnp_PREFIX "/bin/capnp" = /usr/bin/capnp which does exist.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DrahtBot

DrahtBot commented Jul 22, 2026

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants