1# Copyright (c) 2022 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.
13
14import("//build/ohos.gni")
15import("//commonlibrary/ets_utils/ets_utils_config.gni")
16import("//foundation/arkui/ace_engine/ace_config.gni")
17import("//foundation/arkui/ace_engine/build/ace_gen_obj.gni")
18
19config("worker_public_config") {
20  include_dirs = [ js_concurrent_module_common ]
21}
22
23ohos_shared_library("worker") {
24  branch_protector_ret = "pac_ret"
25  sanitize = {
26    cfi = true
27    cfi_cross_dso = true
28    debug = false
29  }
30  include_dirs = [
31    "include",
32    ets_util_path,
33  ]
34  public_configs = [ ":worker_public_config" ]
35
36  sources = [
37    "../common/helper/napi_helper.cpp",
38    "message_queue.cpp",
39    "native_module_worker.cpp",
40    "thread.cpp",
41    "worker.cpp",
42    "worker_runner.cpp",
43  ]
44
45  deps = [ "${ets_util_path}/js_sys_module/timer:timer" ]
46
47  defines = []
48
49  if (is_ohos) {
50    defines += [ "OHOS_PLATFORM" ]
51  } else if (is_mingw) {
52    defines += [ "WINDOWS_PLATFORM" ]
53  } else if (target_os == "android") {
54    defines += [ "ANDROID_PLATFORM" ]
55  } else if (target_os == "ios") {
56    defines += [ "IOS_PLATFORM" ]
57  } else if (is_mac && target_os != "android") {
58    defines += [ "MAC_PLATFORM" ]
59  }
60
61  external_deps = [ "napi:ace_napi" ]
62
63  if (is_linux && current_toolchain == host_toolchain) {
64    external_deps += [ "innerkits:libhilog_linux" ]
65    defines = [
66      "LINUX_PLATFORM",
67      "PREVIEW",
68    ]
69  } else {
70    if (is_standard_system) {
71      external_deps += [
72        "hilog:libhilog",
73        "init:libbegetutil",
74      ]
75    } else {
76      external_deps += [ "hilog:libhilog" ]
77    }
78  }
79
80  if (is_ohos && is_standard_system && !is_arkui_x) {
81    defines += [ "ENABLE_WORKER_EVENTHANDLER" ]
82    external_deps += [ "eventhandler:libeventhandler" ]
83  }
84
85  external_deps += [ "hitrace:hitrace_meter" ]
86
87  subsystem_name = "commonlibrary"
88  part_name = "ets_utils"
89
90  relative_install_dir = "module"
91}
92
93ohos_source_set("worker_static") {
94  branch_protector_ret = "pac_ret"
95  sanitize = {
96    cfi = true
97    cfi_cross_dso = true
98    debug = false
99  }
100  include_dirs = [
101    js_concurrent_module_common,
102    "$concurrent_module/worker",
103    "$sys_module/timer",
104    ets_util_path,
105  ]
106
107  sources = [
108    "$js_concurrent_module_common/helper/napi_helper.cpp",
109    "$sys_module/timer/timer.cpp",
110    "message_queue.cpp",
111    "native_module_worker.cpp",
112    "thread.cpp",
113    "worker.cpp",
114    "worker_runner.cpp",
115  ]
116  deps = []
117
118  defines = []
119
120  external_deps = []
121  if (is_standard_system) {
122    external_deps += [
123      "hilog:libhilog",
124      "init:libbegetutil",
125    ]
126  } else {
127    external_deps += [
128      "c_utils:utils",
129      "hilog:libhilog",
130    ]
131  }
132
133  if (is_arkui_x) {
134    include_dirs += [
135      "$plugins_root/hilog/include",
136      "$plugins_root/interfaces",
137      "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
138    ]
139    sources -= [
140      "$js_concurrent_module_common/helper/napi_helper.cpp",
141      "$sys_module/timer/timer.cpp",
142    ]
143    defines += [ "__ARKUI_CROSS__" ]
144    deps += [
145      "$plugins_root/libs/napi:napi_${target_os}",
146      "$plugins_root/libs/uv:uv_${target_os}",
147      "$sys_module/timer:timer_static",
148    ]
149    if (target_os == "android") {
150      defines += [ "ANDROID_PLATFORM" ]
151    }
152    if (target_os == "ios") {
153      defines += [ "IOS_PLATFORM" ]
154    }
155  } else {
156    deps += [ "$napi_root:ace_napi" ]
157    external_deps += [ "hitrace:hitrace_meter" ]
158  }
159
160  if (is_ohos && is_standard_system && !is_arkui_x) {
161    defines += [ "ENABLE_WORKER_EVENTHANDLER" ]
162    external_deps += [ "eventhandler:libeventhandler" ]
163  }
164
165  subsystem_name = "commonlibrary"
166  part_name = "ets_utils"
167}
168
169group("worker_packages") {
170  deps = [ ":worker" ]
171}
172