• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 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
14if ((defined(ark_standalone_build) && ark_standalone_build) ||
15    (defined(ark_static_standalone_build) && ark_static_standalone_build)) {
16  import("//arkcompiler/runtime_core/static_core/ark_config.gni")
17} else {
18  import(
19      "//build/config/components/runtime_core/static_core/ark_common_config.gni")
20}
21
22if (ark_standalone_build) {
23  import("$build_root/ark.gni")
24} else {
25  import("//build/ohos.gni")
26}
27
28npm_path = "//prebuilts/build-tools/common/nodejs/current/bin/npm"
29
30shared_library("ts_bindings") {
31  sources = [
32    "./native/src/callback-resource.cpp",
33    "./native/src/common-interop.cpp",
34    "./native/src/convertors-napi.cpp",
35    "./native/src/lsp.cpp",
36  ]
37  if ((defined(ark_standalone_build) && ark_standalone_build) ||
38      (defined(ark_static_standalone_build) && ark_static_standalone_build)) {
39    configs += [ "$ark_root:ark_config" ]
40  } else {
41    configs += [
42      "//build/config/components/runtime_core/static_core:ark_common_config",
43    ]
44  }
45  configs += [
46    "$ark_root/assembler:arkassembler_public_config",
47    "../:libes2panda_public_config",
48    "../:libes2panda_config",
49    "$ark_root/libpandabase:arkbase_public_config",
50    "$ark_root/libpandafile:arkfile_public_config",
51  ]
52
53  deps = [
54    "../:libes2panda_frontend_static",
55    "../:libes2panda_public_frontend_static",
56    "../lsp:libes2panda_lsp_static",
57  ]
58
59  include_dirs = [
60    "./native/include",
61    "../public/",
62    "//third_party/node/src",
63    rebase_path("$root_gen_dir/arkcompiler/ets_frontend/ets2panda/"),
64  ]
65
66  if (ark_standalone_build) {
67    deps += [
68      "$ark_root/bytecode_optimizer:libarktsbytecodeopt_package",
69      "$ark_third_party_root/bounds_checking_function:libsec_shared",
70    ]
71    include_dirs += [ "//third_party/node/src" ]
72  } else {
73    external_deps = [
74      "runtime_core:libarktsbytecodeopt_package",
75      sdk_libc_secshared_dep,
76    ]
77  }
78
79  defines = [
80    "TS_INTEROP_MODULE=NativeModule",
81    "INTEROP_LIBRARY_NAME=ts_bindings",
82    "TS_USE_NODE_VM",
83    "TS_NAPI",
84  ]
85  if (ark_standalone_build) {
86    configs -= [ "$build_root/config/compiler:compiler" ]
87  } else {
88    configs -= [ "//build/config/compiler:compiler" ]
89  }
90
91  if (is_linux) {
92    libs = [ "stdc++fs" ]
93    cflags_cc = [
94      "-std=c++17",
95      "-Wall",
96      "-Werror",
97      "-Wno-unused-variable",
98      "-fPIC",
99    ]
100
101    ldflags = [
102      "-Wl,--allow-shlib-undefined",
103      "-Wl,--fatal-warnings",
104      "-Wl,--build-id=md5",
105      "-fPIC",
106      "-Wl,-z,noexecstack",
107      "-Wl,-z,now",
108      "-Wl,-z,relro",
109      "-Wl,--as-needed",
110      "-fuse-ld=lld",
111      "-Wl,--icf=all",
112      "-Wl,--color-diagnostics",
113      "-m64",
114    ]
115    output_extension = "node"
116    output_prefix_override = true
117  } else if (is_mingw) {
118    output_extension = "dll"
119    cflags_cc = [
120      "-std=c++17",
121      "-Wall",
122      "-Werror",
123      "-Wno-unused-variable",
124      "-fPIC",
125      "-Wno-error=deprecated-copy",
126      "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
127      "-ftrivial-auto-var-init=zero",
128      "-fcolor-diagnostics",
129      "-fmerge-all-constants",
130      "-Xclang",
131      "-mllvm",
132      "-Xclang",
133      "-instcombine-lower-dbg-declare=0",
134      "-no-canonical-prefixes",
135      "-static",
136      "-rtlib=compiler-rt",
137      "-stdlib=libc++",
138      "-lunwind",
139      "-lpthread",
140      "-Qunused-arguments",
141      "-fuse-ld=lld",
142      "-fno-stack-protector",
143      "-fno-strict-aliasing",
144      "-Wno-builtin-macro-redefined",
145      "-fms-extensions",
146      "-static",
147      "-rtlib=compiler-rt",
148      "-stdlib=libc++",
149      "-std=c++17",
150      "-lunwind",
151      "-lpthread",
152      "-Qunused-arguments",
153      "-target",
154      "x86_64-pc-windows-gnu",
155      "-D__CUSTOM_SECURITY_LIBRARY",
156    ]
157
158    ldflags = [
159      "-Wl,--fatal-warnings",
160      "-fPIC",
161      "-Wl,--as-needed",
162      "-fuse-ld=lld",
163      "-Wl,--icf=all",
164      "-m64",
165      "-static",
166      "-rtlib=compiler-rt",
167      "-stdlib=libc++",
168      "-std=c++17",
169      "-lunwind",
170      "-lpthread",
171      "-Qunused-arguments",
172      "-target",
173      "x86_64-pc-windows-gnu",
174    ]
175    sources += [ "./native/src/win-dynamic-node.cpp" ]
176  } else if (is_mac) {
177    cflags_cc = [
178      "-std=c++17",
179      "-Wall",
180      "-Werror",
181      "-Wno-unused-variable",
182      "-fPIC",
183    ]
184
185    ldflags = [
186      "-fPIC",
187      "-fuse-ld=lld",
188      "-Wl,--icf=all",
189      "-Wl,--color-diagnostics",
190      "-m64",
191      "-Wl,-undefined,dynamic_lookup",
192    ]
193    output_extension = "node"
194    output_prefix_override = true
195  }
196}
197
198shared_library("public") {
199  sources = [
200    "./native/src/bridges.cpp",
201    "./native/src/callback-resource.cpp",
202    "./native/src/common-interop.cpp",
203    "./native/src/common.cpp",
204    "./native/src/convertors-napi.cpp",
205  ]
206
207  configs += [
208    "$ark_root/assembler:arkassembler_public_config",
209    "../:libes2panda_public_config",
210    "../:libes2panda_config",
211    "$ark_root/libpandabase:arkbase_public_config",
212    "$ark_root/libpandafile:arkfile_public_config",
213  ]
214
215  include_dirs = [
216    "./native/include",
217    "../public/",
218    "//third_party/node/src",
219    rebase_path("$root_gen_dir/arkcompiler/ets_frontend/ets2panda/"),
220  ]
221
222  if (!is_mac) {
223    deps = [ "../aot:ets2panda" ]
224  }
225
226  if (ark_standalone_build) {
227    deps += [ "$ark_third_party_root/bounds_checking_function:libsec_shared" ]
228  } else {
229    external_deps = [ sdk_libc_secshared_dep ]
230  }
231
232  defines = [
233    "TS_INTEROP_MODULE=NativeModule",
234    "INTEROP_LIBRARY_NAME=ts_bindings",
235    "TS_USE_NODE_VM",
236    "TS_NAPI",
237  ]
238  if (ark_standalone_build) {
239    configs -= [ "$build_root/config/compiler:compiler" ]
240  } else {
241    configs -= [ "//build/config/compiler:compiler" ]
242  }
243
244  if (is_linux) {
245    cflags_cc = [
246      "-std=c++17",
247      "-Wall",
248      "-Werror",
249      "-Wno-unused-variable",
250      "-fPIC",
251    ]
252
253    ldflags = [
254      "-Wl,--allow-shlib-undefined",
255      "-Wl,--fatal-warnings",
256      "-Wl,--build-id=md5",
257      "-fPIC",
258      "-Wl,-z,noexecstack",
259      "-Wl,-z,now",
260      "-Wl,-z,relro",
261      "-Wl,--as-needed",
262      "-fuse-ld=lld",
263      "-Wl,--icf=all",
264      "-Wl,--color-diagnostics",
265      "-m64",
266    ]
267    output_extension = "node"
268    output_prefix_override = true
269  } else if (is_mingw) {
270    output_extension = "dll"
271    cflags_cc = [
272      "-std=c++17",
273      "-Wall",
274      "-Werror",
275      "-Wno-unused-variable",
276      "-fPIC",
277      "-Wno-error=deprecated-copy",
278      "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
279      "-ftrivial-auto-var-init=zero",
280      "-fcolor-diagnostics",
281      "-fmerge-all-constants",
282      "-Xclang",
283      "-mllvm",
284      "-Xclang",
285      "-instcombine-lower-dbg-declare=0",
286      "-no-canonical-prefixes",
287      "-static",
288      "-rtlib=compiler-rt",
289      "-stdlib=libc++",
290      "-lunwind",
291      "-lpthread",
292      "-Qunused-arguments",
293      "-fuse-ld=lld",
294      "-fno-stack-protector",
295      "-fno-strict-aliasing",
296      "-Wno-builtin-macro-redefined",
297      "-fms-extensions",
298      "-static",
299      "-rtlib=compiler-rt",
300      "-stdlib=libc++",
301      "-std=c++17",
302      "-lunwind",
303      "-lpthread",
304      "-Qunused-arguments",
305      "-target",
306      "x86_64-pc-windows-gnu",
307      "-D__CUSTOM_SECURITY_LIBRARY",
308    ]
309
310    ldflags = [
311      "-Wl,--fatal-warnings",
312      "-fPIC",
313      "-Wl,--as-needed",
314      "-fuse-ld=lld",
315      "-Wl,--icf=all",
316      "-m64",
317      "-static",
318      "-rtlib=compiler-rt",
319      "-stdlib=libc++",
320      "-std=c++17",
321      "-lunwind",
322      "-lpthread",
323      "-Qunused-arguments",
324      "-target",
325      "x86_64-pc-windows-gnu",
326    ]
327    sources += [ "./native/src/win-dynamic-node.cpp" ]
328  } else if (is_mac) {
329    cflags_cc = [
330      "-std=c++17",
331      "-Wall",
332      "-Werror",
333      "-Wno-unused-variable",
334      "-fPIC",
335    ]
336
337    ldflags = [
338      "-fPIC",
339      "-fuse-ld=lld",
340      "-Wl,--icf=all",
341      "-Wl,--color-diagnostics",
342      "-m64",
343      "-Wl,-undefined,dynamic_lookup",
344    ]
345    output_extension = "node"
346    output_prefix_override = true
347  }
348}
349
350action("build_bindings") {
351  deps = [
352    ":public",
353    ":ts_bindings",
354  ]
355  sources = [
356    "./src/Es2pandaNativeModule.ts",
357    "./src/InteropNativeModule.ts",
358    "./src/InteropTypes.ts",
359    "./src/Platform.ts",
360    "./src/Wrapper.ts",
361    "./src/arrays.ts",
362    "./src/generated/Es2pandaEnums.ts",
363    "./src/generated/Es2pandaNativeModule.ts",
364    "./src/global.ts",
365    "./src/index.ts",
366    "./src/loadLibraries.ts",
367    "./src/lspNode.ts",
368    "./src/mainWrapper.ts",
369    "./src/private.ts",
370    "./src/strings.ts",
371    "./src/ts-reflection.ts",
372    "./src/types.ts",
373    "./src/utils.ts",
374  ]
375  script = "build_bindings.py"
376
377  args = [
378    "--source-path",
379    rebase_path(get_path_info(".", "abspath")),
380    "--output-path",
381    rebase_path("$target_gen_dir"),
382    "--npm",
383    rebase_path(npm_path),
384    "--current-os",
385    "$current_os",
386    "--root-out-dir",
387    rebase_path(root_out_dir),
388  ]
389
390  outputs = [ "$target_gen_dir" ]
391}
392
393ohos_copy("ets2panda_build_bindings") {
394  deps = [ ":build_bindings" ]
395  sources = [ rebase_path("$target_gen_dir") ]
396  outputs = [ target_out_dir + "/$target_name" ]
397  module_source_dir = target_out_dir + "/$target_name"
398  module_install_name = ""
399  part_name = "ets_frontend"
400  subsystem_name = "arkcompiler"
401}
402