Skip to content

[wasm] EmccCompile: Add support for compiling sequentially #67483

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

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
<_WasmSourceFileToCompile Remove="@(_WasmSourceFileToCompile)" />
<_WasmSourceFileToCompile Include="@(_WasmRuntimePackSrcFile)" Dependencies="%(_WasmRuntimePackSrcFile.Dependencies);$(_EmccDefaultFlagsRsp);$(_EmccCompileRsp)" />
</ItemGroup>

<EmccCompile
SourceFiles="@(_WasmSourceFileToCompile)"
Arguments='"@$(_EmccDefaultFlagsRsp)" "@$(_EmccCompileRsp)"'
Expand All @@ -342,6 +343,7 @@

<ItemGroup>
<_BitCodeFile Dependencies="%(_BitCodeFile.Dependencies);$(_EmccDefaultFlagsRsp);$(_EmccCompileBitcodeRsp)" />
<_WasmSourceFileToCompileSequentially Include="@(WasmAssemblyToAOTSequentially -> '%(Identity).bc')" />
</ItemGroup>

<Message Text="Compiling assembly bitcode files with $(EmccLinkOptimizationFlag) ..." Importance="High" Condition="@(_BitCodeFile->Count()) > 0" />
Expand All @@ -350,6 +352,7 @@
Arguments="&quot;@$(_EmccDefaultFlagsRsp)&quot; &quot;@$(_EmccCompileBitcodeRsp)&quot;"
EnvironmentVariables="@(EmscriptenEnvVars)"
DisableParallelCompile="$(DisableParallelEmccCompile)"
SourceFileNamesToCompileSequentially="@(_WasmSourceFileToCompileSequentially)"
OutputMessageImportance="$(_EmccCompileOutputMessageImportance)">
<Output TaskParameter="OutputFiles" ItemName="FileWrites" />
</EmccCompile>
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 @@ -69,6 +69,7 @@
- $(WasmSIMD) - Enable support for the WASM SIMD feature.

Public items:
- @(WasmAssemblyToAOTSequentially) - Filenames of assemblies to always compile (to .o) sequentially
- @(WasmExtraFilesToDeploy) - Files to copy to $(WasmAppDir).
(relative path can be set via %(TargetPath) metadata)
- @(WasmFilesToIncludeInFileSystem) - Files to include in the vfs
Expand Down
29 changes: 24 additions & 5 deletions src/tasks/WasmAppBuilder/EmccCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class EmccCompile : Microsoft.Build.Utilities.Task
public string Arguments { get; set; } = string.Empty;
public string? WorkingDirectory { get; set; }
public string OutputMessageImportance{ get; set; } = "Low";
public string[] SourceFileNamesToCompileSequentially { get; set; } = Array.Empty<string>();

[Output]
public ITaskItem[]? OutputFiles { get; private set; }
Expand Down Expand Up @@ -80,6 +81,7 @@ private bool ExecuteActual()
_totalFiles = SourceFiles.Length;
IDictionary<string, string> envVarsDict = GetEnvironmentVariablesDict();
ConcurrentBag<ITaskItem> outputItems = new();
ConcurrentBag<(string srcFile, string objFile)> filesToCompileSequentially = new();
try
{
List<(string, string)> filesToCompile = new();
Expand All @@ -96,15 +98,21 @@ private bool ExecuteActual()
{
Log.LogMessage(MessageImportance.Low, $"Skipping {srcFile} because {reason}.");
outputItems.Add(CreateOutputItemFor(srcFile, objFile));
continue;
}
else

if (SourceFileNamesToCompileSequentially.Contains(Path.GetFileName(srcFile)))
{
Log.LogMessage(MessageImportance.Low, $"Compiling {srcFile} because {reason}.");
filesToCompile.Add((srcFile, objFile));
Log.LogMessage(MessageImportance.Low, $"Compiling {srcFile} because {reason}. It will be compiled at the end, sequentially.");
filesToCompileSequentially.Add((srcFile, objFile));
continue;
}

Log.LogMessage(MessageImportance.Low, $"Compiling {srcFile} because {reason}.");
filesToCompile.Add((srcFile, objFile));
}

_numCompiled = SourceFiles.Length - filesToCompile.Count;
_numCompiled = SourceFiles.Length - (filesToCompile.Count + filesToCompileSequentially.Count);
if (_numCompiled == _totalFiles)
{
// nothing to do!
Expand Down Expand Up @@ -165,7 +173,18 @@ all assigned to that one partition.
});

if (!result.IsCompleted && !Log.HasLoggedErrors)
Log.LogError("Unknown failure occurred while compiling. Check logs to get more details.");
{
Log.LogError("Unknown failure occured while compiling. Check logs to get more details.");
}
else if (!Log.HasLoggedErrors && !filesToCompileSequentially.IsEmpty)
{
Log.LogMessage(MessageImportance.High, "Compiling sequentially ...");
foreach ((string srcFile, string objFile) in filesToCompileSequentially)
{
if (!ProcessSourceFile(srcFile, objFile))
break;
}
}

if (!Log.HasLoggedErrors)
{
Expand Down