1package {
2    default_visibility: [":__subpackages__"],
3    default_applicable_licenses: ["Android-Apache-2.0"],
4}
5
6rust_defaults {
7    name: "libdiced_open_dice_defaults",
8    crate_name: "diced_open_dice",
9    defaults: ["avf_build_flags_rust"],
10    srcs: ["src/lib.rs"],
11}
12
13rust_library_rlib {
14    name: "libdiced_open_dice_nostd",
15    defaults: ["libdiced_open_dice_defaults"],
16    rustlibs: [
17        "libcoset_nostd",
18        "libopen_dice_android_bindgen_nostd",
19        "libopen_dice_cbor_bindgen_nostd",
20        "libzeroize_nostd",
21    ],
22    features: [
23        "multialg",
24    ],
25    whole_static_libs: [
26        "libcrypto_baremetal",
27    ],
28    visibility: [
29        "//packages/modules/Virtualization:__subpackages__",
30    ],
31}
32
33rust_library {
34    name: "libdiced_open_dice",
35    defaults: ["libdiced_open_dice_defaults"],
36    host_supported: true,
37    vendor_available: true,
38    rustlibs: [
39        "libcoset",
40        "libopen_dice_android_bindgen",
41        "libopen_dice_cbor_bindgen",
42        "libserde",
43        "libzeroize",
44    ],
45    features: [
46        "serde_derive",
47        "std",
48    ],
49    proc_macros: ["libserde_derive"],
50    shared_libs: [
51        "libcrypto",
52    ],
53    visibility: [
54        "//hardware/interfaces/security/secretkeeper/aidl/vts",
55        "//packages/modules/Virtualization:__subpackages__",
56        "//system/authgraph/tests:__subpackages__",
57        "//system/secretkeeper/client:__subpackages__",
58        "//system/software_defined_vehicle:__subpackages__",
59    ],
60    apex_available: [
61        "//apex_available:platform",
62        "com.android.virt",
63    ],
64}
65
66rust_defaults {
67    name: "libdiced_open_dice_test_defaults",
68    crate_name: "diced_open_dice_test",
69    srcs: ["tests/api_test.rs"],
70    test_suites: ["general-tests"],
71}
72
73rust_test {
74    name: "libdiced_open_dice.integration_test",
75    defaults: ["libdiced_open_dice_test_defaults"],
76    rustlibs: [
77        "libdiced_open_dice",
78    ],
79}
80
81rust_test {
82    name: "libdiced_open_dice_nostd.integration_test",
83    defaults: ["libdiced_open_dice_test_defaults"],
84    rustlibs: [
85        "libdiced_open_dice_nostd",
86    ],
87}
88
89rust_defaults {
90    name: "libopen_dice_bindgen_nostd.rust_defaults",
91    bindgen_flags: [
92        "--use-core",
93        "--ctypes-prefix=core::ffi",
94        "--raw-line=#![no_std]",
95    ],
96    dylib: {
97        enabled: false,
98    },
99    no_stdlibs: true,
100    prefer_rlib: true,
101    stdlibs: [
102        "libcore.rust_sysroot",
103        "libcompiler_builtins.rust_sysroot",
104    ],
105    target: {
106        musl: {
107            enabled: false,
108        },
109        glibc: {
110            enabled: false,
111        },
112        darwin: {
113            enabled: false,
114        },
115    },
116}
117
118rust_defaults {
119    name: "libopen_dice.rust_defaults",
120    host_supported: true,
121    vendor_available: true,
122    apex_available: [
123        "//apex_available:platform",
124        "com.android.compos",
125        "com.android.virt",
126    ],
127}
128
129rust_defaults {
130    name: "libopen_dice_cbor_bindgen.rust_defaults",
131    wrapper_src: "bindgen/dice.h",
132    crate_name: "open_dice_cbor_bindgen",
133    source_stem: "bindings",
134    bindgen_flags: [
135        "--rustified-enum DiceConfigType",
136        "--rustified-enum DiceMode",
137        "--rustified-enum DiceResult",
138        "--rustified-enum DicePrincipal",
139
140        // By generating only essential functions, we can make bindings concise and
141        // optimize compilation time.
142        "--allowlist-function=DiceDeriveCdiPrivateKeySeed",
143        "--allowlist-function=DiceDeriveCdiCertificateId",
144        "--allowlist-function=DiceMainFlow",
145        "--allowlist-function=DiceHash",
146        "--allowlist-function=DiceKdf",
147        "--allowlist-function=DiceKeypairFromSeed",
148        "--allowlist-function=DiceSign",
149        "--allowlist-function=DiceVerify",
150        "--allowlist-function=DiceGenerateCertificate",
151
152        // We also need some constants in addition to the functions.
153        "--allowlist-var=DICE_CDI_SIZE",
154        "--allowlist-var=DICE_HASH_SIZE",
155        "--allowlist-var=DICE_HIDDEN_SIZE",
156        "--allowlist-var=DICE_INLINE_CONFIG_SIZE",
157        "--allowlist-var=DICE_PRIVATE_KEY_SEED_SIZE",
158        "--allowlist-var=DICE_ID_SIZE",
159        "--allowlist-var=DICE_PRIVATE_KEY_BUFFER_SIZE",
160    ],
161}
162
163rust_bindgen {
164    name: "libopen_dice_cbor_bindgen",
165    defaults: [
166        "libopen_dice.rust_defaults",
167        "libopen_dice_cbor_bindgen.rust_defaults",
168    ],
169    whole_static_libs: ["libopen_dice_cbor"],
170}
171
172rust_bindgen {
173    name: "libopen_dice_cbor_bindgen_nostd",
174    defaults: [
175        "libopen_dice_cbor_bindgen.rust_defaults",
176        "libopen_dice_bindgen_nostd.rust_defaults",
177    ],
178    bindgen_flags: [
179        "--rustified-enum DiceKeyAlgorithm",
180        "--allowlist-type=DiceContext",
181    ],
182    whole_static_libs: ["libopen_dice_cbor_baremetal_multialg"],
183}
184
185rust_defaults {
186    name: "libopen_dice_android_bindgen.rust_defaults",
187    wrapper_src: "bindgen/android.h",
188    crate_name: "open_dice_android_bindgen",
189    source_stem: "bindings",
190    bindgen_flags: [
191        // By generating only essential functions, we can make bindings concise and
192        // optimize compilation time.
193        "--allowlist-function=DiceAndroidFormatConfigDescriptor",
194        "--allowlist-function=DiceAndroidMainFlow",
195        "--allowlist-function=DiceAndroidHandoverMainFlow",
196        "--allowlist-function=DiceAndroidHandoverParse",
197
198        // We also need some constants in addition to the functions.
199        "--allowlist-var=DICE_ANDROID_CONFIG_.*",
200
201        // Prevent DiceInputValues from being generated a second time and
202        // import it instead from open_dice_cbor_bindgen.
203        "--blocklist-type=DiceInputValues_",
204        "--blocklist-type=DiceInputValues",
205        "--raw-line",
206        "pub use open_dice_cbor_bindgen::DiceInputValues;",
207
208        // Prevent DiceResult from being generated a second time and
209        // import it instead from open_dice_cbor_bindgen.
210        "--blocklist-type=DiceResult",
211        "--raw-line",
212        "pub use open_dice_cbor_bindgen::DiceResult;",
213    ],
214
215}
216
217rust_bindgen {
218    name: "libopen_dice_android_bindgen",
219    defaults: [
220        "libopen_dice.rust_defaults",
221        "libopen_dice_android_bindgen.rust_defaults",
222    ],
223    rustlibs: [
224        "libopen_dice_cbor_bindgen",
225    ],
226    whole_static_libs: ["libopen_dice_android"],
227}
228
229rust_bindgen {
230    name: "libopen_dice_android_bindgen_nostd",
231    defaults: [
232        "libopen_dice_android_bindgen.rust_defaults",
233        "libopen_dice_bindgen_nostd.rust_defaults",
234    ],
235    rustlibs: [
236        "libopen_dice_cbor_bindgen_nostd",
237    ],
238    whole_static_libs: ["libopen_dice_android_baremetal_multialg"],
239}
240
241rust_test {
242    name: "libopen_dice_cbor_bindgen_test",
243    srcs: [
244        ":libopen_dice_cbor_bindgen",
245    ],
246    crate_name: "open_dice_cbor_bindgen_test",
247    test_suites: ["general-tests"],
248    auto_gen_config: true,
249    clippy_lints: "none",
250    lints: "none",
251}
252
253rust_test {
254    name: "libopen_dice_android_bindgen_test",
255    srcs: [
256        ":libopen_dice_android_bindgen",
257    ],
258    crate_name: "open_dice_android_bindgen_test",
259    rustlibs: [
260        "libopen_dice_cbor_bindgen",
261    ],
262    test_suites: ["general-tests"],
263    auto_gen_config: true,
264    clippy_lints: "none",
265    lints: "none",
266}
267