| #!/usr/bin/env python3 |
| |
| # Copyright 2025 Google LLC |
| # |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import argparse |
| import os |
| import subprocess |
| import sys |
| import sysconfig |
| import textwrap |
| |
| EMSDK_ROOT = os.path.join('third_party', 'emsdk') |
| |
| EMSDK_PATH = os.path.join(EMSDK_ROOT, 'emsdk.py') |
| EMSDK_CONFIG_PATH = os.path.join(EMSDK_ROOT, '.emscripten') |
| |
| EMSDK_VERSION = '4.0.3' |
| |
| def main(args): |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--get-emsdk-version', help='Print emsdk version and exit.', action='store_true') |
| parser.add_argument('--node', help='Path to nodejs binary.') |
| parser.add_argument('--llvm', help='Path to LLVM binaries.') |
| options = parser.parse_args() |
| |
| if options.get_emsdk_version: |
| print(EMSDK_VERSION) |
| return 0 |
| |
| # Install and activate the default dependencies for emsdk. |
| try: |
| subprocess.check_call([sys.executable, EMSDK_PATH, 'install', EMSDK_VERSION]) |
| except subprocess.CalledProcessError: |
| print ('Failed to install emsdk') |
| return 1 |
| try: |
| subprocess.check_call([sys.executable, EMSDK_PATH, 'activate', EMSDK_VERSION]) |
| except subprocess.CalledProcessError: |
| print ('Failed to activate emsdk') |
| return 1 |
| |
| # Append overrides to the default .emscripten file for certain binaries. |
| em_overrides = ''' |
| # Overrides from dawn/tools/activate-emsdk: |
| del PYTHON |
| ''' |
| if options.node: |
| em_overrides += f"NODE_JS = emsdk_path + '/../../{options.node}'\n" |
| if options.llvm: |
| em_overrides += f"LLVM_ROOT = emsdk_path + '/../../{options.llvm}'\n" |
| with open(EMSDK_CONFIG_PATH, 'a') as f: |
| f.write(em_overrides) |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv)) |