Skip to content

Commit

Permalink
feat: Install embedded emscripten version for Unix based OSes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Aug 14, 2020
1 parent f4bb304 commit 7c3c484
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/Uno.Wasm.Bootstrap/ShellTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,28 +843,30 @@ private string ValidateEmscripten()

throw new InvalidOperationException($"Failed to setup WSL environment.");
}
else
else if (Environment.OSVersion.Platform == PlatformID.Unix)
{
var emsdkPath = Environment.GetEnvironmentVariable("EMSDK");
if (string.IsNullOrEmpty(emsdkPath))
{
throw new InvalidOperationException($"The EMSDK environment variable must be defined. See http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#installation-instructions");
}
var home = Environment.GetEnvironmentVariable("HOME");
var emsdkHostFolder = Environment.GetEnvironmentVariable("WASMSHELL_WSLEMSDK") ?? $"{home}/.uno/emsdk";
var emscriptenSetupScript = Path.Combine(BuildTaskBasePath, "scripts", "emscripten-setup.sh");
var emsdkBaseFolder = emsdkHostFolder + $"/emsdk-{Constants.EmscriptenMinVersion}";

// Get the version file https://github.com/emscripten-core/emsdk/blob/efc64876db1473312587a3f346be000a733bc16d/emsdk.py#L1698
var emsdkVersionVersionFile = Path.Combine(emsdkPath, "upstream", "emscripten", "emscripten-version.txt");
// Adjust line endings
AdjustFileLineEndings(emscriptenSetupScript);

var rawEmsdkVersionVersion = File.Exists(emsdkVersionVersionFile) ? File.ReadAllText(emsdkVersionVersionFile)?.Trim('\"') : "";
var validVersion = Version.TryParse(rawEmsdkVersionVersion, out var emsdkVersion);
var result = RunProcess(
"bash",
$"-c \"chmod +x {emscriptenSetupScript}; {emscriptenSetupScript} \\\"{emsdkHostFolder}\\\" {Constants.EmscriptenMinVersion}\"");

if (string.IsNullOrWhiteSpace(emsdkPath)
|| !validVersion
|| emsdkVersion < Constants.EmscriptenMinVersion)
if (result.exitCode == 0)
{
throw new InvalidOperationException($"The EMSDK version {emsdkVersion} is not compatible with the current mono SDK. Install {Constants.EmscriptenMinVersion} or later.");
return emsdkBaseFolder + $"/emsdk";
}

return emsdkPath;
throw new NotSupportedException($"Failed to install emscripten");
}
else
{
throw new NotSupportedException($"Unsupported platform");
}
}

Expand Down

0 comments on commit 7c3c484

Please sign in to comment.