-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split C interop slides into smaller slides.
Part of #2445. This splits up the slides in the interop with C section into smaller slides. For calling C from Rust, instead of the long slide containing the sample C lib, explaining bindgen, and how to run the Rust code, these are now presented on separate slides. Similarly for calling Rust from C, the simple Rust library is on its own slide, followed by a slide on how to then call and run the Rust library from C.
- Loading branch information
Eric Githinji
committed
Feb 14, 2025
1 parent
699c513
commit 599dbd0
Showing
7 changed files
with
85 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# A Simple C Library | ||
|
||
Let's first create a small C library: | ||
|
||
_interoperability/bindgen/libbirthday.h_: | ||
|
||
```c | ||
{{#include bindgen/libbirthday.h:card}} | ||
``` | ||
_interoperability/bindgen/libbirthday.c_: | ||
```c | ||
{{#include bindgen/libbirthday.c:print_card}} | ||
``` | ||
|
||
Add this to your `Android.bp` file: | ||
|
||
_interoperability/bindgen/Android.bp_: | ||
|
||
```javascript | ||
{{#include bindgen/Android.bp:libbirthday}} | ||
``` | ||
|
||
Create a wrapper header file for the library (not strictly needed in this | ||
example): | ||
|
||
_interoperability/bindgen/libbirthday_wrapper.h_: | ||
|
||
```c | ||
{{#include bindgen/libbirthday_wrapper.h:include}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Running Our Binary | ||
|
||
Build, push, and run the binary on your device: | ||
|
||
```shell | ||
{{#include ../../build_all.sh:print_birthday_card}} | ||
``` | ||
|
||
Finally, we can run auto-generated tests to ensure the bindings work: | ||
|
||
_interoperability/bindgen/Android.bp_: | ||
|
||
```javascript | ||
{{#include bindgen/Android.bp:libbirthday_bindgen_test}} | ||
``` | ||
|
||
```shell | ||
{{#include ../../build_all.sh:libbirthday_bindgen_test}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# A Simple Rust Library | ||
|
||
Exporting Rust functions and types to C is easy. Here's a simple Rust library: | ||
|
||
_interoperability/rust/libanalyze/analyze.rs_ | ||
|
||
```rust,editable | ||
{{#include rust/libanalyze/analyze.rs:analyze_numbers}} | ||
``` | ||
|
||
_interoperability/rust/libanalyze/Android.bp_ | ||
|
||
```javascript | ||
{{#include rust/libanalyze/Android.bp}} | ||
``` | ||
|
||
<details> | ||
|
||
`#[unsafe(no_mangle)]` disables Rust's usual name mangling, so the exported | ||
symbol will just be the name of the function. You can also use | ||
`#[unsafe(export_name = "some_name")]` to specify whatever name you want. | ||
|
||
</details> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters