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 and pyo3 to support multiple products.
assumes you have rust installed
#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
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)
set ANDROID_NDK_HOME to the ndk directory which you can install through this link
ANDROID_NDK_HOME="<DIRECTORY_PATH>"
(recommended to export in ~/.bashrc)
inside .cargo/config
, change the linkers' path such that:
[target.aarch64-linux-android]
linker = "<LINKER_BIN_PATH>/aarch64-linux-android21-clang++"
[target.armv7-linux-androideabi]
linker = "<LINKER_BIN_PATH>/armv7a-linux-androideabi21-clang++"
where <LINKER_BIN_PATH> is usually located in $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
cargo build
cargo test
cargo make (displays help infomration)
cargo make cpp_wrapper
cargo make java_wrapper
cargo make python_wrapper
cargo make all_wrappers
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.
cargo make java_wrapper
cd java_example
javac Main.java
java Main
cargo make cpp_wrapper
cd cpp_example
mkdir build
cd build
cmake ..
make
./main
cargo make python_wrapper
cd python_example
pip install <wheel_filename> --force-reinstall
python3 main.py
cargo make java_wrapper --target aarch64-linux-android
or
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