Skip to content

Commit

Permalink
chore(common): allow build agents to automatically select emsdk version
Browse files Browse the repository at this point in the history
The build agents will now automatically install and activate the
Emscripten version found in minimum-versions.inc.sh when configuring
WASM projects. For developer machines, this behaviour can be enabled by
setting the environment variable `KEYMAN_USE_EMSDK` (recommended).

This will be back-ported to 17.0 so that we can ensure that all builds
use a consistent Emscripten version.
  • Loading branch information
mcdurdin committed Aug 21, 2024
1 parent a0ebe13 commit b0bd95d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 1 addition & 2 deletions resources/build/minimum-versions.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ KEYMAN_MIN_TARGET_VERSION_CHROME=95.0 # Final version that runs on Andro
# Dependency versions
KEYMAN_MIN_VERSION_NODE_MAJOR=20 # node version source of truth is /package.json:/engines/node
KEYMAN_MIN_VERSION_NPM=10.5.1 # 10.5.0 has bug, discussed in #10350
KEYMAN_MIN_VERSION_EMSCRIPTEN=3.1.44 # Warning: 3.1.45 is bad (#9529); newer versions work
KEYMAN_MAX_VERSION_EMSCRIPTEN=3.1.58 # See #9529
KEYMAN_MIN_VERSION_EMSCRIPTEN=3.1.58 # Use KEYMAN_USE_EMSDK to automatically update to this version
KEYMAN_MIN_VERSION_VISUAL_STUDIO=2019
KEYMAN_MIN_VERSION_MESON=1.0.0

Expand Down
36 changes: 36 additions & 0 deletions resources/locate_emscripten.inc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# shellcheck shell=bash
# no hashbang for .inc.sh

. "$KEYMAN_ROOT/resources/build/minimum-versions.inc.sh"

#
# We don't want to rely on emcc being on the path, because Emscripten puts far
# too many things onto the path (in particular for us, node).
Expand Down Expand Up @@ -34,4 +36,38 @@ locate_emscripten() {
fi
[[ -f ${EMSCRIPTEN_BASE}/${EMCC_EXECUTABLE} && ! -x ${EMSCRIPTEN_BASE}/${EMCC_EXECUTABLE} ]] && builder_die "locate_emscripten: Variable EMSCRIPTEN_BASE ($EMSCRIPTEN_BASE) contains ${EMCC_EXECUTABLE} but it is not executable"
[[ -x ${EMSCRIPTEN_BASE}/${EMCC_EXECUTABLE} ]] || builder_die "locate_emscripten: Variable EMSCRIPTEN_BASE ($EMSCRIPTEN_BASE) does not point to ${EMCC_EXECUTABLE}'s folder"

verify_emscripten_version
}

# Ensure that we use correct version of emsdk on build agents.
# For developers, define KEYMAN_USE_SDK to do this on your
# build machine.
verify_emscripten_version() {
if [[ "$VERSION_ENVIRONMENT" != local || ! -z "${KEYMAN_USE_EMSDK+x}" ]]; then
_select_emscripten_version_with_emsdk
fi
}

# Use emsdk to select the appropriate version of Emscripten
# according to minimum-versions.inc.sh
_select_emscripten_version_with_emsdk() {
if [[ -z "${EMSCRIPTEN_BASE+x}" ]]; then
builder_die "Variable EMSCRIPTEN_BASE must be set"
fi

if [[ -z "${KEYMAN_MIN_VERSION_EMSCRIPTEN+x}" ]]; then
builder_die "Variable KEYMAN_MIN_VERSION_EMSCRIPTEN must be set"
fi

pushd "${EMSCRIPTEN_BASE}/../.." > /dev/null
if [[ ! -f emsdk ]]; then
builder_die "emsdk[.bat] should be in $(pwd)"
fi

export EMSDK_KEEP_DOWNLOADS=1
git pull
./emsdk install "$KEYMAN_MIN_VERSION_EMSCRIPTEN"
./emsdk activate "$KEYMAN_MIN_VERSION_EMSCRIPTEN"
popd > /dev/null
}

0 comments on commit b0bd95d

Please sign in to comment.