Skip to content

Commit cb76e70

Browse files
committed
Update documentation
1 parent 10cafad commit cb76e70

2 files changed

Lines changed: 66 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
This version of `cargo-ndk` is much closer to a thin passthrough to `cargo` than previous versions. Please take note of the breaking changes.
66

7-
It also introduces a new command, `cargo ndk-test`. This will push your tests to a device via adb and run them on-device. It currently has
7+
It introduces a new command, `cargo ndk-test`. This will push your tests to a device via adb and run them on-device. It currently has
88
a limitation that doctests can still only be run on the host.
99

10-
**New MSRV: 1.86**
10+
It also introduces a `cargo ndk-runner` subcommand (which is used by `ndk-test` under the hood) and can be specified as a `runner` in Cargo's `config.toml` to enable `cargo run` to work with Android binaries.
11+
12+
> [!IMPORTANT]
13+
> New MSRV: **1.86**. This means that **to build `cargo-ndk`** you need at least 1.86. You can still build projects targetting older versions of Rust with this release of `cargo-ndk`.
1114
1215
- **Breaking change**: Replaced gumdrop CLI parsing with clap. This is functionally equivalent but may cause some minor behavioral differences in edge cases
1316
- **Breaking change**: No longer strips build output by default, and `--no-strip` option is removed
@@ -16,6 +19,7 @@ a limitation that doctests can still only be run on the host.
1619
- **Breaking change**: `--bindgen` has been removed, and relevant environment variables are set by default
1720
- Feature: Clang builtins can now be linked automatically by adding `--link-builtins` or its equivalent environment variable
1821
- Feature: `cargo ndk-test` for running tests on Android devices.
22+
- Feature: `cargo ndk-runner` for running binaries on Android devices.
1923
- Enhancement: Can now be built for an Android host (i.e. Termux) if built with `CARGO_NDK_ON_ANDROID` environment variable set
2024
- Enhancement: CLI flags can now be used in any order (e.g., `cargo ndk -t x86 build` and `cargo ndk build --target x86` are equivalent).
2125
- Enhancement: Added environment variable support for configuration flags with `CARGO_NDK_` prefix (e.g., `CARGO_NDK_TARGET`, `CARGO_NDK_PLATFORM`, `CARGO_NDK_OUTPUT_DIR`)

README.md

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@
44
<img alt="Minimum supported Rust version: 1.86" src="https://img.shields.io/badge/MSRV-1.86-informational">
55
[<img alt="Crates.io Version" src="https://img.shields.io/crates/v/cargo-ndk">](https://lib.rs/crates/cargo-ndk)
66

7-
This cargo extension handles all the environment configuration needed for successfully building libraries
8-
for Android from a Rust codebase, with support for generating the correct `jniLibs` directory structure.
7+
This cargo extension handles all the environment configuration needed for successfully building libraries or binaries for Android from a Rust codebase, with support for generating the correct `jniLibs` directory structure.
8+
9+
`cargo-ndk` provides three subcommands to cargo:
10+
11+
- `cargo ndk` — a passthrough for `cargo` applying all the relevant environment variables to ensure a successful build against the NDK
12+
- `cargo ndk-test` — run tests via `adb` automagically
13+
- `cargo ndk-env` — generate sh exports, PowerShell env vars or JSON (i.e. for Visual Studio Code) to make `rust-analyzer` happy, or other unspeakable crimes I hope you keep to yourself
14+
15+
## Table of Contents
16+
17+
- [Installing](#installing)
18+
- [Examples](#examples)
19+
- [Building a library for 32-bit and 64-bit ARM systems](#building-a-library-for-32-bit-and-64-bit-arm-systems)
20+
- [Linking against and copying `libc++_shared.so`](#linking-against-and-copying-libc_sharedso-into-the-relevant-places-in-the-output-directory)
21+
- [Usage](#usage)
22+
- [Using `cargo run` binaries via adb](#using-cargo-run-binaries-via-adb)
23+
- [Running your tests on an Android device](#running-your-tests-on-an-android-device)
24+
- [Controlling verbosity](#controlling-verbosity)
25+
- [Environment variable configuration](#environment-variable-configuration)
26+
- [Providing environment variables for C dependencies](#providing-environment-variables-for-c-dependencies)
27+
- [`cargo-ndk`-specific environment variables](#cargo-ndk-specific-environment-variables)
28+
- [Printing the environment](#printing-the-environment)
29+
- [Troubleshooting](#troubleshooting)
30+
- [Supported hosts](#supported-hosts)
31+
- [Local development](#local-development)
32+
- [License](#license)
933

1034
## Installing
1135

@@ -25,23 +49,9 @@ rustup target add \
2549

2650
Modify as necessary for your use case.
2751

28-
## Usage
29-
30-
If you have installed the NDK with Android Studio to its default location, `cargo ndk` will automatically detect
31-
the most recent NDK version and use it. This can be overriden by specifying the path to the NDK root directory in
32-
the `ANDROID_NDK_HOME` environment variable.
52+
## Examples
3353

34-
### Examples
35-
36-
#### Running your tests on an Android device
37-
38-
```
39-
cargo ndk-test -t armeabi-v7a
40-
```
41-
42-
This uses `adb` under the hood to push the binaries to a connected device, and running it in the Android shell.
43-
44-
#### Building a library for 32-bit and 64-bit ARM systems
54+
### Building a library for 32-bit and 64-bit ARM systems
4555

4656
```
4757
cargo ndk -t armeabi-v7a -t arm64-v8a -o ./jniLibs build --release
@@ -52,7 +62,7 @@ expected by Android, and then the ordinary flags to be passed to `cargo`.
5262

5363
![Example](./example/example.svg)
5464

55-
#### Linking against and copying `libc++_shared.so` into the relevant places in the output directory
65+
### Linking against and copying `libc++_shared.so` into the relevant places in the output directory
5666

5767
Create a `build.rs` in your project with the following:
5868

@@ -83,6 +93,31 @@ fn android() {
8393
}
8494
```
8595

96+
## Usage
97+
98+
If you have installed the NDK with Android Studio to its default location, `cargo ndk` will automatically detect
99+
the most recent NDK version and use it. This can be overriden by specifying the path to the NDK root directory in
100+
the `ANDROID_NDK_HOME` environment variable.
101+
102+
### Using `cargo run` binaries via adb
103+
104+
If you want `cargo run` to automatically run via `adb` for Android builds, add a `.cargo/config.toml` to your project with the following content:
105+
106+
```toml
107+
[target.aarch64-linux-android]
108+
runner = "cargo ndk-runner"
109+
```
110+
111+
Add for each target that you are using.
112+
113+
### Running your tests on an Android device
114+
115+
```
116+
cargo ndk-test -t armeabi-v7a
117+
```
118+
119+
This uses `cargo ndk-runner` under the hood to push the binaries to a connected device, and running it in the Android shell.
120+
86121
### Controlling verbosity
87122

88123
Add `-v` or `-vv` as you ordinarily would after the cargo command.
@@ -134,6 +169,12 @@ Rust Analyzer and anything else with JSON-based environment handling:
134169

135170
For configuring rust-analyzer, add the `--json` flag and paste the blob into the relevant place in the config.
136171

172+
## Troubleshooting
173+
174+
### The build is complaining that some compiler builtins are missing. What do I do?
175+
176+
Add `--link-builtins` to your `cargo ndk build` command and you should be happy.
177+
137178
## Supported hosts
138179

139180
- Linux
@@ -150,10 +191,6 @@ You can also build for Termux or similar by providing the environment variable `
150191
cargo install --path .
151192
```
152193

153-
## Similar projects
154-
155-
* [cargo-cocoapods](https://github.com/bbqsrc/cargo-cocoapods) - for building .a files for all Apple platforms, and bundling for CocoaPods
156-
157194
## License
158195

159196
This project is licensed under either of

0 commit comments

Comments
 (0)