Skip to content
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

Merged
merged 442 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
442 commits
Select commit Hold shift + click to select a range
39dca9a
update method hbs template
lamafab Apr 19, 2023
33990a9
track init.hbs
lamafab Apr 20, 2023
39ab604
update part_property.hbs
lamafab Apr 20, 2023
65e4280
complete Swift class template
lamafab Apr 20, 2023
d4e6309
organize unit test structure, write simple test for swift method rend…
lamafab Apr 20, 2023
031cb13
implement convenience function for engine creation
lamafab Apr 20, 2023
3598217
additional test
lamafab Apr 20, 2023
20a1f22
adjust test input/outputs
lamafab Apr 20, 2023
f5a8a01
remove extra newline from template
lamafab Apr 20, 2023
361a640
add comment
lamafab Apr 20, 2023
4635afc
implement from_grammer function and get_type_str for creating native …
lamafab Apr 20, 2023
1214bc0
add get_method_name function for extracting Swift-appropriate name
lamafab Apr 20, 2023
0e63ac6
fix devcontainer
lamafab Apr 21, 2023
996f68b
add copyright notice to each Rust file
lamafab Apr 21, 2023
fdcfb9a
track Cargo lock and ignore target
lamafab Apr 21, 2023
f7f1646
Merge branch 'master' into codegen-v2
lamafab Apr 21, 2023
c8a3bd9
fix conflicts
lamafab Apr 21, 2023
d7c0e61
fix src/tests/mod.rs
lamafab Apr 21, 2023
875beed
init manifest
lamafab Apr 21, 2023
ffc3dcd
impl mapping for ImportInfo
lamafab Apr 21, 2023
589fa3f
impl additional TryFrom's for manifest types
lamafab Apr 21, 2023
525c6fb
add mappings for ObjectInfo
lamafab Apr 21, 2023
f2dd277
cleanup and add comment
lamafab Apr 21, 2023
5afdac1
convert G-type to PropertyInfo
lamafab Apr 21, 2023
626de2b
format tabs
lamafab Apr 21, 2023
dd98784
expand g-type conversion to TypeInfo
lamafab Apr 21, 2023
1aead28
handle additional variants
lamafab Apr 21, 2023
dae3121
get rid of TryFrom impl
lamafab Apr 21, 2023
47c1742
implement g-type conversion for MethodInfo
lamafab Apr 21, 2023
9f6bb73
reorder code
lamafab Apr 21, 2023
14793cb
stard with C header directory lookup
lamafab Apr 21, 2023
3e1112b
remove attempt at C header directory processing
lamafab Apr 21, 2023
ed7444f
separate impl from manifest file
lamafab Apr 22, 2023
9df6ea5
remove unused imports
lamafab Apr 22, 2023
c5a6ba6
rename ObjectInfo to StructInfo, update EnumInfo fields
lamafab Apr 22, 2023
4631e36
expand on process_c_header_dir
lamafab Apr 22, 2023
d6bb875
continue on process_c_header_dir
lamafab Apr 22, 2023
2c1e228
check both structs and enums for methods
lamafab Apr 22, 2023
d0e665c
proceed with function decl
lamafab Apr 22, 2023
ed00aea
remove prefix for method name
lamafab Apr 22, 2023
9d7d69e
remove unused found_* variables
lamafab Apr 22, 2023
6572fe5
track GStruct
lamafab Apr 22, 2023
c5235fc
write process_c_header_dir output to a directory
lamafab Apr 22, 2023
6022fa7
Merge branch 'manifest' into codegen-v2-swift
lamafab Apr 22, 2023
d740eba
use match in convert items
lamafab Apr 22, 2023
253de63
don't remove prefix of functions
lamafab Apr 22, 2023
62ae7b2
create output dir if not exists
lamafab Apr 23, 2023
f5c4dc8
display manifest output in yaml
lamafab Apr 24, 2023
58debb6
handle Init and Deinit methods
lamafab Apr 24, 2023
e5eb836
handle properties, skip none-exported methods
lamafab Apr 24, 2023
6510b65
handle include header
lamafab Apr 24, 2023
b302a9e
handle TWData and TWString explicitly
lamafab Apr 24, 2023
9c55e9c
adjust serde representation
lamafab Apr 24, 2023
4ea7275
add TW_DATA and TW_STRING tags where appropriate
lamafab Apr 24, 2023
ece503d
replicate manifest type variants from grammar
lamafab Apr 24, 2023
71d3d7e
rename MethodInfo to FunctionInfo
lamafab Apr 24, 2023
e8f5e5e
prefix swift structs with Swift*
lamafab Apr 24, 2023
dc210be
adjust Swift types, implement C type mapping
lamafab Apr 24, 2023
5e4b804
complete conversion from manifest to SwiftFunction
lamafab Apr 24, 2023
5271fa4
remove tags field on ParamInfo
lamafab Apr 24, 2023
f0b3eb2
rename TWData to Data and TWString to String
lamafab Apr 24, 2023
1931a17
add process_func function
lamafab Apr 25, 2023
6a96ce1
implement process_struct_methods
lamafab Apr 25, 2023
5dcd15b
generate property templates
lamafab Apr 25, 2023
bc8083b
handle inits
lamafab Apr 25, 2023
038c628
fix partial inclusion of templates
lamafab Apr 25, 2023
ebfbda4
include class directly into file tempalte
lamafab Apr 25, 2023
c92ff01
experiment with templates more
lamafab Apr 25, 2023
8783bdf
add entire template in one file
lamafab Apr 25, 2023
4f2b68d
expand deinit section
lamafab Apr 25, 2023
59cb886
remove parital templates, cleanup lib.rs
lamafab Apr 25, 2023
46aadf0
reorder code in codegen/swift
lamafab Apr 25, 2023
47a4f76
add simple CLI interface
lamafab Apr 25, 2023
662b0b5
add parser-headers command to cli
lamafab Apr 25, 2023
f13d789
remove warnings
lamafab Apr 25, 2023
665b18e
Merge branch 'update-main' into codegen-v2-swift
lamafab Apr 25, 2023
0a67b23
handle both Const and Mutable for TWSting/TWData
lamafab Apr 25, 2023
dcdb431
remove comment
lamafab Apr 25, 2023
86eb943
remove deprecated test
lamafab Apr 26, 2023
c6cd7ae
remove .h suffix on imports
lamafab Apr 26, 2023
41a0d24
support enum rendering
lamafab Apr 26, 2023
b6c92b8
make render_file_info return Result<Option<T>>
lamafab Apr 26, 2023
f282889
cleanup file template a little
lamafab Apr 26, 2023
3e03802
remove TW prefix from type names and filenames
lamafab Apr 26, 2023
b271428
add skip tag
lamafab Apr 26, 2023
5e35a66
generate header grammer to out/
lamafab Apr 26, 2023
19f33d7
remove redundant check
lamafab Apr 26, 2023
015d52b
Merge branch 'master' into codegen-v2-swift
lamafab Apr 27, 2023
a298a0f
add RenderInput and RenderOutput structs, generate multiple files for…
lamafab Apr 27, 2023
6127ba5
rename main manifest parser
lamafab Apr 27, 2023
f7ed71c
render enums separately in enum/ dir, render enum extensions
lamafab Apr 27, 2023
b75f2ab
add comments
lamafab Apr 27, 2023
7395a04
track templates
lamafab Apr 27, 2023
8c5a6c9
avoid rendering empty structs/extensions
lamafab Apr 27, 2023
2ed6f7e
cleanup enum skip mechanism
lamafab Apr 27, 2023
9e4a001
add Proto typedefs to manifest
lamafab Apr 27, 2023
c585398
remove imports from FileInfo
lamafab Apr 27, 2023
cd10b63
generate Protobuf bindings
lamafab Apr 28, 2023
fdf31fa
convert first char of function and property names to lowercase
lamafab Apr 28, 2023
6b8dffb
track proto template
lamafab Apr 28, 2023
f2552a9
rename enum dir to Enum
lamafab Apr 28, 2023
e9b86f5
rename deter_as to defer_as
lamafab Apr 28, 2023
878560c
strip prefix from enum variant
lamafab Apr 28, 2023
edd7aa7
add default counter values for enum variants
lamafab Apr 28, 2023
93836de
setup is_public in enum template rendering
lamafab Apr 28, 2023
41d9e9c
replace variant tuple with EnumVariantInfo
lamafab Apr 28, 2023
3f9872a
add custom handler for TWStellarPassphrase
lamafab Apr 28, 2023
2a99480
add custom handler for TWHRP
lamafab Apr 28, 2023
2a6c9a1
adjust template to enum variant changes
lamafab Apr 28, 2023
6027004
track markers for enum in C grammer parser
lamafab Apr 28, 2023
b333f2d
add value_type field to EnumInfo
lamafab Apr 28, 2023
d3475c4
add inherited parents to enums
lamafab Apr 28, 2023
1c9cb4e
tiny formatting addition to enum template
lamafab Apr 28, 2023
aafb673
add 'Address' parent to struct where appropriate
lamafab Apr 28, 2023
cec8eb4
rename functions
lamafab Apr 28, 2023
f770728
rename parents to superclasses
lamafab Apr 28, 2023
0909230
fix markers in enum tests
lamafab Apr 28, 2023
157e9bc
render deinits
lamafab Apr 28, 2023
f2409e0
fix formatting in extension.hbs
lamafab Apr 28, 2023
5149198
fix enum generation
lamafab May 1, 2023
8f995e7
classes are always final, add is_nullable for inits
lamafab May 1, 2023
591b868
handle equality operator
lamafab May 1, 2023
2c79103
only classes are final, not structs
lamafab May 1, 2023
405d4a2
handle enum explicitly
lamafab May 1, 2023
9e91531
wrap structs and enums as rawValue
lamafab May 1, 2023
5612836
wrap structs and enums differently, correctly handle optional params
lamafab May 1, 2023
2ee18c3
fix wrappers for return value
lamafab May 1, 2023
ec466a2
set this.rawValue for underlying C FFI call if non-static
lamafab May 1, 2023
77775e8
fix how underlying enum extension is called
lamafab May 1, 2023
a406ee9
fix template regarding extra comma
lamafab May 2, 2023
afeb3bb
remove static option from properties
lamafab May 2, 2023
0f3c09e
add SwiftSelfParam
lamafab May 2, 2023
896ecb4
adjust template for extensions
lamafab May 2, 2023
2794645
Merge branch 'self-param' into codegen-v2-swift
lamafab May 2, 2023
e562c1c
add temporary handling of HRP object name
lamafab May 2, 2023
0c852a0
adjust handling of UnsafeRawPointer
lamafab May 2, 2023
d4c64d5
update templates
lamafab May 2, 2023
1f653bf
remove is_static field from PropertyInfo
lamafab May 2, 2023
1973f1c
wrap returnin enum accordingly
lamafab May 2, 2023
d633eba
distinguish between class and struct when initaiting obj
lamafab May 2, 2023
34bbc8e
unwrap enum result
lamafab May 2, 2023
6982673
add and track typed Swift operations in process_object_properties
lamafab May 2, 2023
a2c732f
update SwiftProperty struct based on changes
lamafab May 2, 2023
0fa7893
convert process_object_methods
lamafab May 2, 2023
0259cf8
cleanup and fix errors
lamafab May 2, 2023
5588ae3
adjust template to adjusted structure design
lamafab May 2, 2023
6a3fc93
handle skipping self-reference correctly
lamafab May 2, 2023
35586eb
adjust init to struct changes
lamafab May 2, 2023
5067234
merge Call and CallDefer
lamafab May 2, 2023
8217399
implement CallOptional
lamafab May 2, 2023
6924ffe
deprecate TryFrom<ParamInfo> for SwiftParam
lamafab May 2, 2023
dba4162
implement support for guarded calls
lamafab May 3, 2023
922d3f9
remove unused imports
lamafab May 3, 2023
bf1c28a
handle struct and enum returns correctly
lamafab May 3, 2023
5e55611
handle structs/enums correctly for properties too
lamafab May 3, 2023
705ae38
unwrap enum on return
lamafab May 3, 2023
34fd495
fix C FFI call in equal operator
lamafab May 3, 2023
f617481
set is_public for methods in manifest
lamafab May 3, 2023
2fda565
skip non-exported inits
lamafab May 3, 2023
9909c13
handle optional structs
lamafab May 3, 2023
7cd80bd
guard call for properties
lamafab May 3, 2023
7d0a711
convert enum variant names to camelCase
lamafab May 3, 2023
5bac384
cleanup templates
lamafab May 3, 2023
29eac7f
add special handler for non-conventional TWStoredKey function names
lamafab May 3, 2023
7463fd8
handle single void param in C header grammer
lamafab May 3, 2023
623d880
checkout correctly in grammer
lamafab May 3, 2023
21494ed
add custom handlers for non-conventional variant names
lamafab May 3, 2023
e688e07
add extra ripemd handler
lamafab May 3, 2023
8488f32
add special handler for sha512_256
lamafab May 3, 2023
73277f2
add special handler for Hash functions
lamafab May 3, 2023
9964c77
add special handler for AES
lamafab May 3, 2023
39f233f
Merge branch 'structured-templating' into codegen-v2-swift
lamafab May 4, 2023
71f0114
convert manifest and swift modules into directories
lamafab May 4, 2023
eda447c
split logic over files
lamafab May 4, 2023
b304a83
deprecate tags, just use bool fields
lamafab May 4, 2023
fb2ed73
remove dbg statements
lamafab May 4, 2023
bb18d59
skip specific files entirely
lamafab May 4, 2023
1d2df70
deprecate parser, track manifest directly
lamafab May 4, 2023
0164804
reference variables directly from main
lamafab May 4, 2023
f05d6de
add IoError and YamlError variants to Error type
lamafab May 4, 2023
74ef17a
seperate swift codgen into individual files
lamafab May 4, 2023
92e7a87
clear some TODOs
lamafab May 4, 2023
cb7df47
implement Display for SwiftType
lamafab May 4, 2023
5a4eac6
comment on properties function and add comments
lamafab May 4, 2023
f9da965
add docs to function mapping
lamafab May 4, 2023
bd1b5e1
cleanup
lamafab May 4, 2023
27b6330
unify C FFI call handler
lamafab May 4, 2023
bc3019c
format special name handler
lamafab May 4, 2023
8b3fdb7
note comment on unwrap
lamafab May 4, 2023
61b2fe2
add rustfmt::skip on special handling
lamafab May 4, 2023
76b4ee6
rename handle_* to param_*
lamafab May 4, 2023
a45c922
add a wrapper for return value
lamafab May 4, 2023
a0822a3
descripte swift operation variants
lamafab May 4, 2023
fa39703
add additional comments
lamafab May 4, 2023
fde1db7
update manifest with TWBase*.yaml
lamafab May 4, 2023
6990b9d
add proper error types and handlings
lamafab May 4, 2023
0ab05c9
handle unwraps in main
lamafab May 4, 2023
9a5b68f
small fix
lamafab May 4, 2023
968957a
formatting
lamafab May 4, 2023
663b263
Merge branch 'reorder' into codegen-v2-swift
lamafab May 4, 2023
756621e
add copyright header
lamafab May 4, 2023
28ee7da
trigger CI
lamafab May 4, 2023
bd00bbc
deprecate tags field from TWBase*.yaml
lamafab May 4, 2023
020a1fa
update TWDataVector
lamafab May 4, 2023
41a7d84
expand TWCommonProto
lamafab May 4, 2023
f83a777
replace Swift type () with Void
lamafab May 4, 2023
2b80c68
Merge branch 'patches' into codegen-v2-swift
lamafab May 4, 2023
f0f0b47
track TWLiquidStakingProto.yaml
lamafab May 4, 2023
4645416
add string description to TWCurve
lamafab May 4, 2023
7af1373
fix outdated path in println
lamafab May 4, 2023
0ffe2bf
undo changes to tool and swift
lamafab May 4, 2023
7bfdc24
automatically add year in copyright header in templates
lamafab May 5, 2023
89fc3be
remove deprecated skip_self field in templates
lamafab May 5, 2023
d638eb0
only use one call to current_year
lamafab May 5, 2023
8dd8e2a
separate string generation from swift type conversion
lamafab May 8, 2023
290c118
don't render empty protos, stip Proto suffix correctly
lamafab May 8, 2023
b9bbfd4
reorder structs
lamafab May 8, 2023
05f9cfd
add convenience function pretty_name
lamafab May 8, 2023
847b4fe
move render functions into render module
lamafab May 8, 2023
42b82d3
add comments to Swift types
lamafab May 8, 2023
6d7a37d
rename render types/functions
lamafab May 8, 2023
1fcad07
init tests module, test single_struct, add expected input/output
lamafab May 8, 2023
59b1cf4
test template rendering for with optional types
lamafab May 8, 2023
de3c805
test single class
lamafab May 8, 2023
24b19f7
add tests for private fields
lamafab May 8, 2023
e443a17
fix spacing for private properties
lamafab May 8, 2023
0620539
simplify struct tests
lamafab May 8, 2023
dc3cebb
test private enum
lamafab May 8, 2023
100d958
add convenience method for enum comparision
lamafab May 8, 2023
ce49688
set options.swift in legacy codegen to false
lamafab May 8, 2023
1853960
add build step for swift codegen-v2 generation
lamafab May 8, 2023
a976d21
Merge branch 'swift-tests' into codegen-v2-swift
lamafab May 8, 2023
c98d54a
add test for enum extensions
lamafab May 9, 2023
5ef2b44
add processor for deinits
lamafab May 9, 2023
69d7337
test for non-associated properties
lamafab May 9, 2023
5024bf3
track non-associated properties tests
lamafab May 9, 2023
a9c085c
remove unnecessary to_string calls
lamafab May 9, 2023
60d0134
format
lamafab May 9, 2023
4a21ce1
create function partial for hbs template
lamafab May 9, 2023
60dd368
implement function and init partials
lamafab May 9, 2023
09f8f2e
implement partial property
lamafab May 9, 2023
68a793a
use partials in enum extensions
lamafab May 9, 2023
dceaca0
add partial templates to RenderInput
lamafab May 9, 2023
06ecc17
move templates to swift subfolder
lamafab May 9, 2023
3e23827
typo
lamafab May 9, 2023
f2791c9
Merge branch 'partial' into codegen-v2-swift
lamafab May 9, 2023
cc6098a
convert enum values to strings, use hex values in enums where required
lamafab May 10, 2023
5253977
trigger CI
lamafab May 10, 2023
5a74076
add recommended changes by @satoshiotomakan
lamafab May 10, 2023
d55e881
update codgen-v2/README.md
lamafab May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 232 additions & 0 deletions codegen-v2/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions codegen-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ path = "src/main.rs"
[dependencies]
serde = { version = "1.0.159", features = ["derive"] }
serde_json = "1.0.95"
serde_yaml = "0.9.21"
handlebars = "4.3.6"
heck = "0.4.1"
17 changes: 4 additions & 13 deletions codegen-v2/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
# About

This is a _work-in-progress_ parser meant to deprecate the existing Ruby parser
in `codegen/`. This project will progess over multiple stages (PRs).

- [x] Write a (minimal) parser with full coverage of the C headers in `include/` ([#3065](https://github.com/trustwallet/wallet-core/pull/3065)).
- [ ] Implement a templating engine, write easy to read templates.
- [ ] Start with Swift codegen, replicate existing API (no breakage).
- [ ] Complete codegen for remaining languages.
- [ ] Extend the parser to handle all valid C header syntax.
- [ ] Add explicit error types (right now it's just `Error::Todo`).
- [ ] Seperate parser logic from C header grammer (no refactoring required, just reorganization).
- [ ] Update the entire building system.
in `codegen/`. As of now, we only support Swift binding generation. This project
will progess over multiple stages (PRs).

## Execution

```bash
$ cd codegen-v2
$ cargo run
$ cargo run -- swift
```

This command reads the C headers in `include/` and generates a
`include_manifest.json` file.
The bindings are saved to `bindings/`.
Loading