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 ] 50 _lib_name = invoker.name 51 if (is_debug) { 52 _target_ldflags += [ 53 "-s", 54 "ASSERTIONS=2", 55 "-s", 56 "STACK_OVERFLOW_CHECK=1", 57 "-s", 58 "SAFE_HEAP=1", 59 "-g4", 60 "-O0", 61 ] 62 } else { 63 _target_ldflags += [ 64 "-g2", # Required for getting C++ symbol names. 65 "-O3", 66 "-s", 67 "ASSERTIONS=1", 68 ] 69 } 70 71 _vars_to_forward = [ "deps" ] 72 73 executable("${_lib_name}.js") { 74 ldflags = _target_ldflags 75 output_extension = "" 76 forward_variables_from(invoker, _vars_to_forward) 77 } 78} 79