Skip to content

Commit 47b2449

Browse files
committed
feat: WasmExport for raw exports
1 parent 7a9033a commit 47b2449

14 files changed

Lines changed: 1167 additions & 131 deletions

File tree

AspNetCore.sln

Lines changed: 177 additions & 76 deletions
Large diffs are not rendered by default.

sdk/Zapto.AspNetCore.CloudFlare.SDK/Sdk/Sdk.targets

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -251,37 +251,22 @@
251251
</Target>
252252

253253
<!--
254-
Generate WasmExports.g.cs automatically.
255-
This file contains the [UnmanagedCallersOnly] exports that must be in the main assembly.
256-
Generated at build time so users don't have to write it manually.
254+
Source generator for WasmExports.g.cs.
255+
The generator scans referenced assemblies for [WasmExport] methods
256+
and generates forwarding exports with [UnmanagedCallersOnly] in the main assembly.
257+
This provides better incremental compilation support than MSBuild targets.
257258
-->
258-
<PropertyGroup>
259-
<WasmExportsGeneratedDir>$(BaseIntermediateOutputPath)generated\</WasmExportsGeneratedDir>
260-
<WasmExportsGeneratedFile>$(WasmExportsGeneratedDir)WasmExports.g.cs</WasmExportsGeneratedFile>
261-
<WasmExportsNamespace Condition="'$(WasmExportsNamespace)' == ''">$(RootNamespace)</WasmExportsNamespace>
262-
<WasmExportsNamespace Condition="'$(WasmExportsNamespace)' == ''">$(AssemblyName)</WasmExportsNamespace>
263-
</PropertyGroup>
264-
265-
<Target Name="GenerateWasmExports"
266-
BeforeTargets="CoreCompile"
267-
Inputs="$(MSBuildThisFileDirectory)WasmExports.cs.template"
268-
Outputs="$(WasmExportsGeneratedFile)">
269-
<MakeDir Directories="$(WasmExportsGeneratedDir)" />
270-
271-
<PropertyGroup>
272-
<_WasmExportsTemplate>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)WasmExports.cs.template'))</_WasmExportsTemplate>
273-
<_WasmExportsContent>$(_WasmExportsTemplate.Replace('$NAMESPACE$', '$(WasmExportsNamespace)'))</_WasmExportsContent>
274-
</PropertyGroup>
275-
276-
<WriteLinesToFile File="$(WasmExportsGeneratedFile)"
277-
Lines="$(_WasmExportsContent)"
278-
Overwrite="true"
279-
WriteOnlyWhenDifferent="true" />
280-
</Target>
281-
282-
<!-- Include the generated file in compilation -->
283-
<ItemGroup>
284-
<Compile Include="$(WasmExportsGeneratedFile)" Visible="false" />
259+
260+
<!-- For local development (ZaptoWasmUseProjectReference=true), reference the generator project -->
261+
<ItemGroup Condition="'$(ZaptoWasmUseProjectReference)' == 'true'">
262+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\src\Zapto.AspNetCore.Wasm.SourceGenerator\Zapto.AspNetCore.Wasm.SourceGenerator.csproj"
263+
OutputItemType="Analyzer"
264+
ReferenceOutputAssembly="false" />
265+
</ItemGroup>
266+
267+
<!-- For NuGet package consumption, include the analyzer from package path -->
268+
<ItemGroup Condition="'$(ZaptoWasmUseProjectReference)' != 'true'">
269+
<Analyzer Include="$(MSBuildThisFileDirectory)..\analyzers\dotnet\cs\Zapto.AspNetCore.Wasm.SourceGenerator.dll" />
285270
</ItemGroup>
286271

287272
</Project>

sdk/Zapto.AspNetCore.CloudFlare.SDK/Sdk/WasmExports.cs.template

Lines changed: 0 additions & 24 deletions
This file was deleted.

sdk/Zapto.AspNetCore.CloudFlare.SDK/Zapto.AspNetCore.CloudFlare.SDK.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,23 @@
2121
<None Include="Sdk\Sdk.props" Pack="true" PackagePath="Sdk" />
2222
<None Include="Sdk\index.js" Pack="true" PackagePath="Sdk" />
2323
<None Include="Sdk\wrangler.toml" Pack="true" PackagePath="Sdk" />
24-
<None Include="Sdk\WasmExports.cs.template" Pack="true" PackagePath="Sdk" />
24+
<!-- Source generator replaces WasmExports.cs.template for better incremental compilation -->
2525
<!-- Sdk.targets is added dynamically with version substitution -->
2626
</ItemGroup>
27+
28+
<!-- Include the source generator in the package -->
29+
<ItemGroup>
30+
<ProjectReference Include="..\..\src\Zapto.AspNetCore.Wasm.SourceGenerator\Zapto.AspNetCore.Wasm.SourceGenerator.csproj"
31+
PrivateAssets="all"
32+
ReferenceOutputAssembly="false" />
33+
</ItemGroup>
34+
35+
<Target Name="IncludeSourceGenerator" BeforeTargets="GenerateNuspec">
36+
<ItemGroup>
37+
<_PackageFiles Include="..\..\src\Zapto.AspNetCore.Wasm.SourceGenerator\bin\$(Configuration)\netstandard2.0\Zapto.AspNetCore.Wasm.SourceGenerator.dll"
38+
PackagePath="analyzers/dotnet/cs" />
39+
</ItemGroup>
40+
</Target>
2741

2842
<!--
2943
Generate Sdk.targets with the package version embedded.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ReSharper disable once CheckNamespace
2+
namespace System.Runtime.CompilerServices;
3+
4+
/// <summary>
5+
/// Polyfill for init-only properties in netstandard2.0.
6+
/// </summary>
7+
internal static class IsExternalInit;

0 commit comments

Comments
 (0)