-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dfcaf8
commit 72b5dd0
Showing
8 changed files
with
35 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,17 @@ | ||
>DISCLAIMER: the code contained in this repo is experimental and still in WIP status. | ||
# react-native-haskell-shelley | ||
# cls-mobile-bridge | ||
|
||
https://www.npmjs.com/package/@emurgo/react-native-haskell-shelley | ||
https://www.npmjs.com/package/@emurgo/csl-mobile-bridge | ||
|
||
## Getting started | ||
|
||
`$ npm install @emurgo/react-native-haskell-shelley --save` | ||
`$ npm install @emurgo/csl-mobile-bridge --save` | ||
|
||
### Mostly automatic installation | ||
|
||
`$ react-native link @emurgo/react-native-haskell-shelley` | ||
`$ react-native link @emurgo/csl-mobile-bridge` | ||
|
||
## Usage | ||
|
||
See examples in [`App.js`](example/App.js). | ||
|
||
## How to add new classes and functions | ||
|
||
The process is basically as follows: we start by writting a rust wrapper of some struct method from our target rust library. Both iOS and Android require specific rust wrappers, so there are separate folders for each (`rust/ios` and `rust/android`). When this project is compiled by the host react native app, all the wrappers are transformed into a native library. In Android, java can directly interact with the rust binaries (the instructions for compiling our rust library are in `build.gradle`), while in iOS there is an additional step in which the rust library is transformed into C, with which can we easily interact with through Objective-C. This intermediate step is contained in `ios/build.sh`, where we basically use `cbindgen` to automatically generate C binaries as well as C headers (which are written in `rust/include/react_native_haskell_shelley.h`). | ||
After writing the corresponding iOS and Android wrappers, we finally just write a simple JS library in `index.js` and define its types in `index.d.ts`. | ||
|
||
### Android | ||
|
||
For every new class: | ||
|
||
- Add a new rust module named `<class_name.rs>` (snake_case) in `rust/src/android/`. Here is where we add rust wrappers of the corresponding rust struct methods from the library we want to bind. You can check other modules to see how this is done in `rust/src/android/`. | ||
- Add a `use` declaration in `rust/src/android/mod.rs` | ||
|
||
|
||
Now you are ready to add functions for your class/rust structure. | ||
|
||
For every new function in the module: | ||
- Add a rust wrapper of the form: `pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_functionNameInCamelCase` | ||
- Declare an equivalent java function to the target rust function in `android/src/main/java/io/emurgo/rnhaskellshelley/Native.java`. The function name must be in camelCase and | ||
corresponds to the last part (in camelCase) of the rust wrapper signature mentioned above. | ||
|
||
- Add the implementation of the java function that will be exposed to react native in `android/src/main/java/io/emurgo/rnhaskellshelley/HaskellShelleyModule.java`. Note that the types and signatures in `HaskellShelleyModule.java` are different from `Native.java`. In the former, we use java types while in the later we use rust types, ie., we match the signatures of the corresponding rust wrappers. | ||
|
||
### iOS | ||
|
||
For every new class: | ||
|
||
- Add a new rust module named `<class_name.rs>` (snake_case) in `rust/src/ios/`. | ||
- Add a `use` declaration in `rust/src/ios/mod.rs` | ||
|
||
As you may have noticed, the two steps above are equivalent to those with Android. The difference is that the rust wrappers are written differently. | ||
|
||
For every new function in the module: | ||
- Add a rust wrapper of the form: `pub unsafe extern "C" fn function_name_in_snake_case` | ||
- Write a iOS-native wrapper in Objective-C in `ios/HaskellShelley.m`. In contrast to Android (java), the iOS native wrappers can't directly interact with rust so we actually use a C library. This C library is automatically generated by `cargo` when the project is built. | ||
|
||
|
||
### Additional steps in Rust | ||
|
||
- Any new struct from `cardano_serialization_lib` that is required either as an input or output in our rust wrappers must implement the `RPtrRepresentable` trait. Add them in [`ptr_impl.rs`](rust/src/ptr_impl.rs). | ||
|
||
### Javascript | ||
|
||
For new classes and methods: | ||
|
||
1. Add the javascript class signature in `index.d.ts` | ||
2. Add the javascript class implementation in `index.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,15 @@ Pod::Spec.new do |s| | |
s.version = package["version"] | ||
s.summary = package["description"] | ||
s.description = <<-DESC | ||
react-native-haskell-shelley | ||
Cardano serialization lib bridge | ||
DESC | ||
s.homepage = "https://github.com/Emurgo/react-native-haskell-shelley" | ||
# brief license entry: | ||
s.homepage = "https://github.com/Emurgo/csl-mobile-bridge" | ||
s.license = "MIT" | ||
# optional - use expanded license entry instead: | ||
# s.license = { :type => "MIT", :file => "LICENSE" } | ||
s.authors = { "emurgo" => "[email protected]" } | ||
s.platforms = { :ios => "11.0" } | ||
s.source = { :git => "https://github.com/Emurgo/react-native-haskell-shelley.git", :tag => "#{s.version}" } | ||
s.platforms = { :ios => "12.4" } | ||
s.source = { :git => "https://github.com/Emurgo/csl-mobile-bridge.git", :tag => "#{s.version}" } | ||
|
||
s.source_files = "ios/**/*.{h,c,m,swift,sh}" | ||
s.requires_arc = true | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters