Final fix for full P/Invoke compatibility on Linux

This commit is contained in:
Wojtek Figat
2023-01-24 18:49:33 +01:00
parent acb1cef19d
commit f5a37ec3b4
3 changed files with 5 additions and 4 deletions

View File

@@ -1010,7 +1010,7 @@ namespace Flax.Build.Bindings
if (buildData.Toolchain.Compiler == TargetCompiler.MSVC)
libraryEntryPoint = $"{classInfo.FullNameManaged}::Internal_{eventInfo.Name}_Bind"; // MSVC allows to override exported symbol name
else
libraryEntryPoint = CppNameMangling.MangleFunctionName(buildData, eventInfo.Name + "_ManagedBind", classInfo.FullNameNativeInternal + "Internal", CSharpEventBindReturn, CSharpEventBindParams);
libraryEntryPoint = CppNameMangling.MangleFunctionName(buildData, eventInfo.Name + "_ManagedBind", classInfo.FullNameNativeInternal + "Internal", CSharpEventBindReturn, eventInfo.IsStatic ? null : new TypeInfo(classInfo.FullNameNative) { IsPtr = true }, CSharpEventBindParams);
contents.Append(indent).Append($"[LibraryImport(\"{classInfo.ParentModule.Module.BinaryModuleName}\", EntryPoint = \"{libraryEntryPoint}\", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]").AppendLine();
contents.Append(indent).Append($"internal static partial void Internal_{eventInfo.Name}_Bind(");
if (!eventInfo.IsStatic)

View File

@@ -967,12 +967,13 @@ namespace Flax.Build.Bindings
else
{
// For simple functions we can bind it directly (CppNameMangling is incomplete for complex cases)
if (functionInfo.Parameters.Count + functionInfo.Parameters.Count == 0)
// TODO: improve this to use wrapper method directly from P/Invoke if possible
/*if (functionInfo.Parameters.Count + functionInfo.Parameters.Count == 0)
{
useSeparateImpl = true; // DLLEXPORT doesn't properly export function thus separate implementation from declaration
libraryEntryPoint = CppNameMangling.MangleFunctionName(buildData, functionInfo.Name, callerName, functionInfo.ReturnType, functionInfo.IsStatic ? null : new TypeInfo(caller.Name) { IsPtr = true }, functionInfo.Parameters, functionInfo.Glue.CustomParameters);
}
else
else*/
{
useLibraryExportInPlainC = true;
libraryEntryPoint = $"{callerName}_{functionInfo.UniqueName}";

View File

@@ -12,7 +12,7 @@ namespace Flax.Build
/// </summary>
internal static class CppNameMangling
{
public static string MangleFunctionName(Builder.BuildData buildData, string name, string outerName, TypeInfo returnType, TypeInfo parameter0, List<FunctionInfo.ParameterInfo> parameters1, List<FunctionInfo.ParameterInfo> parameters2)
public static string MangleFunctionName(Builder.BuildData buildData, string name, string outerName, TypeInfo returnType, TypeInfo parameter0 = null, List<FunctionInfo.ParameterInfo> parameters1 = null, List<FunctionInfo.ParameterInfo> parameters2 = null)
{
List<FunctionInfo.ParameterInfo> parameters = null;
if (parameter0 == null)