Skip to content

Instantly share code, notes, and snippets.

@carlocab
Last active September 17, 2024 10:36
Show Gist options
  • Save carlocab/2db1d7245fa0cd3e92e01fe37b164021 to your computer and use it in GitHub Desktop.
Save carlocab/2db1d7245fa0cd3e92e01fe37b164021 to your computer and use it in GitHub Desktop.
Emscipten Homebrew Formula Update Helper Script
#!/usr/bin/env bash
# Helper script for fetching the required Binaryen and LLVM revisions for the current release of Emscripten in Homebrew/core.
# TODO:
# - print output in a machine-readable format (e.g. JSON)
# - remove dependency on `rg`
# - automate updating `emscripten.rb`
REQUIRED_COMMANDS=(jq curl brew base64 rg python3)
for prog in "${REQUIRED_COMMANDS[@]}"; do
if ! command -v "${prog}" &>/dev/null; then
echo "Error: ${prog} not found. Please install it before using ${0}" >&2
exit 1
fi
done
RELEASE_TAGS_URL=https://raw.githubusercontent.com/emscripten-core/emsdk/main/emscripten-releases-tags.json
JQ=(jq --raw-output)
CURL=(curl --fail --silent --show-error --location)
EMSCRIPTEN_VERSION="$(brew info --json=v2 emscripten | "${JQ[@]}" '.formulae[].versions.stable')"
RELEASE_TAGS_JSON="$("${CURL[@]}" "${RELEASE_TAGS_URL}")"
GOOGLESOURCE_COMMIT_HASH="$("${JQ[@]}" --arg version "${EMSCRIPTEN_VERSION}" ".releases[\$version]" <<<"${RELEASE_TAGS_JSON}")"
GOOGLESOURCE_URL="https://chromium.googlesource.com/emscripten-releases/+/${GOOGLESOURCE_COMMIT_HASH}/DEPS?format=TEXT"
GOOGLESOURCE_DATA="$("${CURL[@]}" "${GOOGLESOURCE_URL}" | base64 --decode | rg --multiline 'vars = \{[^}]+\}')"
echo "Emscripten version: ${EMSCRIPTEN_VERSION}"
python3 <<PYTHON
${GOOGLESOURCE_DATA}
print('Binaryen Revision:', vars['binaryen_revision'])
print('LLVM Revision:', vars['llvm_project_revision'])
PYTHON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment