Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Update build process
Browse files Browse the repository at this point in the history
Also updated the README with build instructions
  • Loading branch information
marcoconti83 committed Aug 5, 2019
1 parent 339e856 commit 9bbfed2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ libs/
obj/
build/
dist/
output/
local.properties
96 changes: 3 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,101 +12,11 @@ JNI bindings for the [cryptobox](https://github.com/wireapp/cryptobox) with supp

## Building

### Host Architecture
There is a Docker file that create an image to cross compile on all necessary platforms. You need to have Docker running on your machine.

Besides common OS-specific development tooling, the following prerequisites
are needed to build for the host architecture:
Run `./docker-build.sh` to start the build. It will download Android SDK and NDK, so it will take a while.

* A Rust compiler (1.16.0 exactly).
* A Java compiler (1.6 or later).

With that in place

make dist

will leave a tarball in the `dist` directory containing all the binaries for
your host architecture in the form of shared libraries, as well as a `.jar`
file and the corresponding `javadoc` output.

### Android

Besides common OS-specific development tooling, the following prerequisites
are needed to build for Android:

* The [Android SDK](http://developer.android.com/sdk/index.html) (The Android Studio IDE is not required).

* The [Android NDK](https://developer.android.com/ndk/downloads/index.html) (`r10d` or newer).

* A Java compiler (1.6 or later).

* A Rust compiler (1.16.0) that can cross-compile to the following
targets corresponding to the NDK toolchains:
* `armv7-linux-androideabi`
* `aarch64-linux-android`
* `i686-linux-android`
* `x86_64-unknown-linux-gnu`

It is recommended to use [rustup](https://github.com/rust-lang-nursery/rustup.rs) to
manage multiple Rust compiler toolchains. Using rustup, the following commands
will install the necessary target-specific Rust binaries needed for Android:

rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add aarch64-linux-android
rustup target add x86_64-unknown-linux-gnu

Alternatively a Rust compiler that supports the necessary targets can be built from source, e.g.:

./configure \
--prefix=/where/to/install \
--arm-linux-androideabi-ndk=/path/to/android-ndk-toolchain-armeabi-v7a \
--aarch64-linux-android-ndk=/path/to/android-ndk-toolchain-arm64-v8a \
--i686-linux-android-ndk=/path/to/android-ndk-toolchain-x86 \
--x86_64-linux-android-ndk=/path/to/android-ndk-toolchain-x86_64 \
--target=arm-linux-androideabi,aarch64-linux-android,i686-linux-android,x86_64-unknown-linux-gnu
make -j4
make install

* The `ANDROID_NDK_HOME` environment variable must be set and point to the
home directory of the NDK installation.

With the prerequisites in place, the Android build can be run with:

cd android && make dist

The distribution artifacts will be in the `android/dist` directory, which includes
an [Android Library Archive](http://tools.android.com/tech-docs/new-build-system/aar-format) (`.aar`).

If [Maven](https://maven.apache.org) is installed (availble on [homebrew](https://formulae.brew.sh/formula/maven)), you can publish the aar to a your local Maven repository with the command:

```
mvn install:install-file \
-Dfile="<path to aar>" \
-DgroupId=com.wire \
-DartifactId=cryptobox-android \
-Dpackaging=aar \
-Dversion=<version number>
```

### Windows

You need:

* [MSYS2](http://msys2.github.io/) with MinGW-w64 toolchains

* The pkg-config from MinGW-w64 toolchain

pacman -S mingw-w64-x86_64-pkg-config

* A Java compiler (1.6 or later)

* A Rust compiler (1.6 or newer) with GNU ABI

* The `JAVA_HOME` environment variable must be set correctly for MSYS2

export JAVA_HOME="/c/Program Files/Java/jdk1.8.0_rev"

* The `PATH` environment variable must include JDK and Rust for MSYS2
Once the script is completed, you will find the result of the compilation copied to the `output/` folder.

## Sample Application

Expand Down
12 changes: 11 additions & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e

if [[ "$1" = "--clean" ]]; then
# clean stopped containers
Expand All @@ -8,5 +9,14 @@ if [[ "$1" = "--clean" ]]; then
docker rmi `docker images --filter "dangling=true" -q`
fi

IMAGE_NAME="wire/cryptobox-jni"

# build
docker build -t wire/cryptobox-jni .
docker build -t ${IMAGE_NAME} .
docker create -ti --name temp_build ${IMAGE_NAME} bash

# archive
rm -fr output || true
mkdir -p output
docker cp temp_build:/home/rust/cryptobox-jni/android/dist output/
echo "DONE: output is in `pwd`/output"

0 comments on commit 9bbfed2

Please sign in to comment.