Skip to content

Commit

Permalink
Add Custom Runtime Pack option to WasmToolchain (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Ricci authored Jul 17, 2020
1 parent 9c56636 commit 13ee8be
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public class CommandLineOptions
[Option("wasmArgs", Required = false, Default = "--expose_wasm", HelpText = "Arguments for the javascript engine used by Wasm toolchain.")]
public string WasmJavaScriptEngineArguments { get; set; }

[Option("customRuntimePack", Required = false, HelpText = "Specify the path to a custom runtime pack. Only used for wasm currently.")]
public string CustomRuntimePack { get; set; }

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

[Usage(ApplicationAlias = "")]
Expand Down
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
name: wasmRuntime.Name,
customDotNetCliPath: options.CliPath?.FullName,
packagesPath: options.RestorePath?.FullName,
timeout: timeOut ?? NetCoreAppSettings.DefaultBuildTimeout));
timeout: timeOut ?? NetCoreAppSettings.DefaultBuildTimeout,
customRuntimePack: options.CustomRuntimePack));

return baseJob.WithRuntime(wasmRuntime).WithToolchain(toolChain);
default:
Expand Down
14 changes: 13 additions & 1 deletion src/BenchmarkDotNet/Templates/WasmCsProj.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="$SDKNAME$" DefaultTargets="Publish">
<Project Sdk="$SDKNAME$" DefaultTargets="$TARGET$">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>bin</OutputPath>
Expand All @@ -7,13 +7,25 @@
<AppDir>$(MSBuildThisFileDirectory)\bin\$TFM$\browser-wasm\publish</AppDir>
<AssemblyName>$PROGRAMNAME$</AssemblyName>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<MicrosoftNetCoreAppRuntimePackDir>$RUNTIMEPACK$</MicrosoftNetCoreAppRuntimePackDir>
$COPIEDSETTINGS$
</PropertyGroup>

<ItemGroup>
<Compile Include="$CODEFILENAME$" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>

<Target Name="UpdateRuntimePack"
DependsOnTargets="ResolveFrameworkReferences" Condition="'$(MicrosoftNetCoreAppRuntimePackDir)' != ''">
<ItemGroup>
<ResolvedRuntimePack Update="@(ResolvedRuntimePack)" PackageDirectory="$(MicrosoftNetCoreAppRuntimePackDir)" />
</ItemGroup>
</Target>

<Target Name="PublishWithCustomRuntimePack"
AfterTargets="Build"
DependsOnTargets="UpdateRuntimePack;Publish" />

<ItemGroup>
<ProjectReference Include="$CSPROJPATH$" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public NetCoreAppSettings(
string name,
string customDotNetCliPath = null,
string packagesPath = null,
TimeSpan? timeout = null
TimeSpan? timeout = null,
string customRuntimePack = null
)
{
TargetFrameworkMoniker = targetFrameworkMoniker;
Expand All @@ -53,6 +54,7 @@ public NetCoreAppSettings(
CustomDotNetCliPath = customDotNetCliPath;
PackagesPath = packagesPath;
Timeout = timeout ?? DefaultBuildTimeout;
CustomRuntimePack = customRuntimePack;
}

/// <summary>
Expand All @@ -79,6 +81,11 @@ public NetCoreAppSettings(
/// </summary>
public TimeSpan Timeout { get; }

/// <summary>
/// Path to a custom runtime pack.
/// </summary>
public string CustomRuntimePack { get; }

public NetCoreAppSettings WithCustomDotNetCliPath(string customDotNetCliPath, string displayName = null)
=> new NetCoreAppSettings(TargetFrameworkMoniker, RuntimeFrameworkVersion, displayName ?? Name, customDotNetCliPath, PackagesPath, Timeout);

Expand Down
13 changes: 10 additions & 3 deletions src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ namespace BenchmarkDotNet.Toolchains.MonoWasm
{
public class WasmGenerator : CsProjGenerator
{
public WasmGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath)
: base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion: null) { }
private readonly string CustomRuntimePack;

public WasmGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, string customRuntimePack)
: base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion: null)
{
CustomRuntimePack = customRuntimePack;
}

protected override void GenerateProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger)
{
Expand All @@ -30,6 +35,8 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
.Replace("$COPIEDSETTINGS$", customProperties)
.Replace("$CONFIGURATIONNAME$", buildPartition.BuildConfiguration)
.Replace("$SDKNAME$", sdkName)
.Replace("$RUNTIMEPACK$", CustomRuntimePack ?? "")
.Replace("$TARGET$", CustomRuntimePack != null ? "PublishWithCustomRuntimePack" : "Publish")
.ToString();

File.WriteAllText(artifactsPaths.ProjectFilePath, content);
Expand All @@ -41,4 +48,4 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
=> Path.Combine(buildArtifactsDirectoryPath, "bin", TargetFrameworkMoniker, "browser-wasm", "publish", "output");
}
}
}
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/Toolchains/MonoWasm/WasmToolChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static IToolchain From(NetCoreAppSettings netCoreAppSettings)
=> new WasmToolChain(netCoreAppSettings.Name,
new WasmGenerator(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath,
netCoreAppSettings.PackagesPath),
netCoreAppSettings.PackagesPath,
netCoreAppSettings.CustomRuntimePack),
new WasmBuilder(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath,
netCoreAppSettings.Timeout),
Expand Down

0 comments on commit 13ee8be

Please sign in to comment.