Fix C# assemblies id generation to use cross-platform hash code impl

This commit is contained in:
mafiesto4
2021-01-17 21:44:37 +01:00
parent f8feccc27d
commit 6b0d34a21d
3 changed files with 28 additions and 9 deletions

View File

@@ -1047,10 +1047,10 @@ namespace Flax.Build.Bindings
internal struct GuidInterop
{
public int A;
public int B;
public int C;
public int D;
public uint A;
public uint B;
public uint C;
public uint D;
}
private static unsafe void GenerateCSharp(BuildData buildData, IGrouping<string, Module> binaryModule)
@@ -1061,10 +1061,10 @@ namespace Flax.Build.Bindings
// Generate binary module ID
GuidInterop idInterop;
idInterop.A = binaryModuleName.GetHashCode();
idInterop.B = project.Name.GetHashCode();
idInterop.C = project.Company.GetHashCode();
idInterop.D = project.Copyright.GetHashCode();
idInterop.A = Utilities.GetHashCode(binaryModuleName);
idInterop.B = Utilities.GetHashCode(project.Name);
idInterop.C = Utilities.GetHashCode(project.Company);
idInterop.D = Utilities.GetHashCode(project.Copyright);
var id = *(Guid*)&idInterop;
// Generate C# binary module information

View File

@@ -14,6 +14,25 @@ namespace Flax.Build
/// </summary>
public static class Utilities
{
/// <summary>
/// Gets the hash code for the string (the same for all platforms). Matches Engine algorithm for string hashing.
/// </summary>
/// <param name="str">The input string.</param>
/// <returns>The file size text.</returns>
internal static uint GetHashCode(string str)
{
uint hash = 5381;
if (str != null)
{
for (int i = 0; i < str.Length; i++)
{
char c = str[i];
hash = ((hash << 5) + hash) + (uint)c;
}
}
return hash;
}
/// <summary>
/// Gets the size of the file as a readable string.
/// </summary>