polyhorn_cli/android/targets.rs
1/// Represents a Android ABI target that is used to build for an Android device
2/// with a specific CPU and instruction set.
3pub struct Target<'a> {
4 /// This is the name for the ABI that Android uses internally (e.g. in
5 /// `jniLibs`).
6 pub abi: &'a str,
7
8 /// This is the name of the target that llvm/rustc uses.
9 pub llvm_triple: &'a str,
10
11 /// This is the name of the archiver utility shipped with the NDK.
12 pub ar: &'a str,
13
14 /// This is the name of the C compiler shipped with the NDK.
15 pub cc: &'a str,
16
17 /// This is the name of the C++ compiler shipped with the NDK.
18 pub cxx: &'a str,
19
20 /// This is the name of the linker shipped with the NDK.
21 pub linker: &'a str,
22}
23
24impl<'a> Target<'a> {
25 const ALL: [Target<'static>; 4] = [
26 Target::armeabi_v7a(),
27 Target::arm64_v8a(),
28 Target::x86(),
29 Target::x86_64(),
30 ];
31
32 /// Returns all available Android targets.
33 pub const fn all() -> &'static [Target<'static>] {
34 &Self::ALL
35 }
36
37 /// Returns a target configuration for the `armeabi-v7a` ABI.
38 pub const fn armeabi_v7a() -> Target<'static> {
39 Target {
40 abi: "armeabi-v7a",
41 llvm_triple: "armv7-linux-androideabi",
42 ar: "arm-linux-androideabi-ar",
43 cc: "armv7a-linux-androideabi16-clang",
44 cxx: "armv7a-linux-androideabi16-clang++",
45 linker: "armv7a-linux-androideabi16-clang",
46 }
47 }
48
49 /// Returns a target configuration for the `arm64-v8a` ABI (also known as
50 /// `aarch64`). This target has been available since API level 21 (the first
51 /// version of Android to support 64-bit architectures).
52 pub const fn arm64_v8a() -> Target<'static> {
53 Target {
54 abi: "arm64-v8a",
55 llvm_triple: "aarch64-linux-android",
56 ar: "aarch64-linux-android-ar",
57 cc: "aarch64-linux-android21-clang",
58 cxx: "aarch64-linux-android21-clang++",
59 linker: "aarch64-linux-android21-clang",
60 }
61 }
62
63 /// Returns a target configuration for the `x86` ABI (also known as `i686`).
64 pub const fn x86() -> Target<'static> {
65 Target {
66 abi: "x86",
67 llvm_triple: "i686-linux-android",
68 ar: "i686-linux-android-ar",
69 cc: "i686-linux-android16-clang",
70 cxx: "i686-linux-android16-clang++",
71 linker: "i686-linux-android16-clang",
72 }
73 }
74
75 /// Returns a target configuration for the `x86_64` ABI. This target has
76 /// been available since API level 21 (the first version of Android to
77 /// support 64-bit architectures).
78 pub const fn x86_64() -> Target<'static> {
79 Target {
80 abi: "x86_64",
81 llvm_triple: "x86_64-linux-android",
82 ar: "x86_64-linux-android-ar",
83 cc: "x86_64-linux-android21-clang",
84 cxx: "x86_64-linux-android21-clang++",
85 linker: "x86_64-linux-android21-clang",
86 }
87 }
88}