Skip to content

Commit 8631651

Browse files
authored
Fix wasm toolchain (#2531)
* Add trailing slash to output paths. * Don't include AppBundle in output paths. * Ensure folder exists. Update wasmcsproj template.
1 parent 0a41e16 commit 8631651

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

src/BenchmarkDotNet/Templates/WasmCsProj.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<RunAOTCompilation>$RUN_AOT$</RunAOTCompilation>
2424
<PublishTrimmed>$(RunAOTCompilation)</PublishTrimmed>
2525
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
26+
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
2627
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
2728
<EnableDefaultWasmAssembliesToBundle>false</EnableDefaultWasmAssembliesToBundle>
2829
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
56
using BenchmarkDotNet.Characteristics;
@@ -260,10 +261,11 @@ internal static StringBuilder MaybeAppendOutputPaths(this StringBuilder stringBu
260261
=> excludeOutput
261262
? stringBuilder
262263
: stringBuilder
263-
.AppendArgument($"/p:IntermediateOutputPath=\"{artifactsPaths.IntermediateDirectoryPath}\"\\")
264-
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}\"")
264+
// Use AltDirectorySeparatorChar so it's not interpreted as an escaped quote `\"`.
265+
.AppendArgument($"/p:IntermediateOutputPath=\"{artifactsPaths.IntermediateDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
266+
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
265267
// OutputPath is legacy, per-project version of OutDir. We set both just in case. https://github.com/dotnet/msbuild/issues/87
266-
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}\"")
267-
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}\"");
268+
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
269+
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"");
268270
}
269271
}

src/BenchmarkDotNet/Toolchains/GeneratorBase.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Text;
44
using BenchmarkDotNet.Code;
5+
using BenchmarkDotNet.Extensions;
56
using BenchmarkDotNet.Loggers;
67
using BenchmarkDotNet.Portability;
78
using BenchmarkDotNet.Running;
@@ -103,6 +104,7 @@ [PublicAPI] protected virtual void GenerateProject(BuildPartition buildPartition
103104
[PublicAPI] protected virtual void GenerateAppConfig(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
104105
{
105106
string sourcePath = buildPartition.AssemblyLocation + ".config";
107+
artifactsPaths.AppConfigPath.EnsureFolderExists();
106108

107109
using (var source = File.Exists(sourcePath) ? new StreamReader(File.OpenRead(sourcePath)) : TextReader.Null)
108110
using (var destination = new StreamWriter(File.Create(artifactsPaths.AppConfigPath), Encoding.UTF8))

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmExecutor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static Process CreateProcess(BenchmarkCase benchmarkCase, ArtifactsPaths
6161
{
6262
FileName = runtime.JavaScriptEngine,
6363
Arguments = $"{runtime.JavaScriptEngineArguments} {mainJs} -- --run {artifactsPaths.ProgramName}.dll {args} ",
64-
WorkingDirectory = artifactsPaths.BinariesDirectoryPath,
64+
WorkingDirectory = Path.Combine(artifactsPaths.BinariesDirectoryPath, "AppBundle"),
6565
UseShellExecute = false,
6666
RedirectStandardOutput = true,
6767
RedirectStandardInput = false, // not supported by WASM!

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths
6666
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
6767
}
6868

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

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

0 commit comments

Comments
 (0)