Coder Social home page Coder Social logo

ble-poc's Introduction

Kickstarter for the re-usable shared lib based on rust to be used in android and iOS

  • Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  • Run the command mkdir android ios flutter rust

    • create sub-directories for each codebase
  • Change directory to rust directory and run the following command cargo init --name rustylib --lib

  • Add the following android target distributions for rust compilations being in rust sub-directory rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

  • Add the following iOS target distributions for rust compilation rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios

    • On my machine mac book pro - intel based machine, I got error for adding the targets armv7-apple-ios, armv7s-apple-ios, and i386-apple-ios

Install tools for iOS,

  • run following commands

    xcode-select --install

  • This cargo subcommand will help you create a universal library for use with iOS. cargo install cargo-lipo

  • This tool will let you automatically create the C/C++11 headers of the library. cargo install cbindgen

Install tools for Android

  • Install Android Studio

  • Install additional SDK tools from Android Studio

    Open Preferences -> System Settings -> Android SDK -> SDK Tools -> Select NDK (side by side), CMake, Android SDK Command Line Tools, Android SDK Platform Tools

  • Set ANDROID_HOME, and NDK_HOME echo "ANDROID_HOME=$HOME/Library/Android/sdk" >> ~/.zshrc echo "NDK_HOME=$HOME/Library/Android/sdk/ndk/25.1.8937393" >> ~/.zshrc

  • Install rustup targets rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

  • Install cargo-ndk cargo install cargo-ndk

Compile for android

  • And setup ANDROID_NDK_HOME for cargo ndk to work properly ANDROID_NDK_HOME=/Users/<username>/Library/Android/sdk/ndk/25.1.8937393

  • Create cargo config in ~/.cargo/config with following contents

[target.x86_64-linux-android]
linker = "/Users/<username>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android28-clang"

[target.aarch64-linux-android]
linker = "/Users/<username>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android28-clang"

[target.armv7-linux-androideabi]
linker = "/Users/<username>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi28-clang"

[target.i686-linux-android]
linker = "/Users/<username>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android28-clang"
  • Build for different android targets
make build_android_shared_lib_x86_64
make build_android_shared_lib_armv7
make build_android_shared_lib_aarch64
make build_android_shared_lib_i686

Obsolete Approach

  • Setup toolchains for android
mkdir ~/.NDK

$(ANDROID_HOME)/ndk-bundle/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir ~/.NDK/arm64;
$(ANDROID_HOME)/ndk-bundle/build/tools/make_standalone_toolchain.py --api 26 --arch arm --install-dir ~/.NDK/arm;
$(ANDROID_HOME)/ndk-bundle/build/tools/make_standalone_toolchain.py --api 26 --arch x86 --install-dir ~/.NDK/x86;

echo "INPUT(-lunwind)" > /Users/<username>/.NDK/x86_64/lib64/clang/14.0.6/lib/linux/x86_64/libgcc.a echo "INPUT(-lunwind)" > /Users/<username>/.NDK/arm64/lib64/clang/14.0.6/lib/linux/aarch64/libgcc.a echo "INPUT(-lunwind)" > /Users/<username>/.NDK/arm64/lib64/clang/14.0.6/lib/linux/aarch64/libgcc.a

  • To build android libs for all environments
cargo ndk -t x86_64-linux-android -t aarch64-linux-android -o ./jniLibs build --release

ble-poc's People

Contributors

krishnakumar4a4 avatar tilak-puli avatar ravikp avatar alka1703 avatar mohammed-strive avatar

Forkers

ravikp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.