Skip to content

Commit 6b475f6

Browse files
authored
Add linker description for wasm AOT (#1743)
* Add linker description for wasm AOT This fixes build errors, where `System.IntPtr` wasn't fully preserved. Example error: runtime/src/mono/wasm/build/WasmApp.Native.targets(425,5): error : Precompiling failed for .../performance/artifacts/bin/MicroBenchmarks/Release/net6.0/Job-DGQDZJ/bin/net6.0/browser-wasm/publish/System.Private.CoreLib.dll: Unable to compile method 'object System.Enum:GetValue ()' due to: 'VTable setup of type System.IntPtr failed assembly:.../performance/artifacts/bin/MicroBenchmarks/Release/net6.0/Job-DGQDZJ/bin/net6.0/browser-wasm/publish/System.Private.CoreLib.dll type:IntPtr member:(null)'. Also suppress linker warnings. There are too many of them (around 414) and we cannot fix them currently as most of them comes from the referenced assemblies.
1 parent 2fefdb3 commit 6b475f6

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/BenchmarkDotNet/Templates/WasmAotCsProj.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<AssemblyName>$PROGRAMNAME$</AssemblyName>
1111
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
1212
<PublishTrimmed>true</PublishTrimmed>
13+
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
1314
<RunAOTCompilation>true</RunAOTCompilation>
1415
<WasmMainJSPath>$(RuntimeSrcDir)\src\mono\wasm\runtime-test.js</WasmMainJSPath>
1516
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
@@ -24,6 +25,7 @@
2425

2526
<ItemGroup>
2627
<Compile Include="$CODEFILENAME$" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
28+
<TrimmerRootDescriptor Include="WasmLinkerDescription.xml" />
2729
</ItemGroup>
2830

2931
<ItemGroup>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<linker>
2+
<assembly fullname="System.Private.CoreLib">
3+
<type fullname="System.IntPtr" />
4+
</assembly>
5+
</linker>

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
2626
if (((WasmRuntime)buildPartition.Runtime).Aot)
2727
{
2828
GenerateProjectAot(buildPartition, artifactsPaths, logger);
29-
}
30-
else
29+
30+
var linkDescriptionFileName = "WasmLinkerDescription.xml";
31+
File.WriteAllText(Path.Combine(Path.GetDirectoryName(artifactsPaths.ProjectFilePath), linkDescriptionFileName), ResourceHelper.LoadTemplate(linkDescriptionFileName));
32+
} else
3133
{
3234
GenerateProjectInterpreter(buildPartition, artifactsPaths, logger);
3335
}

0 commit comments

Comments
 (0)