1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# This is the init script that is passed to `emcc --em-config=.emscripten`
16# (Wasm toolchain). It sets vars to locate the various emsdk / llvm dirs.
17
18import os
19import sys
20from platform import system
21
22# We cannot use __file__ here.
23this_file = os.getenv('EM_CONFIG')
24if this_file is None:
25  sys.stderr.write('Could not find EM_CONFIG in .emscripten\n')
26  sys.exit(1)
27
28root_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file)))
29buildools_os = 'mac' if system().lower() == 'darwin' else 'linux64'
30node_path = os.path.join(root_dir, 'buildtools', buildools_os, 'nodejs')
31emsdk_path = os.path.join(root_dir, 'buildtools', buildools_os, 'emsdk')
32
33# Exported vars.
34NODE_JS = os.path.join(node_path, 'bin', 'node')
35LLVM_ROOT = os.path.join(emsdk_path, 'bin')
36BINARYEN_ROOT = emsdk_path
37EMSCRIPTEN_ROOT = os.path.join(emsdk_path, 'emscripten')
38COMPILER_ENGINE = NODE_JS
39JS_ENGINES = [NODE_JS]
40