-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_annotation_types breaks on non-builtin external types, despite comment in codegen.rs saying otherwise #411
Comments
This potentially relates to #233. You could imagine that the |
I think annotations are only used in the We also want to be able to ignore annotations we don't care about. I shouldn't need to add a What if we made Edit: I forgot how the api to cast works, you'd need to match on the type first. So it's a major breaking change to anyone using |
That would make it significantly less useful, and would break the kind of usage that's shown off in the capnproto-rust/example/fill_random_values/fill.capnp Lines 28 to 32 in ae6eb67
capnproto-rust/example/fill_random_values/shapes.capnp Lines 13 to 14 in ae6eb67
|
You're right, I forgot about generics. I'll see if I can do #233 then. |
Generics are the whole reason that we need
In the meantime, as a stopgap, maybe For example, when it sees that it needs a type from |
Or, to adapt your idea from earlier, it could return |
Relates to capnproto#411 and capnproto#233 This api is quite awkward but I'm intending it as a stopgap until cargo supports non-linking DEP environment variables. But it allows people to use generated code in external crates without us needing to add an annotation to the external `.capnp` file. This is important because without the change to cargo it would be awkward to require users use a modified `json.capnp`.
Relates to capnproto#411 and capnproto#233 This api is quite awkward but I'm intending it as a stopgap until cargo supports non-linking DEP environment variables. But it allows people to use generated code in external crates without us needing to add an annotation to the external `.capnp` file. This is important because without the change to cargo it would be awkward to require users use a modified `json.capnp`.
Closing because #412 has landed and has been released in capnpc-v0.17.2 |
The comment says "Avoid referring to the annotation in the generated code, so that users can import annotation schemas like
c++.capnp
orrust.capnp
without needing to generate code for them, as long as the annotations are not generic." But the generated code does refer to annotation types.This breaks if the annotation has a non-builtin type defined externally.
capnproto-rust/capnpc/src/codegen.rs
Line 1662 in 39a5248
For example
generates the following, which won't compile
The simplest solution I can think of that doesn't require users to do anything but works for all annotations would be for us to codegen the necessary the annotation types in a private module in each file generated. That adds a little duplication to save users from having to include_str! a new file, which I think is probably worthwhile. We can reduce the bloat by passing a flag to codegen_node telling it to skip generating the Reader & Builder.
The text was updated successfully, but these errors were encountered: