Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit fcb5d44

Browse files
committed
Update to include ffi-support
Signed-off-by: Michael Lodder <redmike7@gmail.com>
1 parent 6c615cb commit fcb5d44

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

text/language-bindings/README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ callable libraries. This RFC covers how Ursa will enable its code to be
2727
consumable by other languages.
2828

2929
When exporting to other languages there are two types of wrappers that
30-
can be created: thin and idiomatic. Example code written
30+
can be created: thin and idiomatic. Thin wrappers are just language bindings and shall be called
31+
bindings. Example code written
3132
in Rust below will be used to illustrate the difference.
3233

3334
```rust
@@ -43,7 +44,7 @@ impl Ed25519 {
4344
}
4445
```
4546

46-
The purpose of the wrapper is to expose `sign` and `verify`. A thin wrapper
47+
The purpose of the wrapper is to expose `sign` and `verify`. Bindings
4748
will be the simplest method like so:
4849

4950
```c
@@ -56,7 +57,7 @@ int ursa_bls_verify(const unsigned char *const message, const unsigned long long
5657
const unsigned char *const signature, const unsigned long long signature_length);
5758
```
5859
59-
The C code now exposes those two functions so C# can use them as a thin wrapper
60+
The C code now exposes those two functions so C# can use them via the binding
6061
6162
```csharp
6263
using System;
@@ -79,11 +80,11 @@ namespace Hyperledger.Ursa.Api
7980
}
8081
```
8182

82-
Thin wrappers are not desirable by end users because it requires more knowledge
83+
Using bindings are not desirable by end users because it requires more knowledge
8384
about the native library than they perhaps want to know. It also does not allow
84-
language developers to use what they are most familiar with. However, thin wrappers
85+
language developers to use what they are most familiar with. However, bindings
8586
are required because they handle marshaling between the two languages. Idiomatic wrappers
86-
are written to hide the nastiness of the thin wrapper and allow language developers to
87+
are written to hide the nastiness of the bindings and allow language developers to
8788
stick to what they like and are familiar with. Continuing the example above, an idiomatic
8889
wrapper can be written like this
8990

@@ -137,19 +138,26 @@ namespace Bls
137138

138139
The idiomatic wrapper provides more logic and parameters for convenience than the thin wrapper does.
139140
It can also be expanded to include other types but ultimately maps all inputs to
140-
the expected thin wrapper types.
141+
the expected binding types.
141142

142-
Thin wrappers are composed of many functions using the [foreign function interface (FFI)](https://doc.rust-lang.org/nomicon/ffi.html).
143+
Bindings are composed of many functions using the [foreign function interface (FFI)](https://doc.rust-lang.org/nomicon/ffi.html).
143144

144145
# Reference-level explanation
145146
[reference-level-explanation]: #reference-level-explanation
146147

147-
Thin wrappers can be problematic to write by hand and maintain as APIs change.
148-
It is desirable to have thin wrappers generated programmatically.
148+
Bindings can be problematic to write by hand and maintain as APIs change.
149+
It is desirable to have bindings generated programmatically.
149150
Rust supports generating FFI using `bindgen`. `bindgen` can map to other languages like
150-
C and WASM. Thus thin wrappers should be created and maintained as much as possible using features like `bindgen`.
151-
Thin wrappers should be included in the Ursa project itself in a folder called `wrappers`. This will allow them to
152-
stay in-sync with any other changes to the core library.
151+
C and WASM. Thus bindings should be created and maintained as much as possible using features like `bindgen`.
152+
Bindings should be included in the Ursa project itself in a folder called `wrappers`. This will allow them to
153+
stay in-sync with any other changes to the core library. Rust also offers the [ffi-support](https://crates.io/crates/ffi-support) crate. The crate exposes
154+
Rust objects in three ways:
155+
156+
- Serialization methods like proto or flat buffers or JSON.
157+
- HandleMaps that return handle Id's to callers
158+
- Converts between raw Rust native types to C native types.
159+
160+
Bindings should use the best appropriate option for the given language. For example, WASM must use serialization but Python could use any of them.
153161

154162
Idiomatic wrappers usually cannot be generated by hand as they require more in depth language experience
155163
than automatic generators can produce. Therefore, idiomatic wrappers should be written by project contributors
@@ -160,9 +168,9 @@ Here are general guidelines for producing wrappers:
160168

161169
`<language>` should follow the naming convention as described [here](https://support.codebasehq.com/articles/tips-tricks/syntax-highlighting-in-markdown)
162170

163-
- Thin wrappers
171+
- Bindings
164172
- Produced by code
165-
- Output into the `libursa/wrappers/<language>/folder`
173+
- Output into the `libursa/bindings/<language>/folder`
166174
- Idiomatic wrappers
167175
- Written by developers
168176
- Implemented as best deemed by contributors/community
@@ -180,7 +188,7 @@ Here are general guidelines for producing wrappers:
180188
[drawbacks]: #drawbacks
181189

182190
- Some developers may want all ursa code written in the language of their needs to avoid issues presented by FFI.
183-
- Some languages cannot generate thin wrappers yet using `bindgen`.
191+
- Some languages cannot generate bindings yet using `bindgen`.
184192

185193
# Prior art
186194
[prior-art]: #prior-art

0 commit comments

Comments
 (0)