# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import("./wasm_vars.gni") declare_args() { use_local_emsdk = false } if (!use_local_emsdk) { em_config = rebase_path("//tools/emsdk/.emscripten", "") emsdk_dir = rebase_path("//tools/emsdk/upstream", "") } template("wasm_lib") { _exports = "['ccall', 'callMain', 'addFunction', 'FS']" print(invoker.name) assert(defined(invoker.name)) # If the name is trace_streamer_builtin the target_name must be trace_streamer_builtin_wasm. assert(invoker.name + "_wasm" == target_name) _target_ldflags = [ "-s", "DISABLE_EXCEPTION_CATCHING=1", "-s", "WASM=1", "-s", "NO_DYNAMIC_EXECUTION=1", "-s", "ALLOW_MEMORY_GROWTH=1", "-s", "INITIAL_MEMORY=33554432", "-s", "ALLOW_TABLE_GROWTH=1", "-s", "MEMFS_APPEND_TO_TYPED_ARRAYS=1", "-s", "EXPORTED_RUNTIME_METHODS=" + _exports, "-s", "EXPORT_NAME=${target_name}", "-s", "MODULARIZE=1", "-lworkerfs.js", # For FS.filesystems.WORKERFS "-s", "ASSERTIONS=1", ] if (wasm_use_thread) { _target_ldflags += [ "-s", "USE_PTHREADS=1", "-s", "PTHREAD_POOL_SIZE=6", "-s", "-pthread", ] } else { _target_ldflags += [ "-s", "WASM_ASYNC_COMPILATION=0", ] } _lib_name = invoker.name if (is_debug) { _target_ldflags += [ "-s", "ASSERTIONS=2", "-s", "STACK_OVERFLOW_CHECK=1", "-s", "SAFE_HEAP=1", "-g4", "-O3", ] } else { _target_ldflags += [ # "-g2", # Required for getting C++ symbol names. "-O3", # "-s", # "ASSERTIONS=1", ] } _vars_to_forward = [ "deps" ] executable("${_lib_name}.js") { ldflags = _target_ldflags output_extension = "" forward_variables_from(invoker, _vars_to_forward) } }