Gitignore zig crap

This commit is contained in:
2026-05-05 23:15:08 +02:00
parent 823d0ae29b
commit e11ac4b05c
1396 changed files with 613924 additions and 0 deletions

View File

@ -0,0 +1,92 @@
#!/usr/bin/env python3
import argparse
import json
import os
import re
import subprocess
import sys
from collections import OrderedDict
script_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(script_dir)
sys.path.append(root_dir)
import emsdk # noqa
def version_key(version_string):
parts = re.split('[.-]', version_string)
key = [[int(part) for part in parts[:3]], -len(parts), parts[3:]]
return key
def main():
if subprocess.check_output(['git', 'status', '--porcelain'], cwd=root_dir).strip():
print('tree is not clean')
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--release-hash')
parser.add_argument('-a', '--asserts-hash')
parser.add_argument('-v', '--new-version')
parser.add_argument('--gh-action', action='store_true')
options = parser.parse_args()
release_info = emsdk.load_releases_info()
if options.new_version:
new_version = options.new_version
else:
new_version = version_key(release_info['aliases']['latest'])[0]
new_version[-1] += 1
new_version = '.'.join(str(part) for part in new_version)
asserts_hash = None
if options.release_hash:
new_hash = options.release_hash
asserts_hash = options.asserts_hash
else:
new_hash = emsdk.get_emscripten_releases_tot()
print('Creating new release: %s -> %s' % (new_version, new_hash))
release_info['releases'][new_version] = new_hash
if asserts_hash:
asserts_name = new_version + '-asserts'
release_info['releases'][asserts_name] = asserts_hash
releases = [(k, v) for k, v in release_info['releases'].items()]
releases.sort(key=lambda pair: version_key(pair[0]))
release_info['releases'] = OrderedDict(reversed(releases))
release_info['aliases']['latest'] = new_version
with open(os.path.join(root_dir, 'emscripten-releases-tags.json'), 'w') as f:
f.write(json.dumps(release_info, indent=2))
f.write('\n')
subprocess.check_call(
[sys.executable, os.path.join(script_dir, 'update_bazel_workspace.py')],
cwd=root_dir)
branch_name = 'version_' + new_version
if options.gh_action: # For GitHub Actions workflows
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f'RELEASE_VERSION={new_version}')
else: # Local use
# Create a new git branch
subprocess.check_call(['git', 'checkout', '-b', branch_name, 'origin/main'], cwd=root_dir)
# Create auto-generated changes to the new git branch
subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)
subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir)
print('New release created in branch: `%s`' % branch_name)
# Push new branch to origin
subprocess.check_call(['git', 'push', 'origin', branch_name], cwd=root_dir)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
import json
import os
import subprocess
import sys
EMSCRIPTEN_RELEASES_GIT = 'https://chromium.googlesource.com/emscripten-releases'
TAGFILE = 'emscripten-releases-tags.json'
def get_latest_hash(tagfile):
with open(tagfile) as f:
versions = json.load(f)
latest = versions['aliases']['latest']
return versions['releases'][latest]
def get_latest_emscripten(tagfile):
latest = get_latest_hash(tagfile)
if not os.path.isdir('emscripten-releases'):
subprocess.run(['git', 'clone', EMSCRIPTEN_RELEASES_GIT, '--depth',
'100'], check=True)
# This will fail if the 'latest' revision is not within the most recent
# 100 commits; but that shouldn't happen because this script is intended
# to be run right after a release is added.
info = subprocess.run(['emscripten-releases/src/release-info.py',
'emscripten-releases', latest],
stdout=subprocess.PIPE, check=True, text=True).stdout
for line in info.split('\n'):
tokens = line.split()
if len(tokens) and tokens[0] == 'emscripten':
return tokens[2]
if __name__ == '__main__':
emscripten_hash = get_latest_emscripten(TAGFILE)
print('Emscripten revision ' + emscripten_hash)
if 'GITHUB_ENV' in os.environ:
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f'EMSCRIPTEN_HASH={emscripten_hash}')
sys.exit(0)
print('Not a GitHub Action')
sys.exit(1)

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import json
import sys
def get_latest(tagfile):
with open(tagfile) as f:
versions = json.load(f)
print(versions['aliases']['latest'])
return 0
def get_hash(tagfile, version):
with open(tagfile) as f:
versions = json.load(f)
print(versions['releases'][version])
return 0
if __name__ == '__main__':
if sys.argv[2] == 'latest':
sys.exit(get_latest(sys.argv[1]))
if sys.argv[2] == 'hash':
sys.exit(get_hash(sys.argv[1], sys.argv[3]))

View File

@ -0,0 +1,87 @@
#!/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 requests
import sys
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, 'r') 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, 'r') 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(argv):
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(sys.argv))

