• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2025 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("//arkcompiler/runtime_core/static_core/ark_config.gni")
15
16if (ark_standalone_build) {
17  import("$build_root/ark.gni")
18} else {
19  import("//build/ohos.gni")
20}
21
22if (!(ark_standalone_build ||
23      (defined(ark_static_standalone_build) && ark_static_standalone_build))) {
24  import("//build/config/components/ets_frontend/ets2abc_config.gni")
25}
26
27# NB! Standard library is built only if the front-end is available.
28with_stdlib = false
29foreach(plugin, ark_enabled_plugins) {
30  if (plugin == "ecmascript" || plugin == "ets") {
31    with_stdlib = true
32  }
33}
34
35# Note(ivan-tyulyandin): internal issue #21800
36with_sdk = false
37
38group("ark_packages") {
39  deps = [
40    "runtime/libani_helpers:ani_helpers",
41    "runtime/napi/etsnative:etsnative",
42  ]
43
44  if (ark_static_standalone_build) {
45    deps += [ "$ark_es2panda_root/aot:ets2panda" ]
46  }
47  if (with_stdlib) {
48    deps += [ ":etsstdlib" ]
49  }
50  if (with_sdk) {
51    deps += [ ":etssdk" ]
52  }
53  if (ark_ets_interop_js) {
54    deps += [ "runtime/interop_js:ets_interop_js_napi" ]
55  }
56  if (!(ark_standalone_build ||
57        (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) ||
58        (defined(ark_static_standalone_build) && ark_static_standalone_build))) {
59    deps += [
60      ":commonsdk_packages",
61      ":etsstdlib_bootabc",
62    ]
63  }
64}
65
66if (!(ark_standalone_build ||
67      (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) ||
68      (defined(ark_static_standalone_build) && ark_static_standalone_build))) {
69  generate_static_abc("ets2abc_etsstdlib_bootabc") {
70    arktsconfig = "$ark_root/plugins/ets/stdlib/arktsconfig.json"
71    dst_file = "$target_out_dir/etsstdlib_bootabc.abc"
72    out_puts = [ "$target_out_dir/etsstdlib_bootabc.abc" ]
73    is_boot_abc = "True"
74    device_dst_file = "/system/framework/etsstdlib_bootabc.abc"
75    is_stdlib = "True"
76  }
77
78  ohos_prebuilt_etc("etsstdlib_bootabc_etc") {
79    source = "$target_out_dir/etsstdlib_bootabc.abc"
80    module_install_dir = "framework"
81    subsystem_name = "arkcompiler"
82    part_name = "runtime_core"
83    deps = [ ":ets2abc_etsstdlib_bootabc" ]
84  }
85
86  group("etsstdlib_bootabc") {
87    deps = [ ":etsstdlib_bootabc_etc" ]
88  }
89
90  ohos_prebuilt_etc("ets2abc_commonsdk_api_etc") {
91    source = "$target_out_dir/ets2abc_commonsdk_api.abc"
92    module_install_dir = "framework"
93    subsystem_name = "arkcompiler"
94    part_name = "runtime_core"
95    deps = [ ":ets2abc_commonsdk_api" ]
96  }
97
98  generate_static_abc("ets2abc_commonsdk_api") {
99    base_url = "./sdk/api"
100    files = [
101      "./sdk/api/@ohos.buffer.ets",
102      "./sdk/api/@ohos.uri.ets",
103      "./sdk/api/@ohos.url.ets",
104      "./sdk/api/@ohos.util.ArrayList.ets",
105      "./sdk/api/@ohos.util.Deque.ets",
106      "./sdk/api/@ohos.util.HashMap.ets",
107      "./sdk/api/@ohos.util.HashSet.ets",
108      "./sdk/api/@ohos.util.json.ets",
109      "./sdk/api/@ohos.util.LightWeightMap.ets",
110      "./sdk/api/@ohos.util.LightWeightSet.ets",
111      "./sdk/api/@ohos.util.LinkedList.ets",
112      "./sdk/api/@ohos.util.List.ets",
113      "./sdk/api/@ohos.util.PlainArray.ets",
114      "./sdk/api/@ohos.util.Queue.ets",
115      "./sdk/api/@ohos.util.Stack.ets",
116      "./sdk/api/@ohos.util.stream.ets",
117      "./sdk/api/@ohos.util.ets",
118      "./sdk/api/@ohos.util.TreeMap.ets",
119      "./sdk/api/@ohos.util.TreeSet.ets",
120      "./sdk/api/@ohos.xml.ets",
121    ]
122    is_boot_abc = "True"
123    device_dst_file = "/system/framework/ets2abc_commonsdk_api.abc"
124  }
125
126  ohos_prebuilt_etc("ets2abc_commonsdk_arkts_etc") {
127    source = "$target_out_dir/ets2abc_commonsdk_arkts.abc"
128    module_install_dir = "framework"
129    subsystem_name = "arkcompiler"
130    part_name = "runtime_core"
131    deps = [ ":ets2abc_commonsdk_arkts" ]
132  }
133
134  generate_static_abc("ets2abc_commonsdk_arkts") {
135    base_url = "./sdk/arkts"
136    files = [
137      "./sdk/arkts/@arkts.math.Decimal.ets",
138      "./sdk/arkts/@arkts.collections.ets",
139    ]
140    is_boot_abc = "True"
141    device_dst_file = "/system/framework/ets2abc_commonsdk_arkts.abc"
142  }
143
144  ohos_shared_library("ets_sdk_native") {
145    include_dirs = [
146      "$ark_root/plugins/ets",
147      "$ark_root/plugins/ets/runtime",
148      "$ark_root/plugins/ets/runtime/ani",
149      "$ark_root/plugins/ets/runtime/napi",
150      "$ark_root/plugins/ets/sdk",
151      "$ark_root/plugins/ets/sdk/native",
152    ]
153    sources = [
154      "$ark_root/plugins/ets/sdk/native/api/Util.cpp",
155      "$ark_root/plugins/ets/sdk/native/api/ani_stringdecoder.cpp",
156      "$ark_root/plugins/ets/sdk/native/api/ani_textdecoder.cpp",
157      "$ark_root/plugins/ets/sdk/native/api/ani_textencoder.cpp",
158      "$ark_root/plugins/ets/sdk/native/api/ani_textencoder_helper.cpp",
159      "$ark_root/plugins/ets/sdk/native/main.cpp",
160      "$ark_root/plugins/ets/stdlib/native/core/stdlib_ani_helpers.cpp",
161    ]
162    external_deps = [
163      "bounds_checking_function:libsec_shared",
164      "c_utils:utils",
165      "hilog:libhilog",
166      "openssl:libcrypto_shared",
167      icuuc_dep,
168    ]
169    deps = [
170      "$ark_root/libpandabase:libarktsbase_static",
171      "$ark_root/plugins/ets/runtime/ani:ani",
172    ]
173    subsystem_name = "arkcompiler"
174    part_name = "runtime_core"
175    output_extension = "so"
176  }
177  group("commonsdk_packages") {
178    deps = [
179      ":ets2abc_commonsdk_api_etc",
180      ":ets2abc_commonsdk_arkts_etc",
181      ":ets_sdk_native",
182    ]
183  }
184}
185
186group("ark_host_linux_tools_packages") {
187}
188
189group("ark_host_windows_tools_packages") {
190  # Required, but empty: nothing to add currently
191}
192
193group("ark_host_mac_tools_packages") {
194  # Required, but empty: nothing to add currently
195}
196
197config("ark_config") {
198  defines = [ "PANDA_WITH_ETS" ]
199
200  if (ark_ets_interop_js) {
201    defines += [ "PANDA_ETS_INTEROP_JS" ]
202  }
203}
204
205# TODO(nsizov): Fix and clean after PR480 is merged
206group("assembler_deps") {
207  deps = [ ":ark_asm_ets_meta_gen_h" ]
208}
209config("assembler") {
210  include_dirs = [
211    "$ark_root/plugins/ets/assembler/extension",
212    "$target_gen_dir",
213  ]
214}
215ark_gen_file("ark_asm_ets_meta_gen_h") {
216  template_file = "$ark_root/assembler/templates/meta_gen.cpp.erb"
217  data = [ "$ark_root/plugins/ets/assembler/extension/metadata.yaml" ]
218  api = [ "$ark_root/assembler/asm_metadata.rb" ]
219  output_file = "$target_gen_dir/ets_meta_gen.h"
220}
221
222config("runtime") {
223  include_dirs = [ "$ark_root/plugins/ets/runtime" ]
224  configs = [
225    "$ark_es2panda_root:libes2panda_public_config",
226    "$ark_root/assembler:arkassembler_public_config",
227    "$ark_root/libpandafile:arkfile_public_config",
228  ]
229}
230
231config("runtime_interpreter_impl") {
232  # Required, but empty: nothing to add currently
233}
234
235config("bytecodeopt") {
236  include_dirs = [
237    "$ark_root/plugins/ets/bytecode_optimizer/",
238    "$target_gen_dir",
239  ]
240}
241
242ark_isa_gen("isa_gen_ets_bytecodeopt") {
243  template_files = [ "ets_codegen_intrinsics_gen.inc.erb" ]
244  sources = "$ark_root/plugins/ets/bytecode_optimizer/templates/"
245  destination = "$target_gen_dir/"
246  requires = [ "$ark_root/assembler/asm_isapi.rb" ]
247}
248
249if (with_stdlib) {
250  es2panda_gen("etsstdlib") {
251    inputs = [ "stdlib" ]
252    if (ark_static_standalone_build) {
253      outputs = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ]
254    } else {
255      outputs = [ "$target_gen_dir/etsstdlib.abc" ]
256    }
257    abs_ark_root = rebase_path(ark_root)
258    json_array = [
259      "{",
260      "  \"compilerOptions\": {",
261      "    \"baseUrl\": \"$abs_ark_root\",",
262      "    \"paths\": {",
263      "      \"std\": [\"$abs_ark_root" + "/plugins/ets/stdlib/std\"],",
264      "      \"escompat\": [\"$abs_ark_root" +
265          "/plugins/ets/stdlib/escompat\"],",
266      "      \"api\": [\"$abs_ark_root" + "/plugins/ets/sdk/api\"],",
267      "      \"arkts\": [\"$abs_ark_root" + "/plugins/ets/sdk/arkts\"],",
268      "      \"import_tests\": [\"$abs_ark_root" +
269          "$ark_es2panda_root/test/parser/ets/import_tests\"]",
270      "    }",
271      "  }",
272      "}",
273    ]
274    json_relative_path_array = {
275      compilerOptions = {
276        baseUrl = "."
277        paths = {
278          std = [ "../lib/stdlib/std" ]
279          escompat = [ "../lib/stdlib/escompat" ]
280        }
281      }
282    }
283
284    default_arktsconfig =
285        get_label_info("$ark_es2panda_root/aot:ets2panda(${host_toolchain})",
286                       "root_out_dir")
287
288    if (ark_static_standalone_build) {
289      default_arktsconfig += "/bin"
290    } else {
291      default_arktsconfig += "/arkcompiler/ets_frontend"
292    }
293
294    write_file("$root_build_dir/tools/es2panda/generated/arktsconfig.json",
295               json_array,
296               "list lines")
297    write_file("$default_arktsconfig/arktsconfig.json",
298               json_array,
299               "list lines")
300    write_file(
301        "$root_build_dir/ohos-sdk/linux/ets/ets1.2/build-tools/ets2panda/bin/arktsconfig.json",
302        json_relative_path_array,
303        "json")
304    write_file(
305        "$root_build_dir/ohos-sdk/windows/ets/ets1.2/build-tools/ets2panda/bin/arktsconfig.json",
306        json_relative_path_array,
307        "json")
308    if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) {
309      write_file(
310          "$root_build_dir/clang_x64/obj/binarys/arkcompiler/ets_frontend/innerapis/ets2panda/clang_x64/libs/arktsconfig.json",
311          json_array,
312          "list lines")
313    }
314    args = [
315      "--extension=ets",
316      "--opt-level=2",
317      "--gen-stdlib=true",
318      "--output=" + rebase_path(outputs[0], root_build_dir),
319    ]
320  }
321
322  if (is_linux) {
323    copy("etsstdlib_copy_linux") {
324      deps = [ ":etsstdlib" ]
325      if (ark_static_standalone_build) {
326        sources = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ]
327      } else {
328        sources = [ "$target_gen_dir/etsstdlib.abc" ]
329      }
330      outputs = [ "$root_build_dir/ohos-sdk/linux/ets/ets1.2/build-tools/ets2panda/lib/etsstdlib.abc" ]
331    }
332  }
333
334  if (is_win || is_mingw) {
335    copy("etsstdlib_copy_windows") {
336      deps = [ ":etsstdlib" ]
337      if (ark_static_standalone_build) {
338        sources = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ]
339      } else {
340        sources = [ "$target_gen_dir/etsstdlib.abc" ]
341      }
342      outputs = [ "$root_build_dir/ohos-sdk/windows/ets/ets1.2/build-tools/ets2panda/lib/etsstdlib.abc" ]
343    }
344  }
345
346  action("ets-compile-stdlib-default") {
347    # Running ark_aot compilation for etsstdlib with default options
348    script = "$ark_root/plugins/ets/compiler/tools/paoc_compile_stdlib.sh"
349    outputs = [ "$root_build_dir/plugins/ets/etsstdlib.an" ]
350
351    deps = [
352      ":etsstdlib",
353      "$ark_root/compiler/tools/paoc:ark_aot",
354    ]
355
356    args = [
357      "--binary-dir=" + rebase_path(root_build_dir),
358      "-compiler-options=--compiler-check-final=true",
359      "-paoc-output=" + rebase_path(outputs[0], root_build_dir),
360    ]
361  }
362
363  group("ets_func_tests") {
364    deps = [ "tests:ets_func_tests_int_jit_aot" ]
365  }
366
367  if (ark_standalone_build) {
368    testonly = true
369    group("hybrid_tests") {
370      deps = [
371        "$ark_root/tools/ark_js_napi_cli:HybridXGCTests",
372        "tests/interop_js/eacoro:eacoro_tests",
373        "tests/interop_js/taskpool:taskpool_tests",
374        "tests/interop_js/xgc:xgc_tests",
375      ]
376    }
377  }
378}
379
380if (with_sdk) {
381  # Note(ivan-tyulyandin): internal issue #21800
382  assert(false, "Sdk build with gn is not supported!")
383}
384