• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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("./wasm_vars.gni")
15
16em_config = rebase_path(".emscripten", "")
17emsdk_dir = rebase_path("//prebuilts/emsdk/emsdk", "")
18
19template("wasm_lib") {
20  _exports = "['ccall', 'callMain', 'addFunction', 'FS']"
21  print(invoker.name)
22  assert(defined(invoker.name))
23
24  # If the name is trace_sreamer the target_name must be trace_sreamer_wasm.
25  assert(invoker.name + "_wasm" == target_name)
26  _target_ldflags = [
27    "-s",
28    "DISABLE_EXCEPTION_CATCHING=1",
29    "-s",
30    "WASM=1",
31    "-s",
32    "NO_DYNAMIC_EXECUTION=1",
33    "-s",
34    "ALLOW_MEMORY_GROWTH=1",
35    "-s",
36    "INITIAL_MEMORY=33554432",
37    "-s",
38    "ALLOW_TABLE_GROWTH=1",
39    "-s",
40    "MEMFS_APPEND_TO_TYPED_ARRAYS=1",
41    "-s",
42    "WASM_ASYNC_COMPILATION=0",
43    "-s",
44    "EXPORTED_RUNTIME_METHODS=" + _exports,
45    "-s",
46    "EXPORT_NAME=${target_name}",
47    "-s",
48    "MODULARIZE=1",
49    "-lworkerfs.js",  # For FS.filesystems.WORKERFS
50  ]
51  _lib_name = invoker.name
52  if (is_debug) {
53    _target_ldflags += [
54      "-s",
55      "ASSERTIONS=2",
56      "-s",
57      "STACK_OVERFLOW_CHECK=1",
58      "-s",
59      "SAFE_HEAP=1",
60      "-g4",
61      "-O0",
62    ]
63  } else {
64    _target_ldflags += [
65      #      "-g2",  # Required for getting C++ symbol names.
66      "-O3",
67      #  "-s",
68      #  "ASSERTIONS=1",
69    ]
70  }
71
72  _vars_to_forward = [ "deps" ]
73
74  executable("${_lib_name}.js") {
75    ldflags = _target_ldflags
76    output_extension = ""
77    forward_variables_from(invoker, _vars_to_forward)
78  }
79}
80