Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Add $(EmccTotalMemory) to allow custom -s TOTAL_MEMORY=.. #56117

Merged
merged 3 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
<_EmccCompileRsp>$(_WasmIntermediateOutputPath)emcc-compile.rsp</_EmccCompileRsp>
<_EmccCompileOutputMessageImportance Condition="'$(EmccVerbose)' == 'true'">Normal</_EmccCompileOutputMessageImportance>
<_EmccCompileOutputMessageImportance Condition="'$(EmccVerbose)' != 'true'">Low</_EmccCompileOutputMessageImportance>

<EmccTotalMemory Condition="'$(EmccTotalMemory)' == ''">536870912</EmccTotalMemory>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -269,7 +271,7 @@
<_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" />
<_EmccLDFlags Include="@(_EmccCommonFlags)" />

<_EmccLDFlags Include="-s TOTAL_MEMORY=536870912" />
<_EmccLDFlags Include="-s TOTAL_MEMORY=$(EmccTotalMemory)" />
<_EmccLDFlags Include="$(EmccExtraLDFlags)" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- $(EmccFlags) - Emcc flags used for both compiling native files, and linking
- $(EmccExtraLDFlags) - Extra emcc flags for linking
- $(EmccExtraCFlags) - Extra emcc flags for compiling native files
- $(EmccTotalMemory) - Total memory specified with `emcc`. Default value: 536870912


Public items:
Expand Down
21 changes: 11 additions & 10 deletions src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths)
var aotArgs = new List<string>();
var processArgs = new List<string>();
bool isDedup = assembly == DedupAssembly;
string msgPrefix = $"[{Path.GetFileName(assembly)}] ";

var a = assemblyItem.GetMetadata("AotArguments");
if (a != null)
Expand Down Expand Up @@ -542,27 +543,27 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths)
sw.WriteLine(responseFileContent);
}

Log.LogMessage(MessageImportance.Low, $"AOT compiler arguments: {responseFileContent}");

string args = $"--response=\"{responseFilePath}\"";
string workingDir = assemblyDir;

// Log the command in a compact format which can be copy pasted
StringBuilder envStr = new StringBuilder(string.Empty);
foreach (KeyValuePair<string, string> kvp in envVariables)
envStr.Append($"{kvp.Key}={kvp.Value} ");
Log.LogMessage(MessageImportance.Low, $"Exec: {envStr}{CompilerBinaryPath} {args}");
{
StringBuilder envStr = new StringBuilder(string.Empty);
foreach (KeyValuePair<string, string> kvp in envVariables)
envStr.Append($"{kvp.Key}={kvp.Value} ");
Log.LogMessage(MessageImportance.Low, $"{msgPrefix}Exec (with response file contents expanded) in {workingDir}: {envStr}{CompilerBinaryPath} {responseFileContent}");
}

try
{
// run the AOT compiler
(int exitCode, string output) = Utils.TryRunProcess(Log,
CompilerBinaryPath,
args,
$"--response=\"{responseFilePath}\"",
envVariables,
assemblyDir,
workingDir,
silent: false,
debugMessageImportance: MessageImportance.Low,
label: assembly);
label: Path.GetFileName(assembly));
if (exitCode != 0)
{
Log.LogError($"Precompiling failed for {assembly}: {output}");
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static (int exitCode, string output) RunShellCommand(
: ("/bin/sh", $"\"{scriptFileName}\"");

string msgPrefix = label == null ? string.Empty : $"[{label}] ";
logger.LogMessage(debugMessageImportance, $"Running {command} via script {scriptFileName}:", msgPrefix);
logger.LogMessage(debugMessageImportance, $"{msgPrefix}Running {command} via script {scriptFileName}:", msgPrefix);
logger.LogMessage(debugMessageImportance, File.ReadAllText(scriptFileName), msgPrefix);

return TryRunProcess(logger,
Expand Down Expand Up @@ -111,7 +111,7 @@ public static (int, string) TryRunProcess(
string? label=null)
{
string msgPrefix = label == null ? string.Empty : $"[{label}] ";
logger.LogMessage(debugMessageImportance, $"Running: {path} {args}", msgPrefix);
logger.LogMessage(debugMessageImportance, $"{msgPrefix}Running: {path} {args}");
var outputBuilder = new StringBuilder();
var processStartInfo = new ProcessStartInfo
{
Expand All @@ -126,12 +126,12 @@ public static (int, string) TryRunProcess(
if (workingDir != null)
processStartInfo.WorkingDirectory = workingDir;

logger.LogMessage(debugMessageImportance, $"Using working directory: {workingDir ?? Environment.CurrentDirectory}", msgPrefix);
logger.LogMessage(debugMessageImportance, $"{msgPrefix}Using working directory: {workingDir ?? Environment.CurrentDirectory}", msgPrefix);

if (envVars != null)
{
if (envVars.Count > 0)
logger.LogMessage(MessageImportance.Low, $"Setting environment variables for execution:", msgPrefix);
logger.LogMessage(MessageImportance.Low, $"{msgPrefix}Setting environment variables for execution:", msgPrefix);

foreach (KeyValuePair<string, string> envVar in envVars)
{
Expand Down