diff --git a/Cargo.toml b/Cargo.toml index 47444fe..1eadf60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,21 @@ keywords = [ "crypto", "grin", "mimblewimble" ] edition = "2021" build = "src/build/build.rs" +[[bin]] +name = "grim-bin" +path = "src/main.rs" + [lib] name="grim" -crate_type=["cdylib", "rlib"] +crate-type = ["rlib"] + +[profile.release-apk] +inherits = "release" +strip = true +opt-level = "z" +lto = true +codegen-units = 1 +panic = "abort" [dependencies] log = "0.4" diff --git a/README.md b/README.md index a0049f5..142a2d3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ To build and run application go to project directory and run: ``` cargo build --release -./target/release/grim +./target/release/grim-bin ``` ### Android diff --git a/macos/build_release.sh b/macos/build_release.sh index b8a2d39..32e32c8 100755 --- a/macos/build_release.sh +++ b/macos/build_release.sh @@ -1,10 +1,11 @@ #!/bin/bash +set -e case $1 in - x86|arm) + x86|arm|all) ;; *) - echo "Usage: release_macos.sh [platform]\n - platform: 'x86', 'arm'" >&2 + echo "Usage: release_macos.sh [platform]\n - platform: 'x86', 'arm', 'all'" >&2 exit 1 esac @@ -23,23 +24,31 @@ BASEDIR=$(cd $(dirname $0) && pwd) cd ${BASEDIR} cd .. -# Setup platform argument +# Setup platform +rustup target add x86_64-apple-darwin +rustup target add aarch64-apple-darwin + +rm -rf target/x86_64-apple-darwin +rm -rf target/aarch64-apple-darwin + [[ $1 == "x86" ]] && arch+=(x86_64-apple-darwin) [[ $1 == "arm" ]] && arch+=(aarch64-apple-darwin) +[[ $1 == "all" ]] && arch+=(universal2-apple-darwin) # Start release build with zig linker for cross-compilation -cargo install cargo-zigbuild +# zig 0.12 required +cargo install cargo-zigbuild@0.18.4 cargo zigbuild --release --target ${arch} -rm .intentionally-empty-file.o -yes | cp -rf target/${arch}/release/grim macos/Grim.app/Contents/MacOS/grim-bin +rm -rf .intentionally-empty-file.o +yes | cp -rf target/${arch}/release/grim-bin macos/Grim.app/Contents/MacOS -### Sign .app before distribution: -### rcodesign generate-self-signed-certificate -### rcodesign sign --pem-file cert.pem macos/Grim.app +### Sign .app resources: +#rcodesign generate-self-signed-certificate +#rcodesign sign --pem-file cert.pem macos/Grim.app # Create release package FILE_NAME=Grim-0.1.0-macos-$1.zip -rm target/${arch}/release/${FILE_NAME} +rm -rf target/${arch}/release/${FILE_NAME} cd macos zip -r ${FILE_NAME} Grim.app mv ${FILE_NAME} ../target/${arch}/release \ No newline at end of file diff --git a/scripts/android.sh b/scripts/android.sh index 5aa7579..5f1b790 100755 --- a/scripts/android.sh +++ b/scripts/android.sh @@ -24,7 +24,7 @@ cd .. # Setup release argument type=$1 -[[ ${type} == "release" ]] && release_param+=(--release) +[[ ${type} == "release" ]] && release_param="--profile release-apk" # Setup platform argument [[ $2 == "v7" ]] && arch+=(armeabi-v7a) @@ -39,12 +39,29 @@ type=$1 [[ $2 == "v8" ]] && rustup target install aarch64-linux-android # Build native code -mkdir -p android/app/src/main/jniLibs cargo install cargo-ndk + +rm -rf target/aarch64-linux-android +rm -rf target/armv7-linux-androideabi +mkdir -p android/app/src/main/jniLibs + +sed -i -e 's/"rlib"/"rlib","cdylib"/g' Cargo.toml + +# temp fix for https://stackoverflow.com/questions/57193895/error-use-of-undeclared-identifier-pthread-mutex-robust-cargo-build-liblmdb-s +success=0 +export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0" cargo ndk -t ${arch} -o android/app/src/main/jniLibs build ${release_param} +unset CPPFLAGS && unset CFLAGS +cargo ndk -t ${arch} -o android/app/src/main/jniLibs build ${release_param} +if [ $? -eq 0 ] +then + success=1 +fi + +sed -i -e 's/"rlib","cdylib"/"rlib"/g' Cargo.toml # Build Android application and launch at all connected devices -if [ $? -eq 0 ] +if [ $success -eq 1 ] then cd android diff --git a/src/main.rs b/src/main.rs index 457ba0d..c65c6e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,6 @@ #![windows_subsystem = "windows"] -use egui::os::OperatingSystem; - pub fn main() { #[allow(dead_code)] #[cfg(not(target_os = "android"))] @@ -37,6 +35,7 @@ fn real_main() { use std::sync::Arc; use egui::pos2; + use egui::os::OperatingSystem; use eframe::icon_data::from_png_bytes; let platform = Desktop::default();