├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── ic_launcher-playstore.png │ │ ├── java │ │ │ └── com │ │ │ │ └── schuetz │ │ │ │ └── rustandroidios │ │ │ │ ├── JniApi.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── schuetz │ │ │ └── rustandroidios │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── schuetz │ │ └── rustandroidios │ │ └── JniTests.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── img ├── ios1.png ├── logos_.png └── android1.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── ios_app ├── ios_app │ ├── Assets.xcassets │ │ ├── Contents.json │ │ └── AppIcon.appiconset │ │ │ ├── 76.png │ │ │ ├── 120.png │ │ │ ├── 152.png │ │ │ ├── 180.png │ │ │ └── Contents.json │ ├── ViewController.swift │ ├── Info.plist │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ └── AppDelegate.swift ├── ios_app.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── xcshareddata │ │ └── xcschemes │ │ │ ├── ios_appTests.xcscheme │ │ │ └── ios_app.xcscheme │ └── project.pbxproj ├── Rust-Bridging-Header.h ├── build-rust-xcode.sh ├── core │ └── mobileapp-ios.h ├── ios_appTests │ ├── Info.plist │ └── ios_appTests.swift └── .gitignore ├── .gitignore ├── .github └── workflows │ ├── rust.yml │ └── android.yml ├── src ├── lib.rs ├── ffi_ios.rs └── ffi_android.rs ├── Cargo.toml ├── gradle.properties ├── gradlew.bat ├── gradlew ├── README.md └── Cargo.lock /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /img/ios1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/img/ios1.png -------------------------------------------------------------------------------- /img/logos_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/img/logos_.png -------------------------------------------------------------------------------- /img/android1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/img/android1.png -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ios_app/ios_app/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/76.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/120.png -------------------------------------------------------------------------------- /ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/152.png -------------------------------------------------------------------------------- /ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivnsch/rust_android_ios/HEAD/ios_app/ios_app/Assets.xcassets/AppIcon.appiconset/180.png -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /ios_app/ios_app.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Rust demo 3 | Returned class: %s 4 | Callback called with: %s 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jan 02 17:55:58 CET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | .gradle 4 | /local.properties 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | target/ 10 | app/src/main/libs/ 11 | app/src/main/java/net/akaame/myapplication/Session.java 12 | app/src/main/java/net/akaame/myapplication/InternalPointerMarker.java 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ios_app/ios_app.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios_app/Rust-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Rust-Bridging-Header.h 3 | // ios_app 4 | // 5 | // Created by Ivan Schuetz on 06.08.19. 6 | // Copyright © 2019 com.schuetz. All rights reserved. 7 | // 8 | 9 | #ifndef Rust_Bridging_Header_h 10 | #define Rust_Bridging_Header_h 11 | 12 | #import "mobileapp-ios.h" 13 | 14 | #endif /* Rust_Bridging_Header_h */ 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Build 20 | run: cargo build --verbose 21 | - name: Run tests 22 | run: cargo test --verbose 23 | 24 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_os = "ios")] 2 | mod ffi_ios; 3 | #[cfg(target_os = "android")] 4 | mod ffi_android; 5 | 6 | // Core functionality goes here (or any other Rust file). 7 | // This demo is only about FFI, so empty. 8 | // Possible structures: 9 | // - For simple calculations or services: functions. 10 | // - For more complex scenarios: e.g. function that bootstraps a dependency graph, 11 | // stored in a static variable. the FFI/JNI functions call the dependency graph's functions. 12 | -------------------------------------------------------------------------------- /ios_app/build-rust-xcode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Ensure that `cargo` is in PATH, using the default location. 4 | . "$HOME/.cargo/env" 5 | 6 | set -x 7 | 8 | # Go to repo's root 9 | cd "${SRCROOT}/../" 10 | 11 | # Build binaries 12 | cargo +ios-arm64-1.46.0 build --target aarch64-apple-ios --release --lib 13 | cargo build --target=x86_64-apple-ios --release 14 | 15 | # Create fat binary 16 | libtool -static -o ./ios_app/core/libcore ./target/aarch64-apple-ios/release/libcore.a ./target/x86_64-apple-ios/release/libcore.a 17 | -------------------------------------------------------------------------------- /app/src/test/java/com/schuetz/rustandroidios/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.schuetz.rustandroidios; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_android_ios" 3 | version = "0.0.1" 4 | authors = ["Ivan Schuetz "] 5 | edition = "2018" 6 | 7 | [lib] 8 | name = "core" 9 | crate-type = ["cdylib", "staticlib"] 10 | 11 | [dependencies] 12 | log = "0.4.6" 13 | log-panics = "2.0" 14 | 15 | [target.'cfg(target_os="android")'.dependencies] 16 | jni = { version = "0.16", default-features = false } 17 | android_logger = "0.8" 18 | 19 | [target.'cfg(target_os = "ios")'.dependencies] 20 | libc = "0.2" 21 | core-foundation = "0.6.2" 22 | 23 | [build-dependencies] 24 | env_logger = "0.6" 25 | -------------------------------------------------------------------------------- /ios_app/core/mobileapp-ios.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | const char *string; 10 | int32_t int_; 11 | } ParamStruct; 12 | 13 | typedef struct { 14 | CFStringRef string; 15 | int32_t int_; 16 | } ReturnStruct; 17 | 18 | int32_t add_values(int32_t value1, int32_t value2); 19 | 20 | CFStringRef greet(const char *who); 21 | 22 | void pass_struct(const ParamStruct *object); 23 | 24 | void register_callback(void (*callback)(CFStringRef)); 25 | 26 | ReturnStruct return_struct(void); 27 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |