mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-07 18:16:15 +02:00
38 lines
760 B
Markdown
38 lines
760 B
Markdown
|
# Rust Libraries
|
||
|
|
||
|
You use `rust_library` to create a new Rust library for Android.
|
||
|
|
||
|
Here we declare a dependency on two libraries:
|
||
|
|
||
|
* `libgreeting`, which we define below,
|
||
|
* `libtextwrap`, which is a crate already vendored in
|
||
|
[`external/rust/crates/`][crates].
|
||
|
|
||
|
[crates]: https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/
|
||
|
|
||
|
_hello_rust/Android.bp_:
|
||
|
|
||
|
```javascript
|
||
|
{{#include library/Android.bp}}
|
||
|
```
|
||
|
|
||
|
_hello_rust/src/main.rs_:
|
||
|
|
||
|
```rust,ignore
|
||
|
{{#include library/src/main.rs:main}}
|
||
|
```
|
||
|
|
||
|
_hello_rust/src/lib.rs_:
|
||
|
|
||
|
```rust,ignore
|
||
|
{{#include library/src/lib.rs:greeting}}
|
||
|
```
|
||
|
|
||
|
You build, push, and run the binary like before:
|
||
|
|
||
|
```shell
|
||
|
{{#include ../build_all.sh:hello_rust_with_dep}}
|
||
|
Hello Bob, it is very
|
||
|
nice to meet you!
|
||
|
```
|