diff --git a/include/mp/proxy.capnp b/include/mp/proxy.capnp index 5763b0b3..abd02e43 100644 --- a/include/mp/proxy.capnp +++ b/include/mp/proxy.capnp @@ -7,6 +7,10 @@ using Cxx = import "/capnp/c++.capnp"; $Cxx.namespace("mp"); +annotation include(file): Text; +annotation includeTypes(file): Text; +# Extra include paths to add to generated files. + annotation wrap(interface, struct): Text; # Wrap capnp interface generating ProxyClient / ProxyServer C++ classes that # forward calls to a C++ interface with same methods and parameters. Text diff --git a/src/mp/gen.cpp b/src/mp/gen.cpp index a5c7f60c..4a0c1ccf 100644 --- a/src/mp/gen.cpp +++ b/src/mp/gen.cpp @@ -21,6 +21,8 @@ #define PROXY_TYPES "mp/proxy-types.h" constexpr uint64_t NAMESPACE_ANNOTATION_ID = 0xb9c6f99ebf805f2cull; // From c++.capnp +constexpr uint64_t INCLUDE_ANNOTATION_ID = 0xb899f3c154fdb458ull; // From proxy.capnp +constexpr uint64_t INCLUDE_TYPES_ANNOTATION_ID = 0xbcec15648e8a0cf1ull; // From proxy.capnp constexpr uint64_t WRAP_ANNOTATION_ID = 0xe6f46079b7b1405eull; // From proxy.capnp constexpr uint64_t COUNT_ANNOTATION_ID = 0xd02682b319f69b38ull; // From proxy.capnp constexpr uint64_t EXCEPTION_ANNOTATION_ID = 0x996a183200992f88ull; // From proxy.capnp @@ -191,7 +193,11 @@ void Generate(kj::StringPtr src_prefix, inl << "#ifndef " << guard << "_PROXY_TYPES_H\n"; inl << "#define " << guard << "_PROXY_TYPES_H\n\n"; inl << "#include <" << include_path << ".proxy.h>\n"; - inl << "#include <" << include_base << "-types.h>\n\n"; + for (const auto annotation : file_schema.getProto().getAnnotations()) { + if (annotation.getId() == INCLUDE_TYPES_ANNOTATION_ID) { + inl << "#include <" << annotation.getValue().getText() << ">\n"; + } + } inl << "namespace mp {\n"; std::ofstream h(output_path + ".proxy.h"); @@ -199,7 +205,11 @@ void Generate(kj::StringPtr src_prefix, h << "#ifndef " << guard << "_PROXY_H\n"; h << "#define " << guard << "_PROXY_H\n\n"; h << "#include <" << include_path << ".h>\n"; - h << "#include <" << include_base << ".h>\n"; + for (const auto annotation : file_schema.getProto().getAnnotations()) { + if (annotation.getId() == INCLUDE_ANNOTATION_ID) { + h << "#include <" << annotation.getValue().getText() << ">\n"; + } + } h << "#include <" << PROXY_DECL << ">\n\n"; h << "#if defined(__GNUC__) && !defined(__clang__)\n"; h << "#pragma GCC diagnostic push\n"; diff --git a/test/src/mp/test/foo.capnp b/test/src/mp/test/foo.capnp index 333c4e4a..5839c05a 100644 --- a/test/src/mp/test/foo.capnp +++ b/test/src/mp/test/foo.capnp @@ -8,6 +8,8 @@ using Cxx = import "/capnp/c++.capnp"; $Cxx.namespace("mp::test::messages"); using Proxy = import "/mp/proxy.capnp"; +$Proxy.include("mp/test/foo.h"); +$Proxy.includeTypes("mp/test/foo-types.h"); interface FooInterface $Proxy.wrap("mp::test::FooImplementation") { add @0 (a :Int32, b :Int32) -> (result :Int32);