Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Add a --wasmDataDir parameter #1938

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public class CommandLineOptions
[Option("AOTCompilerMode", Required = false, Default = MonoAotCompilerMode.mini, HelpText = "Mono AOT compiler mode, either 'mini' or 'llvm'")]
public MonoAotCompilerMode AOTCompilerMode { get; set; }

[Option("wasmDataDir", Required = false, HelpText = "Wasm data directory")]
public DirectoryInfo WasmDataDirectory { get; set; }
adamsitnik marked this conversation as resolved.
Show resolved Hide resolved

internal bool UserProvidedFilters => Filters.Any() || AttributeNames.Any() || AllCategories.Any() || AnyCategories.Any();

[Usage(ApplicationAlias = "")]
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ private static Job MakeWasmJob(Job baseJob, CommandLineOptions options, string m
javaScriptEngine: options.WasmJavascriptEngine?.FullName ?? "v8",
javaScriptEngineArguments: options.WasmJavaScriptEngineArguments,
aot: wasmAot,
wasmDataDir: options.WasmDataDirectory?.FullName,
moniker: moniker);

var toolChain = WasmToolChain.From(new NetCoreAppSettings(
Expand Down
6 changes: 5 additions & 1 deletion src/BenchmarkDotNet/Environments/Runtimes/WasmRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class WasmRuntime : Runtime, IEquatable<WasmRuntime>

public bool Aot { get; }

public string WasmDataDir { get; }

/// <summary>
/// creates new instance of WasmRuntime
/// </summary>
Expand All @@ -24,14 +26,16 @@ public class WasmRuntime : Runtime, IEquatable<WasmRuntime>
/// <param name="msBuildMoniker">moniker, default: "net5.0"</param>
/// <param name="displayName">default: "Wasm"</param>
/// <param name="aot">Specifies whether AOT or Interpreter (default) project should be generated.</param>
public WasmRuntime(string msBuildMoniker = "net5.0", string displayName = "Wasm", string javaScriptEngine = "v8", string javaScriptEngineArguments = "--expose_wasm", bool aot = false, RuntimeMoniker moniker = RuntimeMoniker.Wasm) : base(moniker, msBuildMoniker, displayName)
/// <param name="wasmDataDir">Specifies a wasm data directory surfaced as $(WasmDataDir) for the project</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding xml doc comment 👍 (most of our contributors ignore build warnings and don't fix them)

public WasmRuntime(string msBuildMoniker = "net5.0", string displayName = "Wasm", string javaScriptEngine = "v8", string javaScriptEngineArguments = "--expose_wasm", bool aot = false, string wasmDataDir = null, RuntimeMoniker moniker = RuntimeMoniker.Wasm) : base(moniker, msBuildMoniker, displayName)
{
if (!string.IsNullOrEmpty(javaScriptEngine) && javaScriptEngine != "v8" && !File.Exists(javaScriptEngine))
throw new FileNotFoundException($"Provided {nameof(javaScriptEngine)} file: \"{javaScriptEngine}\" doest NOT exist");

JavaScriptEngine = javaScriptEngine;
JavaScriptEngineArguments = javaScriptEngineArguments;
Aot = aot;
WasmDataDir = wasmDataDir;
}

public override bool Equals(object obj)
Expand Down
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Templates/WasmCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<OriginalCSProjPath>$CSPROJPATH$</OriginalCSProjPath>
<WasmPropsPath>$([System.IO.Path]::ChangeExtension('$(OriginalCSProjPath)', '.Wasm.props'))</WasmPropsPath>
<WasmTargetsPath>$([System.IO.Path]::ChangeExtension('$(OriginalCSProjPath)', '.Wasm.targets'))</WasmTargetsPath>
<WasmDataDir>$WASMDATADIR$</WasmDataDir>
<WasmDataDir Condition="'$(WasmDataDir)' != ''">$([MSBuild]::NormalizeDirectory($(WasmDataDir)))</WasmDataDir>
</PropertyGroup>

<Import Project="$(WasmPropsPath)" Condition="Exists($(WasmPropsPath))" />
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths
.Replace("$COPIEDSETTINGS$", customProperties)
.Replace("$CONFIGURATIONNAME$", buildPartition.BuildConfiguration)
.Replace("$SDKNAME$", sdkName)
.Replace("$MAINJS$", MainJS)
.Replace("$WASMDATADIR$", runtime.WasmDataDir)
.Replace("$TARGET$", CustomRuntimePack != null ? "PublishWithCustomRuntimePack" : "Publish")
.ToString();

Expand Down