Bare-Metal on Android
To build a bare-metal Rust binary in AOSP, you need to use a rust_ffi_static Soong rule to build your Rust code, then a cc_binary with a linker script to produce the binary itself, and then a raw_binary to convert the ELF to a raw binary ready to be run.
1. rust_ffi_static {
2. name: "libvmbase_example",
3. defaults: ["vmbase_ffi_defaults"],
4. crate_name: "vmbase_example",
5. srcs: ["src/main.rs"],
6. rustlibs: [
7. "libvmbase",
8. ],
9. }
11. cc_binary {
12. name: "vmbase_example",
13. defaults: ["vmbase_elf_defaults"],
14. srcs: [
15. "idmap.S",
16. ],
17. static_libs: [
18. "libvmbase_example",
19. ],
20. linker_scripts: [
21. "image.ld",
22. ":vmbase_sections",
23. ],
24. }
26. raw_binary {
27. name: "vmbase_example_bin",
28. stem: "vmbase_example.bin",
29. src: ":vmbase_example",
30. enabled: false,
31. target: {
32. android_arm64: {
33. enabled: true,
34. },
35. },
36. }