View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
# Copyright 2020 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.
"""Updates the node binaries that we cache store at
http://storage.google.com/webassembly.
For the windows version we also alter the directory layout to add the 'bin'
directory.
"""
import urllib.request
import subprocess
import sys
import os
import shutil
from zip import unzip_cmd, zip_cmd
version = '20.18.0'
base = 'https://nodejs.org/dist/v20.18.0/'
upload_base = 'gs://webassembly/emscripten-releases-builds/deps/'
suffixes = [
'-win-x86.zip',
'-win-x64.zip',
'-win-arm64.zip',
'-darwin-x64.tar.gz',
'-darwin-arm64.tar.gz',
'-linux-x64.tar.xz',
'-linux-arm64.tar.xz',
'-linux-armv7l.tar.xz',
]
for suffix in suffixes:
filename = 'node-v%s%s' % (version, suffix)
download_url = base + filename
print('Downloading: ' + download_url)
urllib.request.urlretrieve(download_url, filename)
if '-win-' in suffix:
subprocess.check_call(unzip_cmd() + [filename])
dirname = os.path.splitext(os.path.basename(filename))[0]
shutil.move(dirname, 'bin')
os.mkdir(dirname)
shutil.move('bin', dirname)
os.remove(filename)
subprocess.check_call(zip_cmd() + [filename, dirname])
shutil.rmtree(dirname)
if '--upload' in sys.argv:
upload_url = upload_base + filename
print('Uploading: ' + upload_url)
cmd = ['gsutil', 'cp', '-n', filename, upload_url]
print(' '.join(cmd))
subprocess.check_call(cmd)
os.remove(filename)

View File

