-
Notifications
You must be signed in to change notification settings - Fork 234
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
generate UDL from proc macros #2345
Comments
Wouldn't we be better off just creating great docs from the procmacros? |
That could be good for human readability but it is still nice to have UDL as input for other tools. For example, from @arg0d in #2081:
I definitely think a docs generator would be useful, but that seems like an orthogonal problem (and one that depends on UDL). |
For input to other tools, wouldn't a format that's machine readable be better? Otherwise these tools would need to take a dependency on our weedle2 fork and duplicate much of the convoluted logic in our uniffi_udl crate to make sense of it. |
UDL already needs to be machine readable and there are currently parsers for it. Sure, there may be problems with the parsers but those are implementation details and not necessarily a problem with UDL itself. As noted in #2081:
#2081 highlights two issues:
The parser problem can be addressed via a fresh implementation and does not require any breaking changes. The UDL syntax problem is a problem if the expectation is that rust developers are handwriting UDL files, but it seems to me proc macros are preferable to most developers and UDL is being hand-written because it's required by other tools (ie. binding generators). Auto-generating UDL would be embracing what developers seem to prefer (proc macros) while not making any breaking changes to downstream tooling (binding generators). If there are fundamental problems with the UDL syntax itself then those should be noted in #2081 but so far it seems like it's mostly an implementation problem. |
As you will see in that issue, I don't fully agree with the characterizations there.
Well sure, but through that lens you could say everything can simply be solved with a fresh implementation.
I think this is a misunderstanding of how uniffi hangs together. Zero binding generators consume UDL. Some people do write UDL because it can express things procmacros can not.
As above, I don't think removing UDL would break any binding generators. The only thing that consumes UDL is uniffi_udl, and that emits types defined in uniffi_meta, which are then consumed by uniffi_bindgen, and that is what bindings consume. |
Yes and I largely agree with everything you've said. Introducing yet another UDL specification could introduce a lot of problems which is why I'm trying to address the problems outlined in that issue with an outcome that doesn't involve a new specification.
It's important to separate user-facing file formats from implementations. UDL is a file format that is consumed by various tools. Changing the specification of UDL itself is very different from changing how it is parsed.
Nord's c++, C#, and go binding generators all consume UDL. To be fair, I think you could make a pretty reasonable argument that we could have a specific file format to serve as input for binding generators. For example, serializing the data in "What should external binding generators use as input" is an important question, but they currently use UDL so if we want to change that it should be made clear what the benefits of using a new format over UDL would be. So far the obvious benefits seem to be:
|
I believe they consume it indirectly via how I described it above (ie, they depend on
I don't think that's an accurate representation of the architecture here. |
From the README on how to generate bindings: The UDL file is clearly user input to the tool. If there was a new file format supported by |
I'm afraid those docs are slightly misleading - creating bindings directly from the UDL only works in simple single-crate scenarios, but even in those scenarios, the fact the bindings don't directly consume the UDL is relevant to the conversation. Sadly our docs are poor in this regard too. It probably would be possible to have things work from only UDL files in more scenarios, but it's not clear there's actually demand for that - there's certainly none internally. Given creating bindings directly from the UDL only works in simple scenarios, having something spit out UDL might be interesting for some use-cases, but I don't see those use-cases as ever including feeding that UDL back into the binding generators (or more accurately given the above, back into uniffi_bindgen). It is for this reason that I see no advantage in outputting UDL rather than some other more common machine readable format. I fear we are starting to talk past each other and I've communicated everything I thought was a misunderstanding, so I'll leave this alone for now. |
Thanks @mhammond. I believe we're on the same page now. I think the main misunderstanding was that I was talking from user perspective and you are talking about how it is implemented. The external generators do not have any code paths for parsing the UDL (as that is handled by Changes to the UDL seems like it would be a breaking change to binding generators, but that appears to not be the case in most real-world scenarios. This misunderstanding seems like it could be largely resolved via #1241 but I do wonder why parsing |
#2081 and general user feedback seems to indicate:
As such, it would be nice to have a solution that enables the upsides of UDL without the sometimes painful requirement of hand writing it. If there was a way to auto generate UDL from proc macros we could have the best of both worlds. Rust developers can use proc macros and in-line documentation as they are implementing the FFI functions while consumers (humans or otherwise) can still have the easy-to-parse UDL file.
It would also be nice to have an API that can be implemented in builds scripts that tracks when the UDL has changes and warn/error on breaking changes.
The text was updated successfully, but these errors were encountered: