Skip to content

Commit

Permalink
Merge pull request #2256 from tomjakubowski/chore/check-emsdk
Browse files Browse the repository at this point in the history
Validate installed emsdk version
  • Loading branch information
texodus authored Jun 15, 2023
2 parents 30560d4 + f68a9cf commit 0dd3111
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
25 changes: 12 additions & 13 deletions scripts/install_emsdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,25 @@ function emsdk(...args) {
execute_throw`${emsdk} ${args.join(" ")}`;
}

function upgrade() {
console.log(`-- Emscripten not found, installing ${emscripten}`);
emsdk_checkout();
function toolchain_install() {
console.log(`-- Installing Emscripten ${emscripten}`);
emsdk("install", emscripten);
emsdk("activate", emscripten);
console.log(`-- Emscripten ${emscripten} installed`);
}

function check() {
try {
const emsdkdir = path.join(__dirname, "..", ".emsdk");
execute_throw`cd ${emsdkdir} && . ${emsdkdir}/emsdk_env.sh && emcc --version`;
return true;
} catch (e) {
return fs.existsSync(path.join(__dirname, "..", ".emsdk"));
}
function repo_check() {
return fs.existsSync(path.join(base(), "emsdk_env.sh"));
}

if (!process.env.PSP_SKIP_EMSDK_INSTALL) {
if (!check()) {
upgrade();
// if a stale toolchain is still activated in the shell, these vars break
// emsdk install in a confusing way. ensure they are unset
for (let ev of ["EMSDK", "EMSDK_NODE", "EMSDK_PYTHON", "SSL_CERT_FILE"]) {
delete process.env[ev];
}
if (!repo_check()) {
emsdk_checkout();
}
toolchain_install();
}
10 changes: 9 additions & 1 deletion scripts/run_emsdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ try {
const cwd = process.cwd();
const cmd = process.argv.slice(2).join(" ");
const emsdkdir = path.join(__dirname, "..", ".emsdk");
execute_throw`cd ${emsdkdir} && . ./emsdk_env.sh >/dev/null 2>&1 && cd ${cwd} && ${cmd}`;
const emversion = require(path.join(
__dirname,
"..",
"package.json"
)).emscripten;
if (!emversion) {
throw new Error("Emscripten version not specified in package.json");
}
execute_throw`cd ${emsdkdir} && . ./emsdk_env.sh >/dev/null 2>&1 && emsdk activate ${emversion} >/dev/null && cd ${cwd} && ${cmd}`;
} catch (e) {
console.log(e.message);
process.exit(1);
Expand Down

0 comments on commit 0dd3111

Please sign in to comment.