Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Motivation

Hyperledger Iroha 2 supports several client SDK libraries, such as Java SDK, Javascript SDK or Python SDK. The way this works currently is by exporting language agnostic schema file that describes all structures exchanged between server (written in Rust) and the client (written in the language of choice - Java, Javascript, Python). SDK developers then build their respective libraries with some automated process of code generation out of the schema. Often times changes in the schema are such that they require manual intervention in the transcription process but if nothing else it is required by every SDK to build and maintain the code for code generation out of schema. To solve this problems for all SDKs in once place it has been decided to generate a shared object that exposes extern functions SDK client libraries can link against dynamically


Abstract


We have internally developed a library for generating extern functions out of existing Rust source code named iroha_ffi (the library will be renamed and released as a separate crate). While this is a powerful library in itself, the cbindgen library for generating C/C++ header files out of Rust source code is missing one crucial feature for these two to interoperate, namely the ability to resolve associated types. To tackle this, first part of this internship will be to add the support for resolving associated types into cbindgen. Since cbindgen's parser is a simple one it is believed that we can use it directly as is to parse MIR (which resolves all associated types) instead of Rust source code with minimal modifications. If this is not sufficient (which will surface once we start using cbindgen), the task will be to integrate with the cbindgen's parser so that it parses Rust source code first and then uses MIR to fill out associated types. Second part of the internship will be to use iroha_ffi library to generate extern functions out of existing functions in the iroha_client library or write them manually if the case so requires (preferably not). Third, and the final, part of the internship will revolve around generating C header files from the extern functions exported from iroha_client library. At this step we will determine if we're missing any crucial features to enable this interop and reevaluate our progress. Hopefully, by the end of the internship we will have the object files and C header files ready to be linked against by the SDK. If the time allows we would like to create a small demo application based on the Java SDK demonstrating that we can successfully link and call functions from the generated object file


Repositories

1. cbindgen(git@github.com:mozilla/cbindgen.git),
2. iroha2(git@github.com:hyperledger/iroha.git) branch: iroha2-stable
3. iroha2-java(git@github.com:hyperledger/iroha-java.git)

Milestones

Eval 1:

  •  Add the functionality to parse function signatures with associated types out of MIR to cbindgen (either by itself or in addition to Rust source code)
  •  Write tests that will cover the functionality of parsing associated types in cbindgen
  •  Open a PR to merge this code into cbindgen, progress with further tasks as we wait for this to be approved

Eval 2:

  •  Use cbindgen to generate C .h header files out of extern functions in the Rust source code
  •  Conduct manual testing
  •  Address the code bugs

Eval 3:

  •  Document the mentorship results
  •  Create a small app demonstrating that you have successfully linked the shared object with the C header files
  •  Present your results


Timeline

Dates

Tasks/Plan

Status

June 1 - June 24

revisit knowledge of Rust
run iroha nodes and connect to it via both `iroha_client_cli` and client app
run cbindgen on a small example: - export a function from Rust - generate C bindings with cbindgen - link this C lib from C and Java

done
June 25 - Aug 23

fork the cbindgen repository
add the functionality to parse function signatures from MIR

done
Aug 24 - Sept 6

make use of ffi_export macro to generate FFI bindings of methods and functions in iroha_client
MIR approach failed - explore other approaches

done
Sept 7 - Oct 18
implement resolution of associated types by parsing source code of all dependent crates.
create a solution to resolve mutually dependent associated types (topologically sort)
done
Oct 19 - Nov24
generate FFI bindings (.h files) for Iroha client using cbindgen
Nov 25 - Dec 1
write tests and open PR to cbindgen and prepare an article reportdone


Mentors

Name

Time zone

Discord ID

Telegram ID

Email ID

Marin VeršićUTC+2mversic@mingler101marin.versic101@gmail.com

Mentees

Name

Time zone

Discord ID

Telegram ID

Email ID

OrangeUTC+8orangeng@orangengngquanhao@gmail.com

Merged PRs

  • PR to cbindgen