You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPERS.md
+64-18Lines changed: 64 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
1
# Developers
2
2
3
-
- This uses https://mozilla.github.io/uniffi-rs/ for building the interface
3
+
`iroh-ffi` uses [`uniffi-rs`](https://mozilla.github.io/uniffi-rs/) for building the different language bindings.
4
+
5
+
## General
6
+
7
+
### Translating the iroh API into iroh-ffi bindings
4
8
5
-
## translating the iroh API into iroh ffi bindings
6
9
Use these general guidelines when translating the rust API featured in the rust
7
10
`iroh` library with the API we detail in this crate:
8
11
-`PathBuf` -> `String`
@@ -15,27 +18,78 @@ Use these general guidelines when translating the rust API featured in the rust
15
18
- Anything that can be represented as a string, should have a `to_string` and `from_string` method, eg `NamespaceId`, `DocTicket`
16
19
- Enums that have enum variants which contain data should look at the `SocketAddr` or `LiveEvent` enums for the expected translation.
17
20
18
-
## Testing
21
+
###Testing
19
22
20
23
Please include tests when you add new pieces of the API to the ffi bindings
21
24
25
+
## Languages
26
+
27
+
### Kotlin
28
+
29
+
- See `README.kotlin.md` for setup
30
+
- Run tests using `./test_kotlin.sh`
31
+
22
32
### Python
23
33
24
-
#### Requirements
34
+
#### Development setup
25
35
26
36
- Install [`maturin`](https://www.maturin.rs/installation) for python development and packaging.
37
+
- Create and activate a virtual environment
27
38
- Install `uniffi-bindgen` with `pip`
28
-
-`maturin develop` will build your package
29
-
- maturin expects you to use `virtualenv` to manage your virtual environment
39
+
-`maturin build` will build a wheel in `targets/wheels`
40
+
-`maturin develop` will build the wheel and install into the current virtual env. It expects you to use `virtualenv` to manage your virtual environment.
41
+
42
+
See below for example commands that do all this.
30
43
31
-
#### pytest
44
+
#### Running the example
32
45
33
-
We use [`pytest`](https://docs.pytest.org/en/7.1.x/contents.html) to test the python api.
46
+
This repo includes a very small, but working example for using the python API, at [`python/main.py`](python/main.py).
34
47
35
-
Run the tests by using `python -m pytest` in order to correctly include all of the iroh bindings.
48
+
To run it with the latest version of iroh published on pypi:
36
49
50
+
```sh
51
+
# Install iroh with pip
52
+
pip install iroh
53
+
# Run the example
54
+
python3 python/main.py --help
55
+
```
56
+
57
+
To run with a locally-built wheel:
37
58
38
-
#### Building wheels
59
+
```sh
60
+
# Create and activate a virtual env
61
+
virtualenv .
62
+
source ./bin/activate
63
+
# Install dependencies
64
+
pip install uniffi-bindgen
65
+
# Build wheel
66
+
maturin develop
67
+
# Run the example
68
+
python3 python/main.py --help
69
+
70
+
```
71
+
72
+
#### Testing
73
+
74
+
We use [`pytest`](https://docs.pytest.org/en/7.1.x/contents.html) to test the python API.
75
+
76
+
Execute the following commands to prepare and run all tests:
77
+
```sh
78
+
# Create and activate a virtual env
79
+
virtualenv .
80
+
source ./bin/activate
81
+
# Install dependencies
82
+
pip install uniffi-bindgen pytest pytest-asyncio
83
+
# Build wheel
84
+
maturin develop
85
+
# Run tests
86
+
python -m pytest
87
+
```
88
+
89
+
When developing the python API, create a test file for each rust module that you create, and test all pieces of the API in that module in the python test file. The file should be named `[MODULENAME]_test.py`.
90
+
For example, the `iroh::net` ffi bindings crate should have a corresponding `net_test.py` file.
91
+
92
+
#### Building portable wheels
39
93
40
94
Invoking `maturin build` will build a wheel in `target/wheels`. This
41
95
will likely only work on your specific platform. To build a portable
@@ -58,11 +112,3 @@ Uniffi translates the rust to python in a systematic way. The biggest discrepanc
58
112
- unit enums will have the same names:
59
113
`SocketAddrType::V4` in rust will be `SocketAddrType.V4` in python
60
114
- methods that return `Result` in rust will potentially throw exceptions on error in python
61
-
62
-
#### test file
63
-
Create a test file for each rust module that you create, and test all pieces of the API in that module in the python test file. The file should be named "[MODULENAME]\_test.py". For example, the `iroh::net` ffi bindings crate should have a corresponding "net\_test.py" file.
This is the [Iroh](https://github.com/n0-computer/iroh)python api!
3
+
This is the [Iroh](https://github.com/n0-computer/iroh)Python API!
4
4
5
-
The api was generated using [uniffi-rs](https://github.com/mozilla/uniffi-rs).
5
+
The API was generated using [uniffi-rs](https://github.com/mozilla/uniffi-rs).
6
6
7
7
All iroh classes, methods, functions, and enums contain docstrings.
8
8
9
-
The current best way to understand how the iroh python api can be used is to check out our [tests](https://github.com/n0-computer/iroh-ffi/tree/main/python).
9
+
The current best way to understand how the iroh python API can be used is to check out our
10
+
[example](https://github.com/n0-computer/iroh-ffi/blob/main/python/main.py) or [tests](https://github.com/n0-computer/iroh-ffi/tree/main/python).
10
11
11
12
We currently ship binary wheels on pypi for:
12
13
- amd64 win
13
14
- x86_64 manylinux2014
14
15
- aarch64 manylinux2014
15
16
- arm64 macosx
16
17
- x86_64 macosx
18
+
19
+
Notes on how the wheels are built and tested are in our [FFI development docs](https://github.com/n0-computer/iroh-ffi/blob/main/DEVELOPERS.md#python).
0 commit comments