mirror of
https://github.com/RoboSats/robo-identities.git
synced 2025-07-19 01:03:31 +00:00
Add docker generate builds wasm & android native (#17)
* Generate Builds * Generate Android builds * Last commit
This commit is contained in:
5
.cargo/config.toml
Normal file
5
.cargo/config.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[target.aarch64-linux-android]
|
||||||
|
linker = "/opt/android-sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang"
|
||||||
|
|
||||||
|
[target.armv7-linux-androideabi]
|
||||||
|
linker = "/opt/android-sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang"
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,2 @@
|
|||||||
/target
|
/builds
|
||||||
/Cargo.lock
|
/target
|
1576
Cargo.lock
generated
Normal file
1576
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"robohash",
|
"robohash",
|
||||||
"robonames",
|
"robonames",
|
||||||
@ -11,4 +10,4 @@ members = [
|
|||||||
lto = true # Enable link-time optimization
|
lto = true # Enable link-time optimization
|
||||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
||||||
panic = 'abort' # Abort on panic
|
panic = 'abort' # Abort on panic
|
||||||
strip = true # Strip symbols from binary*
|
strip = true # Strip symbols from binary*
|
||||||
|
78
Dockerfile
Normal file
78
Dockerfile
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
FROM debian:testing-slim AS base
|
||||||
|
|
||||||
|
# install common packages
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y \
|
||||||
|
wget \
|
||||||
|
curl \
|
||||||
|
unzip \
|
||||||
|
build-essential \
|
||||||
|
openjdk-17-jre-headless \
|
||||||
|
--no-install-recommends \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Set an environment variable for convenience.
|
||||||
|
ENV GRADLE_ROOT=${HOME}/opt/gradle
|
||||||
|
|
||||||
|
RUN mkdir -p ${GRADLE_ROOT}
|
||||||
|
RUN wget https://services.gradle.org/distributions/gradle-7.5.1-bin.zip -O gradle-7.5.1-bin.zip \
|
||||||
|
&& sha256sum gradle-7.5.1-bin.zip \
|
||||||
|
&& echo "f6b8596b10cce501591e92f229816aa4046424f3b24d771751b06779d58c8ec4 gradle-7.5.1-bin.zip" | sha256sum -c - \
|
||||||
|
&& unzip gradle-7.5.1-bin.zip -d ${GRADLE_ROOT} \
|
||||||
|
&& rm gradle-7.5.1-bin.zip
|
||||||
|
|
||||||
|
# Add the relevant directories to the $PATH.
|
||||||
|
ENV PATH=${PATH}:${GRADLE_ROOT}/gradle-7.5.1/bin
|
||||||
|
|
||||||
|
# Set the ${ANDROID_HOME} variable, so that the tools can find our installation.
|
||||||
|
# See https://developer.android.com/studio/command-line/variables#envar.
|
||||||
|
ENV ANDROID_HOME=${HOME}/opt/android-sdk
|
||||||
|
|
||||||
|
# Download and extract the command-line tools into ${ANDROID_HOME}.
|
||||||
|
RUN mkdir -p ${ANDROID_HOME}
|
||||||
|
RUN wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip \
|
||||||
|
-O commandlinetools-linux-8512546_latest.zip \
|
||||||
|
&& sha256sum commandlinetools-linux-8512546_latest.zip \
|
||||||
|
&& echo "2ccbda4302db862a28ada25aa7425d99dce9462046003c1714b059b5c47970d8 commandlinetools-linux-8512546_latest.zip" | sha256sum -c - \
|
||||||
|
&& unzip commandlinetools-linux-8512546_latest.zip -d ${ANDROID_HOME}/cmdline-tools \
|
||||||
|
&& rm commandlinetools-linux-8512546_latest.zip
|
||||||
|
|
||||||
|
# Add the relevant directories to the $PATH.
|
||||||
|
ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/cmdline-tools/bin:${ANDROID_HOME}/platform-tools
|
||||||
|
|
||||||
|
RUN yes | sdkmanager --licenses \
|
||||||
|
&& sdkmanager --verbose \
|
||||||
|
"build-tools;30.0.3" \
|
||||||
|
"ndk;25.1.8937393" \
|
||||||
|
"platforms;android-33"
|
||||||
|
ENV NDK_HOME=${ANDROID_HOME}/ndk/25.1.8937393
|
||||||
|
|
||||||
|
# install rust tools
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | \
|
||||||
|
sh -s -- --default-toolchain nightly -y
|
||||||
|
|
||||||
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
|
RUN rustup target add \
|
||||||
|
aarch64-linux-android \
|
||||||
|
armv7-linux-androideabi \
|
||||||
|
&& rustup toolchain install nightly \
|
||||||
|
&& rustup target add --toolchain nightly \
|
||||||
|
aarch64-linux-android \
|
||||||
|
armv7-linux-androideabi
|
||||||
|
|
||||||
|
ENV PATH="${PATH}:${NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
||||||
|
|
||||||
|
# install cargo tools
|
||||||
|
RUN cargo install cargo-ndk
|
||||||
|
|
||||||
|
COPY . /root
|
||||||
|
|
||||||
|
# Robonames
|
||||||
|
FROM base AS robonames
|
||||||
|
WORKDIR /root/robonames
|
||||||
|
|
||||||
|
# Robohash
|
||||||
|
FROM base AS robohash
|
||||||
|
WORKDIR /root/robohash
|
||||||
|
|
10
README.md
10
README.md
@ -2,4 +2,12 @@
|
|||||||
|
|
||||||
Crates to generate robot identities from a hex hash string. Implements the RoboSats nickname generator and the [RoboHash](https://github.com/e1ven/Robohash/) profile images by [e1ven](https://github.com/e1ven) and [kyco](https://github.com/kyco/robohash).
|
Crates to generate robot identities from a hex hash string. Implements the RoboSats nickname generator and the [RoboHash](https://github.com/e1ven/Robohash/) profile images by [e1ven](https://github.com/e1ven) and [kyco](https://github.com/kyco/robohash).
|
||||||
|
|
||||||
The goal is to build a compact WASM capable of generating robot avatars in the web frontend.
|
The goal is to build a compact WASM capable of generating robot avatars in the web frontend.
|
||||||
|
|
||||||
|
### 🛠️ Build libraries
|
||||||
|
|
||||||
|
```
|
||||||
|
docker-compose up
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the build process is done, you will find all libraries under the `./builds` folder.
|
26
docker-compose.yml
Normal file
26
docker-compose.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
version: '3.4'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rust_wasm:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./robo-identities-wasm/Dockerfile
|
||||||
|
volumes:
|
||||||
|
- ./builds/wasm/:/app/robo-identities-wasm/pkg/:rw
|
||||||
|
command: wasm-pack build
|
||||||
|
rust_java_robonames:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Dockerfile
|
||||||
|
target: robonames
|
||||||
|
volumes:
|
||||||
|
- ./builds/java/robonames:/root/target/:rw
|
||||||
|
command: cargo ndk -t armeabi-v7a -t arm64-v8a -o ./target build --release
|
||||||
|
rust_java_robohash:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Dockerfile
|
||||||
|
target: robohash
|
||||||
|
volumes:
|
||||||
|
- ./builds/java/robohash:/root/target/:rw
|
||||||
|
command: cargo ndk -t armeabi-v7a -t arm64-v8a -o ./target build --release
|
22
robo-identities-wasm/Dockerfile
Normal file
22
robo-identities-wasm/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
FROM debian:testing-slim
|
||||||
|
|
||||||
|
# install common packages
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install --no-install-recommends -y \
|
||||||
|
ca-certificates curl file \
|
||||||
|
build-essential \
|
||||||
|
autoconf automake autotools-dev libtool xutils-dev && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# install Rust toolchain
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | \
|
||||||
|
sh -s -- --default-toolchain nightly -y
|
||||||
|
|
||||||
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
|
# install depdendencies
|
||||||
|
RUN cargo install wasm-pack
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
WORKDIR /app/robo-identities-wasm
|
@ -18,6 +18,7 @@ path = "src/main.rs"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
jni = "0.21.1"
|
||||||
ring = "0.16.20"
|
ring = "0.16.20"
|
||||||
anyhow = "1.0.66"
|
anyhow = "1.0.66"
|
||||||
data-encoding = "2.3.2"
|
data-encoding = "2.3.2"
|
||||||
@ -29,10 +30,14 @@ strum = "0.25"
|
|||||||
strum_macros = "0.25"
|
strum_macros = "0.25"
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.37"
|
||||||
imageproc = "0.23.0"
|
imageproc = "0.23.0"
|
||||||
|
prefer-dynamic = "0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.5.1", features = ["html_reports"] }
|
criterion = { version = "0.5.1", features = ["html_reports"] }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "benchmark"
|
name = "benchmark"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["rlib", "dylib"]
|
||||||
|
@ -126,6 +126,55 @@ fn select_hue_rotation(hash_array: &[i64]) -> Option<i32> {
|
|||||||
Some(hue)
|
Some(hue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod android {
|
||||||
|
use jni::objects::{JClass, JString};
|
||||||
|
use jni::sys::jstring;
|
||||||
|
use jni::JNIEnv;
|
||||||
|
|
||||||
|
use crate::RoboHashBuilder;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_com_robosats_RoboIdentities_nativeGenerateRobohash<'local>(
|
||||||
|
mut env: JNIEnv<'local>,
|
||||||
|
|
||||||
|
_class: JClass<'local>,
|
||||||
|
initial_string: JString<'local>,
|
||||||
|
) -> jstring {
|
||||||
|
let initial_string: String = env
|
||||||
|
.get_string(&initial_string)
|
||||||
|
.expect("Couldn't get java string!")
|
||||||
|
.into();
|
||||||
|
|
||||||
|
match initial_string.split_once(';') {
|
||||||
|
Some((hash, size_str)) => {
|
||||||
|
match size_str.parse::<u32>() {
|
||||||
|
Ok(size) => {
|
||||||
|
let robohash = RoboHashBuilder::new(hash)
|
||||||
|
.with_background(&true)
|
||||||
|
.with_size(size as u32, size as u32)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
match robohash {
|
||||||
|
Ok(robo) => match robo.assemble_base64() {
|
||||||
|
Ok(base64_string) => {
|
||||||
|
let output = env
|
||||||
|
.new_string(base64_string)
|
||||||
|
.expect("Couldn't create java string!");
|
||||||
|
output.into_raw()
|
||||||
|
}
|
||||||
|
Err(_text) => todo!(),
|
||||||
|
},
|
||||||
|
Err(_text) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_err) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -6,7 +6,12 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
jni = "0.21.1"
|
||||||
data-encoding = "2.4.0"
|
data-encoding = "2.4.0"
|
||||||
num = "0.4.1"
|
num = "0.4.1"
|
||||||
ring = "0.16.20"
|
ring = "0.16.20"
|
||||||
sha2 = "0.10.1"
|
sha2 = "0.10.1"
|
||||||
|
prefer-dynamic = "0"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["rlib", "dylib"]
|
||||||
|
@ -86,6 +86,37 @@ pub fn generate_short_nickname(hex_str: &str) -> Result<String, Error> {
|
|||||||
Ok(String::from(""))
|
Ok(String::from(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod android {
|
||||||
|
use jni::objects::{JClass, JString};
|
||||||
|
use jni::sys::jstring;
|
||||||
|
use jni::JNIEnv;
|
||||||
|
|
||||||
|
use crate::generate_short_nickname;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_com_robosats_RoboIdentities_nativeGenerateRoboname<'local>(
|
||||||
|
mut env: JNIEnv<'local>,
|
||||||
|
|
||||||
|
_class: JClass<'local>,
|
||||||
|
initial_string: JString<'local>,
|
||||||
|
) -> jstring {
|
||||||
|
let initial_string: String = env
|
||||||
|
.get_string(&initial_string)
|
||||||
|
.expect("Couldn't get java string!")
|
||||||
|
.into();
|
||||||
|
let string: &str = initial_string.as_str();
|
||||||
|
let nickname = generate_short_nickname(string);
|
||||||
|
match nickname {
|
||||||
|
Ok(nick) => {
|
||||||
|
let output = env.new_string(nick).expect("Couldn't create java string!");
|
||||||
|
// Finally, extract the raw pointer to return.
|
||||||
|
output.into_raw()
|
||||||
|
}
|
||||||
|
Err(_) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Reference in New Issue
Block a user