Skip to content

Commit

Permalink
Android glue (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch authored Apr 20, 2020
1 parent a8ddfa4 commit 562bd2c
Show file tree
Hide file tree
Showing 48 changed files with 1,922 additions and 13,897 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ jobs:
fail-fast: false
matrix:
rust-channel: ['stable', 'nightly']
rust-target: ['arm-linux-androideabi', 'armv7-linux-androideabi', 'aarch64-linux-android', 'i686-linux-android', 'x86_64-linux-android']
rust-target: [
'armv7-linux-androideabi',
'aarch64-linux-android',
'i686-linux-android',
'x86_64-linux-android',
]

steps:
- uses: actions/checkout@v1

- name: Download NDK
run: |
curl -LO https://dl.google.com/android/repository/android-ndk-r20-linux-x86_64.zip
Expand All @@ -28,13 +33,22 @@ jobs:

- name: Check formating
run: cargo fmt --all -- --check
- name: Check docs
run: cargo test --manifest-path android-ndk/Cargo.toml --doc --target=x86_64-unknown-linux-gnu --features rustdoc

- name: Run tests
run: cargo test --package android-ndk-sys --lib --target=x86_64-unknown-linux-gnu
run: |
cd ndk-sys && cargo test --features test && cd ..
cd ndk && cargo test --features rustdoc --doc && cd ..
cargo test -p ndk-build
cargo test -p cargo-apk
- name: Install cargo-apk
run:
cargo install --path cargo-apk

- name: Check compiling on target ${{ matrix.rust-target }}
run: |
export NDK_HOME="$GITHUB_WORKSPACE/android-ndk-r20"
export CC="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
export AR="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
cargo check --package android-ndk --target=${{ matrix.rust-target }}
cargo check -p ndk --target ${{ matrix.rust-target }}
cargo apk build -p ndk-examples --target ${{ matrix.rust-target }} --examples
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[workspace]

members = [
"android-ndk-sys",
"android-ndk",
"ndk",
"ndk-build",
"ndk-examples",
"ndk-glue",
"ndk-sys",
"cargo-apk",
]
70 changes: 57 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
# `android-ndk`: Rust bindings of the Android NDK
# Rust on Android

[![Build Status](https://travis-ci.org/mb64/android-ndk-rs.svg?branch=master)](https://travis-ci.org/mb64/android-ndk-rs)
[![Crates.io Status](https://meritbadge.herokuapp.com/android-ndk-sys)](https://crates.io/crates/android-ndk-sys)
[![Docs.rs Status](https://docs.rs/android-ndk-sys/badge.svg)](https://docs.rs/android-ndk-sys)
[![Crates.io Status](https://meritbadge.herokuapp.com/android-ndk)](https://crates.io/crates/android-ndk)
[![Docs.rs Status](https://docs.rs/android-ndk/badge.svg)](https://docs.rs/android-ndk)
- Raw FFI bindings to the NDK ![ndk-sys-docs][ndk-sys-badge]
- Safe abstraction of the bindings ![ndk-docs][ndk-badge]
- Startup code ![ndk-glue-docs][ndk-glue-badge]
- Everything for building apk's ![ndk-build-docs][ndk-build-badge]
- Build tool ![cargo-apk-docs][cargo-apk-badge]

This is a work in progress at the moment.
## Hello world
`Cargo.toml`
```toml
[lib]
crate-type = ["lib", "cdylib"]
```

`android-ndk-sys` contains the raw FFI bindings, pre-generated from NDK r20, and `android-ndk`
provides a safe API over it.
`src/lib.rs`
```rust
#[cfg(target_os = "android")]
ndk_glue::ndk_glue!(main);

Other helpful crates for Android:
pub fn main() {
println!("hello world");
}
```

* [`jni`](https://crates.io/crates/jni), JNI bindings for Rust
* [`android_logger`](https://crates.io/crates/android_logger) and [`ndk-logger`](https://crates.io/crates/ndk-logger),
Android backends for the `log` crate
`src/main.rs`
```rust
fn main() {
$crate::main();
}
```

```sh
cargo install cargo-apk
cargo apk run
```

## Logging and stdout
Stdout is redirected to the android log api when using `ndk-glue`. Any logger that logs to
stdout should therefore work.

## JNI
TODO: talk more about jni and add some examples

- [`jni`](https://crates.io/crates/jni), JNI bindings for Rust

## Winit and glutin
TODO shameless plug

## Flutter
TODO shameless plug

[ndk-sys-docs]: https://docs.rs/ndk-sys
[ndk-sys-badge]: https://docs.rs/ndk-sys/badge.svg
[ndk-docs]: https://docs.rs/ndk
[ndk-badge]: https://docs.rs/ndk/badge.svg
[ndk-glue-docs]: https://docs.rs/ndk-glue
[ndk-badge]: https://docs.rs/ndk-glue/badge.svg
[ndk-build-docs]: https://docs.rs/ndk-build
[ndk-build-badge]: https://docs.rs/ndk-build/badge.svg
[cargo-apk-docs]: https://docs.rs/cargo-apk
[cargo-apk-badge]: https://docs.rs/cargo-apk/badge.svg
2 changes: 0 additions & 2 deletions android-ndk-sys/.cargo/config

This file was deleted.

Loading

0 comments on commit 562bd2c

Please sign in to comment.