Skip to content
Merged
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
39 changes: 39 additions & 0 deletions src/tasks/WasmAppBuilder/PInvokeTableGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ private void CollectPInvokes(List<PInvoke> pinvokes, List<PInvokeCallback> callb
}
}

if (HasAttribute(type, "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute"))
{
var method = type.GetMethod("Invoke");

if (method != null)
{
string? signature = SignatureMapper.MethodToSignature(method!);
if (signature == null)
throw new NotSupportedException($"Unsupported parameter type in method '{type.FullName}.{method.Name}'");


Log.LogMessage(MessageImportance.Low, $"Adding pinvoke signature {signature} for method '{type.FullName}.{method.Name}'");
signatures.Add(signature);
}
}

void CollectPInvokesForMethod(MethodInfo method)
{
if ((method.Attributes & MethodAttributes.PinvokeImpl) != 0)
Expand Down Expand Up @@ -151,6 +167,29 @@ static bool MethodHasCallbackAttributes(MethodInfo method)
}
}

private static bool HasAttribute(MemberInfo element, params string[] attributeNames)
{
foreach (CustomAttributeData cattr in CustomAttributeData.GetCustomAttributes(element))
{
try
{
for (int i = 0; i < attributeNames.Length; ++i)
{
if (cattr.AttributeType.FullName == attributeNames [i] ||
cattr.AttributeType.Name == attributeNames[i])
{
return true;
}
}
}
catch
{
// Assembly not found, ignore
}
}
return false;
}

private void EmitPInvokeTable(StreamWriter w, Dictionary<string, string> modules, List<PInvoke> pinvokes)
{
w.WriteLine("// GENERATED FILE, DO NOT MODIFY");
Expand Down