Skip to content

Commit 562bd2c

Browse files
authored
Android glue (#13)
1 parent a8ddfa4 commit 562bd2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1922
-13897
lines changed

.github/workflows/rust.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
rust-channel: ['stable', 'nightly']
12-
rust-target: ['arm-linux-androideabi', 'armv7-linux-androideabi', 'aarch64-linux-android', 'i686-linux-android', 'x86_64-linux-android']
12+
rust-target: [
13+
'armv7-linux-androideabi',
14+
'aarch64-linux-android',
15+
'i686-linux-android',
16+
'x86_64-linux-android',
17+
]
1318

1419
steps:
1520
- uses: actions/checkout@v1
16-
21+
1722
- name: Download NDK
1823
run: |
1924
curl -LO https://dl.google.com/android/repository/android-ndk-r20-linux-x86_64.zip
@@ -28,13 +33,22 @@ jobs:
2833

2934
- name: Check formating
3035
run: cargo fmt --all -- --check
31-
- name: Check docs
32-
run: cargo test --manifest-path android-ndk/Cargo.toml --doc --target=x86_64-unknown-linux-gnu --features rustdoc
36+
3337
- name: Run tests
34-
run: cargo test --package android-ndk-sys --lib --target=x86_64-unknown-linux-gnu
38+
run: |
39+
cd ndk-sys && cargo test --features test && cd ..
40+
cd ndk && cargo test --features rustdoc --doc && cd ..
41+
cargo test -p ndk-build
42+
cargo test -p cargo-apk
43+
44+
- name: Install cargo-apk
45+
run:
46+
cargo install --path cargo-apk
47+
3548
- name: Check compiling on target ${{ matrix.rust-target }}
3649
run: |
3750
export NDK_HOME="$GITHUB_WORKSPACE/android-ndk-r20"
3851
export CC="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
3952
export AR="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
40-
cargo check --package android-ndk --target=${{ matrix.rust-target }}
53+
cargo check -p ndk --target ${{ matrix.rust-target }}
54+
cargo apk build -p ndk-examples --target ${{ matrix.rust-target }} --examples

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[workspace]
2-
32
members = [
4-
"android-ndk-sys",
5-
"android-ndk",
3+
"ndk",
4+
"ndk-build",
5+
"ndk-examples",
6+
"ndk-glue",
7+
"ndk-sys",
8+
"cargo-apk",
69
]

README.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,62 @@
1-
# `android-ndk`: Rust bindings of the Android NDK
1+
# Rust on Android
22

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

9-
This is a work in progress at the moment.
9+
## Hello world
10+
`Cargo.toml`
11+
```toml
12+
[lib]
13+
crate-type = ["lib", "cdylib"]
14+
```
1015

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

14-
Other helpful crates for Android:
21+
pub fn main() {
22+
println!("hello world");
23+
}
24+
```
1525

16-
* [`jni`](https://crates.io/crates/jni), JNI bindings for Rust
17-
* [`android_logger`](https://crates.io/crates/android_logger) and [`ndk-logger`](https://crates.io/crates/ndk-logger),
18-
Android backends for the `log` crate
26+
`src/main.rs`
27+
```rust
28+
fn main() {
29+
$crate::main();
30+
}
31+
```
32+
33+
```sh
34+
cargo install cargo-apk
35+
cargo apk run
36+
```
37+
38+
## Logging and stdout
39+
Stdout is redirected to the android log api when using `ndk-glue`. Any logger that logs to
40+
stdout should therefore work.
41+
42+
## JNI
43+
TODO: talk more about jni and add some examples
44+
45+
- [`jni`](https://crates.io/crates/jni), JNI bindings for Rust
46+
47+
## Winit and glutin
48+
TODO shameless plug
49+
50+
## Flutter
51+
TODO shameless plug
52+
53+
[ndk-sys-docs]: https://docs.rs/ndk-sys
54+
[ndk-sys-badge]: https://docs.rs/ndk-sys/badge.svg
55+
[ndk-docs]: https://docs.rs/ndk
56+
[ndk-badge]: https://docs.rs/ndk/badge.svg
57+
[ndk-glue-docs]: https://docs.rs/ndk-glue
58+
[ndk-badge]: https://docs.rs/ndk-glue/badge.svg
59+
[ndk-build-docs]: https://docs.rs/ndk-build
60+
[ndk-build-badge]: https://docs.rs/ndk-build/badge.svg
61+
[cargo-apk-docs]: https://docs.rs/cargo-apk
62+
[cargo-apk-badge]: https://docs.rs/cargo-apk/badge.svg

android-ndk-sys/.cargo/config

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)