Skip to content

Commit

Permalink
Fix wasm toolchain (#2531)
Browse files Browse the repository at this point in the history
* Add trailing slash to output paths.

* Don't include AppBundle in output paths.

* Ensure folder exists.
Update wasmcsproj template.
  • Loading branch information
timcassell committed Feb 28, 2024
1 parent 0a41e16 commit 8631651
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Templates/WasmCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<RunAOTCompilation>$RUN_AOT$</RunAOTCompilation>
<PublishTrimmed>$(RunAOTCompilation)</PublishTrimmed>
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<EnableDefaultWasmAssembliesToBundle>false</EnableDefaultWasmAssembliesToBundle>
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
Expand Down
10 changes: 6 additions & 4 deletions src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BenchmarkDotNet.Characteristics;
Expand Down Expand Up @@ -260,10 +261,11 @@ internal static StringBuilder MaybeAppendOutputPaths(this StringBuilder stringBu
=> excludeOutput
? stringBuilder
: stringBuilder
.AppendArgument($"/p:IntermediateOutputPath=\"{artifactsPaths.IntermediateDirectoryPath}\"\\")
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}\"")
// Use AltDirectorySeparatorChar so it's not interpreted as an escaped quote `\"`.
.AppendArgument($"/p:IntermediateOutputPath=\"{artifactsPaths.IntermediateDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
// OutputPath is legacy, per-project version of OutDir. We set both just in case. https://github.com/dotnet/msbuild/issues/87
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}\"")
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}\"");
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"");
}
}
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Toolchains/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Text;
using BenchmarkDotNet.Code;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
Expand Down Expand Up @@ -103,6 +104,7 @@ protected virtual string GetIntermediateDirectoryPath(string buildArtifactsDirec
[PublicAPI] protected virtual void GenerateAppConfig(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
{
string sourcePath = buildPartition.AssemblyLocation + ".config";
artifactsPaths.AppConfigPath.EnsureFolderExists();

using (var source = File.Exists(sourcePath) ? new StreamReader(File.OpenRead(sourcePath)) : TextReader.Null)
using (var destination = new StreamWriter(File.Create(artifactsPaths.AppConfigPath), Encoding.UTF8))
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/MonoWasm/WasmExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static Process CreateProcess(BenchmarkCase benchmarkCase, ArtifactsPaths
{
FileName = runtime.JavaScriptEngine,
Arguments = $"{runtime.JavaScriptEngineArguments} {mainJs} -- --run {artifactsPaths.ProgramName}.dll {args} ",
WorkingDirectory = artifactsPaths.BinariesDirectoryPath,
WorkingDirectory = Path.Combine(artifactsPaths.BinariesDirectoryPath, "AppBundle"),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = false, // not supported by WASM!
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
}

protected override string GetExecutablePath(string binariesDirectoryPath, string programName) => Path.Combine(binariesDirectoryPath, MainJS);
protected override string GetExecutablePath(string binariesDirectoryPath, string programName) => Path.Combine(binariesDirectoryPath, "AppBundle", MainJS);

protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, "browser-wasm", "AppBundle");
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, "browser-wasm");
}
}

0 comments on commit 8631651

Please sign in to comment.