Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cariboulabs/swordfish_com_example
https://github.com/cariboulabs/swordfish_com_example
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/cariboulabs/swordfish_com_example
- Owner: cariboulabs
- License: apache-2.0
- Created: 2024-06-02T09:03:51.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-02T09:34:21.000Z (7 months ago)
- Last Synced: 2024-06-02T10:44:47.267Z (7 months ago)
- Language: Rust
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwordFish Comm Example (computer side)
This is an EXAMPLE repo that only contains parts of our internal serial over USB communication protocol.
The main purposes of this repo:
* display the protocol
* showcase how we made our rust code available in python/c/cpp/java with [flapigen](https://github.com/Dushistov/flapigen-rs) and [pyo3](https://github.com/PyO3/pyo3) to support multiple products.## system dependencies
assumes you have rust [installed](https://www.rust-lang.org/tools/install)
```
#for build process
cargo install --force cargo-make#for serialport-rs
sudo apt install libudev-dev pkg-config#for python wrapper
pip install maturin patchelf#for android targets
sudo apt install clang
rustup target add arm-linux-androideabi
rustup target add aarch64-linux-android
```## Setup
### JVM for local java_wrapper (no cross compilaton)
set JAVA_HOME to the jvm directory. easiest to install the jvm through the jdk
```
sudo apt install openjdk-17-jdk
ll /usr/lib/jvm/java-17-openjdk-amd64/ #test that it was installed properlly
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/"
```
_(recommended to export in ~/.bashrc)_### NDK for compiling to android
set ANDROID_NDK_HOME to the ndk directory which you can install [through this link](https://developer.android.com/ndk/downloads)
```
ANDROID_NDK_HOME=""
```
_(recommended to export in ~/.bashrc)_#### linkers
inside `.cargo/config`, change the linkers' path such that:
```
[target.aarch64-linux-android]
linker = "/aarch64-linux-android21-clang++"[target.armv7-linux-androideabi]
linker = "/armv7a-linux-androideabi21-clang++"
```where is usually located in $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
## rust only:
```
cargo build
cargo test
```## cargo make for wrappers
```
cargo make (displays help infomration)
cargo make cpp_wrapper
cargo make java_wrapper
cargo make python_wrapper
cargo make all_wrappers
```# Examples
the cpp and java_desktop examples are hard-coded to run on the default host target, but can easily be configured to run on other desktop targets with simple modifications to paths variables within their respective sources.## java example:
```
cargo make java_wrapper
cd java_example
javac Main.java
java Main
```## cpp example
```
cargo make cpp_wrapper
cd cpp_example
mkdir build
cd build
cmake ..
make
./main
```## python example
```
cargo make python_wrapper
cd python_example
pip install --force-reinstall
python3 main.py
```## to make Java wrapper for android:
```
cargo make java_wrapper --target aarch64-linux-androidor
cargo make java_wrapper --target armv7-linux-androideabi
```note, it is also possible to use cargo-ndk
```
cargo ndk -t aarch64-linux-android -o ./jniLibs build --release
```