1// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15
16package {
17    default_applicable_licenses: ["Android-Apache-2.0"],
18}
19
20cc_library_headers {
21    name: "libberberis_runtime_primitives_headers",
22    defaults: ["berberis_defaults"],
23    host_supported: true,
24    export_include_dirs: ["include"],
25    header_libs: [
26        "libberberis_assembler_headers",
27        "libberberis_base_headers",
28        "libberberis_guest_state_headers",
29    ],
30    export_header_lib_headers: [
31        "libberberis_assembler_headers",
32        "libberberis_base_headers",
33        "libberberis_guest_state_headers",
34    ],
35}
36
37cc_library_static {
38    name: "libberberis_runtime_primitives",
39    defaults: ["berberis_defaults"],
40    host_supported: true,
41    srcs: [
42        "code_pool.cc",
43        "crash_reporter.cc",
44        "guest_function_wrapper_impl.cc",
45        "host_function_wrapper_impl.cc",
46        "known_guest_function_wrapper.cc",
47        "platform.cc",
48        "profiler_interface.cc",
49        "recovery_code.cc",
50        "signal_queue.cc",
51        "translation_cache.cc",
52        "virtual_guest_call_frame.cc",
53    ],
54    header_libs: [
55        "libberberis_code_gen_lib_headers",
56        "libberberis_base_headers",
57        "libberberis_guest_abi_headers",
58        "libberberis_guest_state_headers",
59        "libberberis_instrument_headers",
60        "libberberis_runtime_primitives_headers",
61    ],
62    export_header_lib_headers: ["libberberis_runtime_primitives_headers"],
63}
64
65filegroup {
66    name: "berberis_memory_region_reservation_srcs",
67    srcs: [
68        "memory_region_reservation.cc",
69    ],
70}
71
72cc_defaults {
73    name: "berberis_memory_region_reservation_defaults",
74    defaults: ["berberis_defaults"],
75    host_supported: true,
76    srcs: [":berberis_memory_region_reservation_srcs"],
77    header_libs: [
78        "libberberis_runtime_primitives_headers",
79    ],
80    arch: {
81        x86_64: {
82            cflags: [
83                // CMPXCHG16B is not enabled for host by default at the moment.
84                // It should be always available for our use cases, though.
85                // TODO(b/123428084): Remove if it becomes the default.
86                "-mcx16",
87            ],
88        },
89    },
90    // Targets using these defaults must provide the following guest-specific fields:
91    // header_libs: ["libberberis_guest_state_<guest>_headers"],
92    // export_header_lib_headers: ["libberberis_guest_state_<guest>_headers"],
93}
94
95cc_library_static {
96    name: "libberberis_runtime_primitives_riscv64",
97    defaults: [
98        "berberis_defaults_64",
99        "berberis_memory_region_reservation_defaults",
100    ],
101    host_supported: true,
102    srcs: [
103        "checks_riscv64.cc",
104        "interpret_helpers_riscv64.cc",
105        "virtual_guest_call_frame_riscv64.cc",
106    ],
107    whole_static_libs: [
108        "libberberis_runtime_primitives",
109    ],
110    header_libs: [
111        "libberberis_assembler_headers",
112        "libberberis_base_headers",
113        "libberberis_guest_state_riscv64_headers",
114        "libberberis_runtime_primitives_headers",
115    ],
116    export_header_lib_headers: [
117        "libberberis_runtime_primitives_headers",
118        "libberberis_guest_state_riscv64_headers",
119    ],
120}
121
122cc_test_library {
123    name: "libberberis_runtime_primitives_unit_tests",
124    defaults: ["berberis_test_library_defaults"],
125    host_supported: true,
126    srcs: [
127        "code_pool_test.cc",
128        "signal_queue_test.cc",
129        "table_of_tables_test.cc",
130    ],
131    header_libs: [
132        "berberis_test_utils_headers",
133        "libberberis_guest_state_riscv64_headers",
134        "libberberis_runtime_primitives_headers",
135    ],
136    // libgmock does not have header_lib
137    static_libs: ["libgmock"],
138}
139
140cc_test_library {
141    name: "libberberis_runtime_primitives_riscv64_unit_tests",
142    defaults: ["berberis_test_library_defaults_64"],
143    host_supported: true,
144    srcs: [
145        "memory_region_reservation_test.cc",
146        // Translation cache test relies on implementation of runtime_library
147        // function pointers to link.
148        "translation_cache_test.cc",
149        "virtual_guest_call_frame_riscv64_test.cc",
150    ],
151    header_libs: [
152        "berberis_test_utils_headers",
153        "libberberis_guest_state_riscv64_headers",
154        "libberberis_runtime_primitives_headers",
155    ],
156}
157