@ -0,0 +1,175 @@
#!/usr/bin/env python3
# Copyright 2020 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.
"""Updates the python binaries that we cache store at
http://storage.google.com/webassembly.
We only supply binaries for windows and macOS, but we do it very different ways for those two OSes.
Windows recipe:
1. Download the "embeddable zip file" version of python from python.org
2. Remove .pth file to work around https://bugs.python.org/issue34841
3. Download and install pywin32 in the `site-packages` directory
4. Re-zip and upload to storage.google.com
macOS recipe:
1. Clone cpython
2. Use homebrew to install and configure openssl (for static linking!)
3. Build cpython from source and use `make install` to create archive.
"""
import glob
import multiprocessing
import os
import platform
import urllib.request
import shutil
import subprocess
import sys
from subprocess import check_call
from zip import unzip_cmd, zip_cmd
version = '3.9.2'
major_minor_version = '.'.join(version.split('.')[:2]) # e.g. '3.9.2' -> '3.9'
download_url = 'https://www.nuget.org/api/v2/package/python/%s' % version
# This is not part of official Python version, but a repackaging number appended by emsdk
# when a version of Python needs to be redownloaded.
revision = '4'
pywin32_version = '227'
pywin32_base = 'https://github.com/mhammond/pywin32/releases/download/b%s/' % pywin32_version
upload_base = 'gs://webassembly/emscripten-releases-builds/deps/'
def make_python_patch():
pywin32_filename = 'pywin32-%s.win-amd64-py%s.exe' % (pywin32_version, major_minor_version)
filename = 'python-%s-amd64.zip' % (version)
out_filename = 'python-%s-%s-amd64+pywin32.zip' % (version, revision)
if not os.path.exists(pywin32_filename):
url = pywin32_base + pywin32_filename
print('Downloading pywin32: ' + url)
urllib.request.urlretrieve(url, pywin32_filename)
if not os.path.exists(filename):
print(f'Downloading python: {download_url} to {filename}')
urllib.request.urlretrieve(download_url, filename)
os.mkdir('python-nuget')
check_call(unzip_cmd() + [os.path.abspath(filename)], cwd='python-nuget')
os.remove(filename)
os.mkdir('pywin32')
rtn = subprocess.call(unzip_cmd() + [os.path.abspath(pywin32_filename)], cwd='pywin32')
assert rtn in [0, 1]
os.mkdir(os.path.join('python-nuget', 'lib'))
shutil.move(os.path.join('pywin32', 'PLATLIB'), os.path.join('python-nuget', 'toolss', 'Lib', 'site-packages'))
check_call(zip_cmd() + [os.path.join('..', '..', out_filename), '.'], cwd='python-nuget/tools')
print('Created: %s' % out_filename)
# cleanup if everything went fine
shutil.rmtree('python-nuget')
shutil.rmtree('pywin32')
if '--upload' in sys.argv:
upload_url = upload_base + out_filename
print('Uploading: ' + upload_url)
cmd = ['gsutil', 'cp', '-n', out_filename, upload_url]
print(' '.join(cmd))
check_call(cmd)
def build_python():
if sys.platform.startswith('darwin'):
# Take some rather drastic steps to link openssl and liblzma statically
# and avoid linking libintl completely.
osname = 'macos'
check_call(['brew', 'install', 'openssl', 'xz', 'pkg-config'])
if platform.machine() == 'x86_64':
prefix = '/usr/local'
min_macos_version = '10.11'
elif platform.machine() == 'arm64':
prefix = '/opt/homebrew'
min_macos_version = '11.0'
# Append '-x86_64' or '-arm64' depending on current arch. (TODO: Do
# this for Linux too, move this below?)
osname += '-' + platform.machine()
for f in [os.path.join(prefix, 'lib', 'libintl.dylib'),
os.path.join(prefix, 'include', 'libintl.h'),
os.path.join(prefix, 'opt', 'xz', 'lib', 'liblzma.dylib'),
os.path.join(prefix, 'opt', 'openssl', 'lib', 'libssl.dylib'),
os.path.join(prefix, 'opt', 'openssl', 'lib', 'libcrypto.dylib')]:
if os.path.exists(f):
os.remove(f)
os.environ['PKG_CONFIG_PATH'] = os.path.join(prefix, 'opt', 'openssl', 'lib', 'pkgconfig')
else:
osname = 'linux'
src_dir = 'cpython'
if not os.path.exists(src_dir):
check_call(['git', 'clone', 'https://github.com/python/cpython'])
check_call(['git', 'checkout', 'v' + version], cwd=src_dir)
env = os.environ
if sys.platform.startswith('darwin'):
# Specify the min OS version we want the build to work on
min_macos_version_line = '-mmacosx-version-min=' + min_macos_version
build_flags = min_macos_version_line + ' -Werror=partial-availability'
# Build against latest SDK, but issue an error if using any API that would not work on the min OS version
env = env.copy()
env['MACOSX_DEPLOYMENT_TARGET'] = min_macos_version
configure_args = ['CFLAGS=' + build_flags, 'CXXFLAGS=' + build_flags, 'LDFLAGS=' + min_macos_version_line]
else:
configure_args = []
check_call(['./configure'] + configure_args, cwd=src_dir, env=env)
check_call(['make', '-j', str(multiprocessing.cpu_count())], cwd=src_dir, env=env)
check_call(['make', 'install', 'DESTDIR=install'], cwd=src_dir, env=env)
install_dir = os.path.join(src_dir, 'install')
# Install requests module. This is needed in particular on macOS to ensure
# SSL certificates are available (certifi in installed and used by requests).
pybin = os.path.join(src_dir, 'install', 'usr', 'local', 'bin', 'python3')
pip = os.path.join(src_dir, 'install', 'usr', 'local', 'bin', 'pip3')
check_call([pybin, '-m', 'ensurepip', '--upgrade'])
check_call([pybin, pip, 'install', 'requests==2.32.3'])
# Install psutil module. This is needed by emrun to track when browser
# process quits.
check_call([pybin, pip, 'install', 'psutil'])
dirname = 'python-%s-%s' % (version, revision)
if os.path.isdir(dirname):
print('Erasing old build directory ' + dirname)
shutil.rmtree(dirname)
os.rename(os.path.join(install_dir, 'usr', 'local'), dirname)
tarball = 'python-%s-%s-%s.tar.gz' % (version, revision, osname)
shutil.rmtree(os.path.join(dirname, 'lib', 'python' + major_minor_version, 'test'))
shutil.rmtree(os.path.join(dirname, 'include'))
for lib in glob.glob(os.path.join(dirname, 'lib', 'lib*.a')):
os.remove(lib)
check_call(['tar', 'zcvf', tarball, dirname])
print('Created: %s' % tarball)
if '--upload' in sys.argv:
print('Uploading: ' + upload_base + tarball)
check_call(['gsutil', 'cp', '-n', tarball, upload_base + tarball])
def main():
if sys.platform.startswith('win') or '--win32' in sys.argv:
make_python_patch()
else:
build_python()
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -0,0 +1,19 @@
import os
def unzip_cmd():
# Use 7-Zip if available (https://www.7-zip.org/)
sevenzip = os.path.join(os.getenv('ProgramFiles', ''), '7-Zip', '7z.exe')
if os.path.isfile(sevenzip):
return [sevenzip, 'x']
# Fall back to 'unzip' tool
return ['unzip', '-q']
def zip_cmd():
# Use 7-Zip if available (https://www.7-zip.org/)
sevenzip = os.path.join(os.getenv('ProgramFiles', ''), '7-Zip', '7z.exe')
if os.path.isfile(sevenzip):
return [sevenzip, 'a', '-mx9']
# Fall back to 'zip' tool
return ['zip', '-rq']