Skip to content

Commit 31e3f5f

Browse files
[Build] Add per-file up-to-date check in CompileNativeAssembly
When _CompileNativeAssemblySources runs, it recompiles ALL .ll files even if only some have changed. This adds a per-file timestamp check in RunAssembler() — if the output .o is newer than the input .ll, that file is skipped. This saves time on incremental CoreCLR builds where generators like CopyIfStreamChanged preserve .ll timestamps for unchanged files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e0d2614 commit 31e3f5f

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ sealed class Config
2222
public string? AssemblerPath;
2323
public string? AssemblerOptions;
2424
public string? InputSource;
25+
public string? OutputFile;
2526
}
2627

2728
[Required]
@@ -43,6 +44,14 @@ public override System.Threading.Tasks.Task RunTaskAsync ()
4344

4445
void RunAssembler (Config config)
4546
{
47+
if (config.OutputFile is not null && File.Exists (config.OutputFile)) {
48+
string sourceFile = Path.Combine (WorkingDirectory, Path.GetFileName (config.InputSource));
49+
if (File.Exists (sourceFile) && File.GetLastWriteTimeUtc (config.OutputFile) >= File.GetLastWriteTimeUtc (sourceFile)) {
50+
LogDebugMessage ($"[LLVM llc] Skipping '{Path.GetFileName (config.InputSource)}' because '{Path.GetFileName (config.OutputFile)}' is up to date");
51+
return;
52+
}
53+
}
54+
4655
var stdout_completed = new ManualResetEvent (false);
4756
var stderr_completed = new ManualResetEvent (false);
4857
var psi = new ProcessStartInfo () {
@@ -118,10 +127,13 @@ IEnumerable<Config> GetAssemblerConfigs ()
118127
string executableDir = Path.GetDirectoryName (llcPath);
119128
string executableName = MonoAndroidHelper.GetExecutablePath (executableDir, Path.GetFileName (llcPath));
120129

130+
string outputFilePath = Path.Combine (WorkingDirectory, sourceFile.Replace (".ll", ".o"));
131+
121132
yield return new Config {
122133
InputSource = item.ItemSpec,
123134
AssemblerPath = Path.Combine (executableDir, executableName),
124135
AssemblerOptions = $"{assemblerOptions} -o={outputFile} {QuoteFileName (sourceFile)}",
136+
OutputFile = outputFilePath,
125137
};
126138
}
127139
}

0 commit comments

Comments
 (0)