• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022-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/ets_frontend/ets_frontend_config.gni")
15
16if ((defined(ark_standalone_build) && ark_standalone_build) || (defined(is_arkui_x) && is_arkui_x)) {
17  import("//arkcompiler/runtime_core/ark_config.gni")
18} else {
19  import("//arkcompiler/ets_frontend/ark_config.gni")
20}
21
22THIRDPARTY_PROTOBUF_SUBSYS_NAME = "thirdparty"
23THIRDPARTY_PROTOBUF_PART_NAME = "protobuf"
24
25proto_base_dir = "protos"
26proto_out_dir = "$target_gen_dir" + "/protos_generated"
27
28protobuf_snapshot_generator_sources = [
29  "src/annotationProto.cpp",
30  "src/assemblyDebugProto.cpp",
31  "src/assemblyFieldProto.cpp",
32  "src/assemblyFileLocationProto.cpp",
33  "src/assemblyFunctionProto.cpp",
34  "src/assemblyInsProto.cpp",
35  "src/assemblyLabelProto.cpp",
36  "src/assemblyLiteralsProto.cpp",
37  "src/assemblyProgramProto.cpp",
38  "src/assemblyRecordProto.cpp",
39  "src/assemblyTypeProto.cpp",
40  "src/ideHelpersProto.cpp",
41  "src/mergeProgram.cpp",
42  "src/metaProto.cpp",
43  "src/protobufSnapshotGenerator.cpp",
44]
45
46config("panda_assembly_proto_public_config") {
47  include_dirs = [
48    "$ark_root/assembler",
49    "$ark_root/libpandabase",
50    "$ark_root/libpandabase/mem",
51    "$ark_root",
52    "src",
53    "$proto_out_dir",
54    "../es2panda",
55    "../es2panda/util",
56  ]
57}
58
59if (ark_standalone_build || is_arkui_x) {
60  assembly_proto_configs = [
61    "$ark_root:ark_config",
62    "$ark_root/assembler:arkassembler_public_config",
63    "$ark_root/libpandafile:arkfile_public_config",
64    "$ark_root/libpandabase:arkbase_public_config",
65  ]
66} else {
67  assembly_proto_configs = [
68    "//arkcompiler/ets_frontend:ark_config"
69  ]
70}
71
72assembly_proto_configs += [
73  ":panda_assembly_proto_public_config",
74]
75
76if (defined(is_arkui_x) && is_arkui_x) {
77  assembly_proto_configs += [ sdk_libc_secshared_config ]
78}
79
80proto_file_defines = [
81  # add your proto file here
82  "annotation",
83  "assemblyDebug",
84  "assemblyField",
85  "assemblyFileLocation",
86  "assemblyFunction",
87  "assemblyIns",
88  "assemblyLabel",
89  "assemblyLiterals",
90  "assemblyProgram",
91  "assemblyRecord",
92  "assemblyType",
93  "compositeProgram",
94  "ideHelpers",
95  "meta",
96]
97
98proto_file_sources = []
99proto_generated_header = []
100proto_generated_source = []
101
102foreach(proto_file, proto_file_defines) {
103  proto_generated_header += [ "$proto_out_dir" + "/" + "$proto_file.pb.h" ]
104  proto_generated_source += [ "$proto_out_dir" + "/" + "$proto_file.pb.cc" ]
105  proto_file_sources += [ "$proto_base_dir" + "/" + "$proto_file.proto" ]
106}
107
108protoc_binary_out_path =
109    "${THIRDPARTY_PROTOBUF_SUBSYS_NAME}/${THIRDPARTY_PROTOBUF_PART_NAME}"
110
111if (!ark_standalone_build && defined(ohos_indep_compiler_enable) &&
112    !ohos_indep_compiler_enable) {
113  if (default_toolchain == current_toolchain) {
114    #if target build
115    host_out_path = "/" + get_label_info(host_toolchain, "name")
116  } else {
117    #if host build (for some linke mingw)
118    host_out_path = "/../" + get_label_info(host_toolchain, "name")
119  }
120
121  host_protoc_path =
122      root_out_dir + host_out_path + "/" + protoc_binary_out_path + "/protoc"
123} else if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) {
124  not_needed([ "protoc_binary_out_path" ])
125  host_protoc_path = rebase_path(
126          "//binarys/third_party/protobuf/innerapis/protoc/clang_x64/libs/protoc")
127} else {
128  host_protoc_path =
129      get_label_info(
130          "${ets_frontend_root}/merge_abc:merge_abc(${host_toolchain})",
131          "root_out_dir") + "/" + protoc_binary_out_path + "/protoc"
132}
133
134action("arkcompiler_generate_proto") {
135  if (ark_standalone_build) {
136    deps = [ "$ark_third_party_root/protobuf:protoc($host_toolchain)" ]
137  } else {
138    external_deps = [ "protobuf:protoc($host_toolchain)" ]
139  }
140  args = []
141  sources = []
142  outputs = proto_generated_header + proto_generated_source
143  script = "./script/build_proto.sh"
144
145  args += [ rebase_path(host_protoc_path) ]
146  args += [
147    "--proto_path",
148    rebase_path(proto_base_dir),
149    "--cpp_out",
150    rebase_path(proto_out_dir),
151    "--experimental_allow_proto3_optional",
152  ]
153
154  foreach(proto_file_source, proto_file_sources) {
155    #tell gn to check which files as source time
156    sources += [ rebase_path(proto_file_source) ]
157    args += [ rebase_path(proto_file_source) ]
158  }
159}
160
161config("proto_file_cpp_config") {
162  include_dirs = [ proto_out_dir ]
163}
164
165ohos_source_set("assembly_proto_static") {
166  cflags = [ "-Wno-error=zero-length-array" ]
167
168  deps = [ ":arkcompiler_generate_proto" ]
169
170  external_deps = []
171  if (!is_arkui_x) {
172    external_deps += [
173      "protobuf:protobuf_lite_static",
174      "protobuf:protobuf_static",
175      "runtime_core:libarkassembler_frontend_static",
176      "runtime_core:libarkbase_frontend_static",
177      "runtime_core:libarkfile_frontend_static",
178      sdk_libc_secshared_dep,
179    ]
180  } else {
181    deps += [
182      "$ark_root/assembler:libarkassembler_frontend_static",
183      "$ark_root/libpandabase:libarkbase_frontend_static",
184      "$ark_root/libpandafile:libarkfile_frontend_static",
185      "$ark_third_party_root/protobuf:protobuf_lite_static",
186      "$ark_third_party_root/protobuf:protobuf_static",
187    ]
188  }
189
190  if (!ark_standalone_build && !is_arkui_x) {
191    external_deps += [
192      "runtime_core:arkassembler_public_headers",
193      "runtime_core:arkbase_public_headers",
194      "runtime_core:arkfile_public_headers",
195    ]
196    if (enable_hilog) {
197      external_deps += [ "hilog:libhilog" ]
198    }
199  }
200
201  if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) {
202    external_deps += [
203      "abseil-cpp:absl_base_static",
204      "runtime_core:libarkassembler_static",
205    ]
206  }
207
208  sources = proto_generated_header + proto_generated_source +
209            protobuf_snapshot_generator_sources
210  public_configs = assembly_proto_configs
211  public_configs += [ ":proto_file_cpp_config" ]
212
213  part_name = "ets_frontend"
214  subsystem_name = "arkcompiler"
215}
216
217ohos_static_library("panda_assembly_proto_static") {
218  deps = [ ":assembly_proto_static" ]
219  if (!ark_standalone_build) {
220    public_external_deps = [
221      "protobuf:protobuf_lite_static",
222      "protobuf:protobuf_static",
223    ]
224  } else {
225    external_deps = [
226      "protobuf:protobuf_lite_static",
227      "protobuf:protobuf_static",
228    ]
229  }
230  part_name = "ets_frontend"
231  subsystem_name = "arkcompiler"
232}
233
234ohos_executable("merge_abc") {
235  use_exceptions = true
236  sources = [
237    "src/main.cpp",
238    "src/options.cpp",
239  ]
240
241  include_dirs = [ "./src" ]
242
243  external_deps = []
244
245  if (ark_standalone_build || is_arkui_x) {
246    configs = [
247      "$ark_root:ark_config",
248      "$ark_root/assembler:arkassembler_public_config",
249      "$ark_root/libpandafile:arkfile_public_config",
250      "$ark_root/libpandabase:arkbase_public_config",
251    ]
252  } else {
253    configs = [ "//arkcompiler/ets_frontend:ark_config" ]
254    external_deps += [
255      "runtime_core:arkassembler_public_headers",
256      "runtime_core:arkbase_public_headers",
257      "runtime_core:arkfile_public_headers",
258    ]
259  }
260
261  configs += [
262    ":panda_assembly_proto_public_config",
263    ":proto_file_cpp_config",
264  ]
265
266  deps = [
267    ":panda_assembly_proto_static",
268    "../es2panda:es2panda_lib",
269  ]
270  external_deps += [
271    "icu:static_icuuc",
272    sdk_libc_secshared_dep,
273  ]
274  if (!is_arkui_x) {
275    external_deps += [ "runtime_core:libarkziparchive_frontend_static" ]
276  } else {
277    deps += [ "$ark_root/libziparchive:libarkziparchive_frontend_static" ]
278  }
279  if (ark_standalone_build) {
280    external_deps += [
281      "protobuf:protobuf_lite_static",
282      "protobuf:protobuf_static",
283    ]
284  }
285  ldflags = []
286  if (is_linux) {
287    if (build_public_version) {
288      ldflags += [ "-static-libstdc++" ]
289    } else {
290      libs = [ libcpp_static_lib ]
291    }
292
293    defines = [ "PANDA_TARGET_LINUX" ]
294  } else if (is_mac) {
295    defines = [ "PANDA_TARGET_MACOS" ]
296  } else if (is_mingw) {
297    defines = [ "PANDA_TARGET_WINDOWS" ]
298  }
299
300  if (!use_musl) {
301    ldflags += [ "-lc++" ]
302  }
303
304  output_name = "merge_abc"
305  install_enable = false
306  part_name = "ets_frontend"
307  subsystem_name = "arkcompiler"
308}
309
310if (is_linux) {
311  ohos_copy("merge_abc_build") {
312    deps = [ ":merge_abc" ]
313    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc" ]
314    outputs = [ "${target_out_dir}/merge_abc-tmp" ]
315    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
316    module_install_name = "merge_abc"
317  }
318
319  ohos_copy("merge_abc_build_ets") {
320    deps = [ ":merge_abc" ]
321    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc" ]
322    outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc-ets" ]
323    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
324    module_install_name = "merge_abc"
325  }
326}
327
328if (is_mingw) {
329  ohos_copy("merge_abc_build_win") {
330    deps = [ ":merge_abc" ]
331    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc.exe" ]
332    outputs = [ "${target_out_dir}/merge_abc-tmp" ]
333    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
334    module_install_name = "merge_abc.exe"
335  }
336
337  ohos_copy("merge_abc_build_win_ets") {
338    deps = [ ":merge_abc" ]
339    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc.exe" ]
340    outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc-win-ets" ]
341    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
342    module_install_name = "merge_abc.exe"
343  }
344}
345
346if (is_mac) {
347  ohos_copy("merge_abc_build_mac") {
348    deps = [ ":merge_abc" ]
349    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc" ]
350    outputs = [ "${target_out_dir}/merge_abc-tmp" ]
351    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
352    module_install_name = "merge_abc"
353  }
354
355  ohos_copy("merge_abc_build_mac_ets") {
356    deps = [ ":merge_abc" ]
357    sources = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc" ]
358    outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/merge_abc-mac-ets" ]
359    module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend"
360    module_install_name = "merge_abc"
361  }
362}
363
364group("merge_proto_abc_build") {
365  if (host_os == "linux") {
366    deps = [ ":merge_abc(${toolchain_linux})" ]
367  }
368
369  if (host_os == "mac") {
370    deps = [ ":merge_abc(${toolchain_mac})" ]
371  }
372}
373
374group("merge_proto_abc_build_win") {
375  deps = [ ":merge_abc(${toolchain_win})" ]
376}
377