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