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

Automate Rust to C++ FFI #4220

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Automate Rust to C++ FFI #4220

wants to merge 21 commits into from

Conversation

gupnik
Copy link
Collaborator

@gupnik gupnik commented Jan 17, 2025

Description

This PR intends to automate the rust to cpp conversion. It is broken down into the following tasks

  • Add a macro to auto-generate a yaml file for each class
  • Use the above yaml files to generate the respective C++ class

How to test

Ensuring that the current builds and tests are executed correctly

Types of changes

New feature (non-breaking change which adds functionality)

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

@gupnik
Copy link
Collaborator Author

gupnik commented Jan 17, 2025

Yaml file generated:

class: TWTONAddressConverter
static_functions:
- name: ToBoc
  rust_name: tw_ton_address_converter_to_boc
  args:
  - name: address
    ty: '* const TWString'
  return_type: '* mut TWString'
- name: FromBoc
  rust_name: tw_ton_address_converter_from_boc
  args:
  - name: boc
    ty: '* const TWString'
  return_type: '* mut TWString'
- name: ToUserFriendly
  rust_name: tw_ton_address_converter_to_user_friendly
  args:
  - name: address
    ty: '* const TWString'
  - name: bounceable
    ty: bool
  - name: testnet
    ty: bool
  return_type: '* mut TWString'

@gupnik gupnik marked this pull request as ready for review January 21, 2025 07:28
Copy link

github-actions bot commented Jan 21, 2025

Binary size comparison

➡️ aarch64-apple-ios:

- 12.77 MB
+ 12.78 MB 	 +8 KB

➡️ aarch64-apple-ios-sim:

- 12.77 MB
+ 12.78 MB 	 +8 KB

➡️ aarch64-linux-android:

- 16.56 MB
+ 16.57 MB 	 +12 KB

➡️ armv7-linux-androideabi:

- 14.00 MB
+ 14.01 MB 	 +11 KB

➡️ wasm32-unknown-emscripten:

- 11.72 MB
+ 11.73 MB 	 +8 KB

@gupnik gupnik changed the title [WIP]: Automate Rust to C++ FFI Automate Rust to C++ FFI Jan 21, 2025
Copy link
Collaborator

@satoshiotomakan satoshiotomakan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gupnik, macros part looks good, please consider codegen-v2/cpp module refactoring.
We should try to have code duplicate as minimum as possible

codegen-v2/Cargo.toml Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp_v2/mod.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp_v2/mod.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp_v2/mod.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp_v2/mod.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/mod.rs Outdated Show resolved Hide resolved
rust/tw_macros/src/tw_ffi.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp_v2/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@satoshiotomakan satoshiotomakan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better! Only small improvements please

codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
codegen-v2/src/codegen/cpp/code_gen.rs Outdated Show resolved Hide resolved
docs/registry.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants