view third_party/emsdk/scripts/update_bazel_workspace.py @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents 8d17f6e6e290
children
line wrap: on
line source

#!/usr/bin/env python3
# This script will update emsdk/bazel/revisions.bzl to the latest version of
# emscripten. It reads emsdk/emscripten-releases-tags.json to get the latest
# version number. Then, it downloads the prebuilts for that version and computes
# the sha256sum for the archive. It then puts all this information into the
# emsdk/bazel/revisions.bzl file.

import hashlib
import json
import os
import re
import sys

import requests

STORAGE_URL = 'https://storage.googleapis.com/webassembly/emscripten-releases-builds'

EMSDK_ROOT = os.path.dirname(os.path.dirname(__file__))
RELEASES_TAGS_FILE = EMSDK_ROOT + '/emscripten-releases-tags.json'
BAZEL_REVISIONS_FILE = EMSDK_ROOT + '/bazel/revisions.bzl'
BAZEL_MODULE_FILE = EMSDK_ROOT + '/bazel/MODULE.bazel'


def get_latest_info():
    with open(RELEASES_TAGS_FILE) as f:
        info = json.load(f)
    latest = info['aliases']['latest']
    return latest, info['releases'][latest]


def get_sha(platform, archive_fmt, latest_hash, arch_suffix=''):
    r = requests.get(f'{STORAGE_URL}/{platform}/{latest_hash}/wasm-binaries{arch_suffix}.{archive_fmt}')
    r.raise_for_status()
    print(f'Fetching {r.url}')
    h = hashlib.new('sha256')
    for chunk in r.iter_content(chunk_size=1024):
        h.update(chunk)
    return h.hexdigest()


def revisions_item(version, latest_hash):
    return f'''\
    "{version}": struct(
        hash = "{latest_hash}",
        sha_linux = "{get_sha('linux', 'tar.xz', latest_hash)}",
        sha_linux_arm64 = "{get_sha('linux', 'tar.xz', latest_hash, '-arm64')}",
        sha_mac = "{get_sha('mac', 'tar.xz', latest_hash)}",
        sha_mac_arm64 = "{get_sha('mac', 'tar.xz', latest_hash, '-arm64')}",
        sha_win = "{get_sha('win', 'zip', latest_hash)}",
    ),
'''


def insert_revision(item):
    with open(BAZEL_REVISIONS_FILE) as f:
        lines = f.readlines()

    lines.insert(lines.index('EMSCRIPTEN_TAGS = {\n') + 1, item)

    with open(BAZEL_REVISIONS_FILE, 'w') as f:
        f.write(''.join(lines))


def update_module_version(version):
    with open(BAZEL_MODULE_FILE) as f:
        content = f.read()

    pattern = r'(module\(\s*name = "emsdk",\s*version = )"\d+.\d+.\d+",\n\)'
    # Verify that the pattern exists in the input since re.sub will
    # will succeed either way.
    assert re.search(pattern, content)
    content = re.sub(pattern, fr'\1"{version}",\n)', content)

    with open(BAZEL_MODULE_FILE, 'w') as f:
        f.write(content)


def main():
    version, latest_hash = get_latest_info()
    update_module_version(version)
    item = revisions_item(version, latest_hash)
    print('inserting item:')
    print(item)
    insert_revision(item)


if __name__ == '__main__':
    sys.exit(main())