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