11using System . IO ;
22using System . Text ;
3+ using BenchmarkDotNet . Environments ;
34using BenchmarkDotNet . Extensions ;
45using BenchmarkDotNet . Helpers ;
56using BenchmarkDotNet . Loggers ;
@@ -11,14 +12,55 @@ namespace BenchmarkDotNet.Toolchains.MonoWasm
1112 public class WasmGenerator : CsProjGenerator
1213 {
1314 private readonly string CustomRuntimePack ;
15+ private readonly bool Aot ;
1416
15- public WasmGenerator ( string targetFrameworkMoniker , string cliPath , string packagesPath , string customRuntimePack )
17+ public WasmGenerator ( string targetFrameworkMoniker , string cliPath , string packagesPath , string customRuntimePack , bool aot )
1618 : base ( targetFrameworkMoniker , cliPath , packagesPath , runtimeFrameworkVersion : null )
1719 {
20+ Aot = aot ;
1821 CustomRuntimePack = customRuntimePack ;
1922 }
2023
2124 protected override void GenerateProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
25+ {
26+ if ( ( ( WasmRuntime ) buildPartition . Runtime ) . Aot )
27+ {
28+ GenerateProjectAot ( buildPartition , artifactsPaths , logger ) ;
29+ }
30+ else
31+ {
32+ GenerateProjectInterpreter ( buildPartition , artifactsPaths , logger ) ;
33+ }
34+ }
35+
36+ protected void GenerateProjectAot ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
37+ {
38+ BenchmarkCase benchmark = buildPartition . RepresentativeBenchmarkCase ;
39+ var projectFile = GetProjectFilePath ( benchmark . Descriptor . Type , logger ) ;
40+
41+ WasmRuntime runtime = ( WasmRuntime ) buildPartition . Runtime ;
42+
43+ using ( var file = new StreamReader ( File . OpenRead ( projectFile . FullName ) ) )
44+ {
45+ var ( customProperties , sdkName ) = GetSettingsThatNeedsToBeCopied ( file , projectFile ) ;
46+
47+ string content = new StringBuilder ( ResourceHelper . LoadTemplate ( "WasmAotCsProj.txt" ) )
48+ . Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
49+ . Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
50+ . Replace ( "$CSPROJPATH$" , projectFile . FullName )
51+ . Replace ( "$TFM$" , TargetFrameworkMoniker )
52+ . Replace ( "$PROGRAMNAME$" , artifactsPaths . ProgramName )
53+ . Replace ( "$RUNTIMESRCDIR$" , runtime . RuntimeSrcDir . ToString ( ) )
54+ . Replace ( "$COPIEDSETTINGS$" , customProperties )
55+ . Replace ( "$CONFIGURATIONNAME$" , buildPartition . BuildConfiguration )
56+ . Replace ( "$SDKNAME$" , sdkName )
57+ . ToString ( ) ;
58+
59+ File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
60+ }
61+ }
62+
63+ protected void GenerateProjectInterpreter ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
2264 {
2365 BenchmarkCase benchmark = buildPartition . RepresentativeBenchmarkCase ;
2466 var projectFile = GetProjectFilePath ( benchmark . Descriptor . Type , logger ) ;
@@ -46,6 +88,15 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
4688 protected override string GetExecutablePath ( string binariesDirectoryPath , string programName ) => Path . Combine ( binariesDirectoryPath , "runtime.js" ) ;
4789
4890 protected override string GetBinariesDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
49- => Path . Combine ( buildArtifactsDirectoryPath , "bin" , TargetFrameworkMoniker , "browser-wasm" , "publish" , "output" ) ;
91+ {
92+ if ( Aot )
93+ {
94+ return Path . Combine ( buildArtifactsDirectoryPath , "bin" , TargetFrameworkMoniker , "browser-wasm" , "AppBundle" ) ;
95+ }
96+ else
97+ {
98+ return Path . Combine ( buildArtifactsDirectoryPath , "bin" , TargetFrameworkMoniker , "browser-wasm" , "publish" , "output" ) ;
99+ }
100+ }
50101 }
51102}
0 commit comments