Skip to content

Commit 246d30b

Browse files
committed
Added multi lib generation
1 parent e053c6c commit 246d30b

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

Common/Utility/Utils.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,25 @@ public static void Align(this BinaryWriter writer, int alignment = 16, byte pad
7878
for (int i = 0; i < padding; i++)
7979
writer.Write(pad);
8080
}
81+
82+
public static IEnumerable<IEnumerable<T>> ChunkBy<T>(this IEnumerable<T> source, int chunkSize) {
83+
if (source == null)
84+
throw new ArgumentNullException(nameof(source));
85+
if (chunkSize <= 0)
86+
throw new ArgumentOutOfRangeException(nameof(chunkSize));
87+
88+
using var enumerator = source.GetEnumerator();
89+
while (enumerator.MoveNext()) {
90+
yield return TakeChunk(enumerator, chunkSize);
91+
}
92+
}
93+
94+
private static IEnumerable<T> TakeChunk<T>(this IEnumerator<T> enumerator, int chunkSize) {
95+
int count = 0;
96+
do {
97+
yield return enumerator.Current;
98+
count++;
99+
} while (count < chunkSize && enumerator.MoveNext());
100+
}
81101
}
82102
}

LibraryGenerator/Commands/MainCommand.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,31 @@ public ValueTask ExecuteAsync(IConsole console)
117117
}
118118
}
119119

120-
// .def and .lib file paths
121-
string defFilePath = Path.Combine(PlatformOutput.FullName, "Minecraft.Windows.def");
122-
string libFilePath = Path.Combine(PlatformOutput.FullName, "Minecraft.Windows.lib");
123-
124-
// Create .def file
125-
Utils.CreateDefinitionFile(defFilePath, allMangledNames);
126-
127-
// Generate .lib file
128-
var libProc = Lib.GenerateLib(defFilePath, libFilePath);
129-
libProc.WaitForExit();
130-
if (libProc.ExitCode != 0)
120+
int index = 0;
121+
foreach (var chunk in allMangledNames.ChunkBy(65534))
131122
{
132-
return ValueTask.FromException(new Exception("Library generation aborted due to errors."));
123+
// .def and .lib file paths
124+
string defFilePath = Path.Combine(PlatformOutput.FullName, $"Minecraft.Windows.{index}.def");
125+
string libFilePath = Path.Combine(PlatformOutput.FullName, $"Minecraft.Windows.{index}.lib");
126+
127+
// Create .def file
128+
Utils.CreateDefinitionFile(defFilePath, chunk);
129+
130+
// Generate .lib file
131+
var libProc = Lib.GenerateLib(defFilePath, libFilePath);
132+
libProc.WaitForExit();
133+
if (libProc.ExitCode != 0) {
134+
return ValueTask.FromException(new Exception("Library generation aborted due to errors."));
135+
}
136+
137+
Logger.Debug($"Library 'Minecraft.Windows.{index}.lib' generated succesfully.");
138+
File.Delete(defFilePath); // Clean up .def file
139+
File.Delete(Path.ChangeExtension(defFilePath, ".exp")); // Clean up .exp file
140+
index++;
133141
}
134142

135143
// Save updated checksums only if all operations succeeded
136144
symbolTracker.SaveChecksums(checksums);
137-
Logger.Debug("Library 'Minecraft.Windows.lib' generated succesfully.");
138145
return default;
139146
}
140147
}

0 commit comments

Comments
 (0)