1# Copyright (c) 2023 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13import("//build/ohos.gni")
14import("ffrt.gni")
15
16defines = []
17
18config("ffrt_config") {
19  visibility = [ ":*" ]
20  include_dirs = [
21    "interfaces/kits",
22    "interfaces/inner_api",
23  ]
24
25  ffrt_defaults_cflags = [
26    "-Wno-unused-variable",
27    "-Wno-unused-function",
28    "-Wno-unused-value",
29    "-Wno-unused-private-field",
30    "-Wno-tautological-constant-out-of-range-compare",
31    "-Wno-shadow",
32    "-Wno-float-equal",
33    "-Wno-unused-parameter",
34    "-fno-common",
35  ]
36
37  cflags = ffrt_defaults_cflags
38  cflags_c = [ "-fno-common" ]
39  cflags_cc = ffrt_defaults_cflags
40
41  ffrt_debug_defines = [
42    "FFRT_LOG_LEVEL=3",
43    "FFRT_BBOX_ENABLE",
44    "FFRT_OH_EVENT_RECORD",
45    "FFRT_CO_BACKTRACE_OH_ENABLE",
46    "FFRT_OH_TRACE_ENABLE",
47    "FFRT_TRACE_LEVEL=1",
48    "FFRT_TRACE_RECORD_LEVEL=1",
49    "FFRT_SEND_EVENT",
50    "FFRT_ALLOCATOR_MMAP_SIZE=${ffrt_allocator_mmap_size}",
51    "FFRT_STACK_SIZE=${ffrt_stack_size}",
52  ]
53
54  #ffrt_release_defines = [
55  #  "FFRT_LOG_LEVEL=0",
56  #  "FFRT_RELEASE",
57  #]
58
59  defines += ffrt_debug_defines
60
61  if (target_cpu == "arm") {
62    defines += [ "APP_USE_ARM" ]
63  }
64
65  if (is_ohos && !ffrt_task_local_enable) {
66    defines += [ "FFRT_TASK_LOCAL_ENABLE" ]
67  }
68
69  #build_variant is root/user, default user
70  if (build_variant == "root") {
71    defines += [ "FFRT_ENG_DEBUG" ]
72  }
73
74  #defines += ffrt_release_defines
75}
76
77config("ffrt_inner_config") {
78  include_dirs = [
79    "src",
80    "src/dfx/log",
81    "src/dfx/trace",
82    "src/dfx/trace_record",
83    "src/sched",
84  ]
85
86  if (is_ohos && is_clang && (target_cpu == "arm" || target_cpu == "arm64")) {
87    cflags = [
88      "-flto=thin",
89      "-fsplit-lto-unit",
90    ]
91  }
92
93  ffrt_inner_cflags = [
94    "-std=c++17",
95    "-g",
96    "-D_FORTIFY_SOURCE=2",
97    "-O2",
98    "-fPIC",
99    "-DFFRT_PTHREAD_ENABLE",
100    "-DFFRT_OH_WATCHDOG_ENABLE",
101    "-DQOS_WORKER_FRAME_RTG",
102    "-DUSE_OHOS_QOS",
103    "-DOHOS_STANDARD_SYSTEM",
104    "-DTASKSTAT_LOG_ENABLE=0",
105  ]
106
107  cflags_cc = ffrt_inner_cflags
108}
109
110ohos_shared_library("libffrt") {
111  if (ffrt_support_enable) {
112    branch_protector_ret = "pac_ret"
113    public_configs = [ ":ffrt_config" ]
114    configs = [ ":ffrt_inner_config" ]
115    ldflags = [ "-Wl,-z,nodelete" ]
116
117    sources = [
118      "src/core/entity.cpp",
119      "src/core/task.cpp",
120      "src/core/task_io.cpp",
121      "src/core/version_ctx.cpp",
122      "src/dfx/bbox/bbox.cpp",
123      "src/dfx/bbox/fault_logger_fd_manager.cpp",
124      "src/dfx/dump/dump.cpp",
125      "src/dfx/log/ffrt_log.cpp",
126      "src/dfx/sysevent/sysevent.cpp",
127      "src/dfx/trace/ffrt_trace.cpp",
128      "src/dfx/trace_record/ffrt_trace_record.cpp",
129      "src/dfx/watchdog/watchdog_util.cpp",
130      "src/dm/dependence_manager.cpp",
131      "src/dm/sdependence_manager.cpp",
132      "src/eu/co2_context.c",
133      "src/eu/co_routine.cpp",
134      "src/eu/co_routine_factory.cpp",
135      "src/eu/cpu_monitor.cpp",
136      "src/eu/cpu_worker.cpp",
137      "src/eu/cpuworker_manager.cpp",
138      "src/eu/execute_unit.cpp",
139      "src/eu/loop.cpp",
140      "src/eu/loop_api.cpp",
141      "src/eu/osattr_manager.cpp",
142      "src/eu/qos_convert.cpp",
143      "src/eu/qos_interface.cpp",
144      "src/eu/rtg_ioctl.cpp",
145      "src/eu/rtg_perf_ctrl.cpp",
146      "src/eu/scpu_monitor.cpp",
147      "src/eu/scpuworker_manager.cpp",
148      "src/eu/sexecute_unit.cpp",
149      "src/eu/worker_manager.cpp",
150      "src/eu/worker_thread.cpp",
151      "src/ipc/ipc.cpp",
152      "src/queue/base_queue.cpp",
153      "src/queue/concurrent_queue.cpp",
154      "src/queue/eventhandler_adapter_queue.cpp",
155      "src/queue/eventhandler_interactive_queue.cpp",
156      "src/queue/queue_api.cpp",
157      "src/queue/queue_handler.cpp",
158      "src/queue/queue_monitor.cpp",
159      "src/queue/serial_queue.cpp",
160      "src/sched/deadline.cpp",
161      "src/sched/execute_ctx.cpp",
162      "src/sched/frame_interval.cpp",
163      "src/sched/interval.cpp",
164      "src/sched/load_tracking.cpp",
165      "src/sched/multi_workgroup.cpp",
166      "src/sched/qos.cpp",
167      "src/sched/sched_deadline.cpp",
168      "src/sched/scheduler.cpp",
169      "src/sched/task_manager.cpp",
170      "src/sched/task_state.cpp",
171      "src/sync/condition_variable.cpp",
172      "src/sync/delayed_worker.cpp",
173      "src/sync/io_poller.cpp",
174      "src/sync/mutex.cpp",
175      "src/sync/perf_counter.cpp",
176      "src/sync/poller.cpp",
177      "src/sync/poller_api.cpp",
178      "src/sync/record_mutex.cpp",
179      "src/sync/shared_mutex.cpp",
180      "src/sync/sleep.cpp",
181      "src/sync/sync.cpp",
182      "src/sync/thread.cpp",
183      "src/sync/timer_api.cpp",
184      "src/sync/wait_queue.cpp",
185      "src/tm/cpu_task.cpp",
186      "src/tm/queue_task.cpp",
187      "src/tm/scpu_task.cpp",
188      "src/tm/task_factory.cpp",
189      "src/util/ffrt_cpu_boost.cpp",
190      "src/util/ffrt_facade.cpp",
191      "src/util/graph_check.cpp",
192      "src/util/init.cpp",
193      "src/util/spmc_queue.cpp",
194      "src/util/worker_monitor.cpp",
195    ]
196
197    external_deps = [
198      "bounds_checking_function:libsec_shared",
199      "c_utils:utils",
200      "faultloggerd:libbacktrace_local",
201      "faultloggerd:libdfx_dumpcatcher",
202      "faultloggerd:libfaultloggerd",
203      "faultloggerd:libunwinder",
204      "hilog:libhilog",
205      "hisysevent:libhisysevent",
206    ]
207
208    defines = []
209
210    if (ffrt_async_stack_enable) {
211      defines += [ "ASYNC_STACKTRACE" ]
212      sources += [ "src/dfx/async_stack/ffrt_async_stack.cpp" ]
213    }
214
215    output_extension = "so"
216    symlink_target_name = [ "libffrt.z.so" ]
217    part_name = "ffrt"
218    subsystem_name = "resourceschedule"
219    install_images = [
220      "system",
221      "updater",
222    ]
223    innerapi_tags = [
224      "chipsetsdk",
225      "ndk",
226      "sasdk",
227    ]
228  }
229}
230
231ohos_prebuilt_etc("blacklist_cfg") {
232  relative_install_dir = "ffrt"
233  source = "worker_monitor.conf"
234  part_name = "ffrt"
235  subsystem_name = "resourceschedule"
236  install_enable = true
237  install_images = [
238    "system",
239    "updater",
240  ]
241}
242
243group("ffrt_ndk") {
244  deps = [
245    ":blacklist_cfg",
246    ":libffrt",
247  ]
248}
249