Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 22 additions & 7 deletions src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<NoWarn>$(NoWarn),CA1050,CA1850</NoWarn>
<TargetFrameworks>$(NetCoreAppToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
<!-- Ignore nullable warnings on net4* -->
<NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">$(NoWarn),CA1050,CS8604,CS8602</NoWarn>
<NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETFramework'">$(NoWarn),CA1050,CA1850</NoWarn>
<EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Compile Include="..\Common\IsExternalInit.cs" />
<Compile Include="$(RepoRoot)src\libraries\System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs" />
</ItemGroup>

<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
<Compile Remove="mono/*.cs" />
</ItemGroup>
Expand All @@ -31,17 +38,25 @@

<!-- Reference Microsoft.Build.Tasks.Core directly to avoid bringing in it's package closure.
This assembly is provided by MSBuild. -->
<PackageDownloadAndReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" Folder="ref/net8.0" />
<PackageDownloadAndReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" Folder="ref/net472" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net472'))" />
<PackageDownloadAndReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" Folder="ref/net8.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>

<Target Name="GetFilesToPackage" Returns="@(FilesToPackage)">
<ItemGroup>
<FilesToPackage Include="$(OutputPath)$(MSBuildProjectName)*" TargetPath="tasks\$(NetCoreAppToolCurrent)" />
<FilesToPackage Include="$(OutputPath)Microsoft.NET.WebAssembly.Webcil.dll" TargetPath="tasks\$(NetCoreAppToolCurrent)" />
<!-- .NETCoreApp -->
<FilesToPackage Include="$(OutputPath)$(NetCoreAppToolCurrent)\$(MSBuildProjectName)*"
TargetPath="tasks\$(NetCoreAppToolCurrent)" />
<FilesToPackage Include="$(OutputPath)$(NetCoreAppToolCurrent)\Microsoft.NET.WebAssembly.Webcil.dll"
TargetPath="tasks\$(NetCoreAppToolCurrent)" />

<!-- For .NETFramework we need all the dependent assemblies too, so copy from the publish folder -->
<FilesToPackage Include="$(OutputPath)$(NetFrameworkToolCurrent)\*"
TargetPath="tasks\$(NetFrameworkToolCurrent)" />
</ItemGroup>
</Target>

<UsingTask TaskName="ManagedToNativeGenerator" Runtime="NET" TaskFactory="TaskHostFactory" AssemblyFile="$(TargetPath)" />
<UsingTask TaskName="ManagedToNativeGenerator" TaskFactory="TaskHostFactory" AssemblyFile="$(OutputPath)$(NetCoreAppToolCurrent)\WasmAppBuilder.dll" />
<Target Name="RunGenerator" DependsOnTargets="Build" Condition="'$(AssembliesScanPath)' != ''">
<ItemGroup>
<WasmPInvokeAssembly Include="$(AssembliesScanPath)*.dll" />
Expand Down
10 changes: 8 additions & 2 deletions src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static string PickCTypeNameForUnknownType(Type t)
if (!t.IsValueType)
return "void *";
// Pass pointers and function pointers by-value
else if (t.IsPointer || t.IsFunctionPointer)
else if (t.IsPointer || IsFunctionPointer(t))
return "void *";
else if (t.IsPrimitive)
throw new NotImplementedException("No native type mapping for type " + t);
Expand Down Expand Up @@ -504,6 +504,12 @@ private string ThunkMapEntryLine(PInvokeCallback cb, LogAdapter Log)

private static readonly Dictionary<Type, bool> _blittableCache = new();

public static bool IsFunctionPointer(Type type)
{
object? bIsFunctionPointer = type.GetType().GetProperty("IsFunctionPointer")?.GetValue(type);
return (bIsFunctionPointer is bool b) && b;
}

public static bool IsBlittable(Type type, LogAdapter log)
{
// We maintain a cache of results in order to only produce log messages the first time
Expand All @@ -523,7 +529,7 @@ static bool IsBlittableUncached(Type type, LogAdapter log)
if (type.IsPrimitive || type.IsByRef || type.IsPointer || type.IsEnum)
return true;

if (type.IsFunctionPointer)
if (IsFunctionPointer(type))
return true;

// HACK: SkiaSharp has pinvokes that rely on this
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/WasmAppBuilder/coreclr/SignatureMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal static class SignatureMapper
}
else if (t.IsPointer)
c = 'i';
else if (t.IsFunctionPointer)
else if (PInvokeTableGenerator.IsFunctionPointer(t))
c = 'i';
else if (t.IsValueType)
{
Expand Down
Loading