-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Codegen] Generate Swift bindings #3122
Conversation
Okay, I was working on some changes (branch // Special handling: some functions do not follow standard camelCase
// convention.
#[rustfmt::skip]
let pretty_name = if object.name() == "TWStoredKey" {
pretty_name
.replace("Json", "JSON")
.replace("Hd", "HD")
} else if object.name() == "TWPublicKey" {
pretty_name
.replace("Der", "DER")
} else if object.name() == "TWHash" {
pretty_name
.replace("ripemd", "RIPEMD")
.replace("Ripemd", "RIPEMD")
.replace("sha512256", "sha512_256")
.replace("sha3256", "sha3_256")
.replace("sha256sha256", "sha256SHA256")
} else if object.name() == "TWAES" {
pretty_name
.replace("Cbc", "CBC")
.replace("Ctr", "CTR")
} else {
pretty_name
}; I'm keeping this for now. @satoshiotomakan I'm putting your recommendations on the TODO list of my next PR. @Milerius I now added support for hex values in enums. I also noticed the following: public enum HDVersion: UInt32, CaseIterable {
case `none` = 0
case `xpub` = 0x0488b21e
case `xprv` = 0x0488ade4
case `ypub` = 0x049d7cb2
case `yprv` = 0x049d7878
case `zpub` = 0x04b24746
case `zprv` = 0x04b2430c
case `ltub` = 0x019da462
case `ltpv` = 0x019d9cfe
case `mtub` = 0x01b26ef6
case `mtpv` = 0x01b26792
case `dpub` = 0x2fda926
case `dprv` = 0x2fda4e8
case `dgub` = 0x02facafd
case `dgpv` = 0x02fac398
} The values for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I have only non-blocking comments
Thanks for the feedback, @satoshiotomakan. I added some of your recommended changes as part of 5a74076. Also, see issue #3159 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes! Re-approve
EDIT: Please check the latest update: #3122 (comment)
About
This is the follow up to the codegen-v2 parser (#3065) migration which generates Swift bindings from the C headers. I also recommend to read the Design Decision section, respectively my Proposal at the end.
ToDo
TWString
andTWData
types.description
field for string representation where required.I don't fully understand this part yet, investigatingExecution
To generate the verbose C header grammar (to
out/header_grammar.json
):To create the manifest (to
out/manifest/
):To generate Swift bindings (to
out/swift_bindings/
):Design Decision
First, let me introduce the two concepts
C grammar
andManifest
.C grammar
The C grammar parser was introduced in #3065 and converts the C headers in
include/
into a parsable JSON file where all the components and its properties are specified. The C grammar is very verbose and unnecessarily complex, given that the C headers are being (ab-)used with custom markers, typedefs, etc for workflow purposes.An example of the C grammar:
See output
Manifest
To make the C grammar easier to work with, we first convert it into a Manifest, which is a collection of simple structures. From there, each binding generator (Swift, Kotlin, etc) can then use that manifest for its own specific purposes with custom treatment/handlers, etc.
The manifest will play a more important role later on (if approved), as described in the Proposal section.
An example of the manifest structure:
See output
Proposal: Deprecate C header & Parser
As explained in the
C grammar
concept section, the way we generate the C bindings introduces a lot of complexity. In the future - in my opinion - we should deprecate both theinclude/
directory and the C grammar parser entirely and only track and maintain the manifest.The parser has now served its purpose to help generate the manifest and once we believe the manifest structure is a good fit, the parser should be retired. This would result in much less code, less maintenance and less complexity.
Feedback (or pushback) appreciated.