diff --git a/Directory.Build.props b/Directory.Build.props index 64838881765ded..a36faa2d095f12 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -86,10 +86,7 @@ $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmBuildTasks', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WorkloadBuildTasks', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoAOTCompiler', 'Debug', '$(NetCoreAppToolCurrent)')) - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'RuntimeConfigParser', 'Debug', '$(NetCoreAppToolCurrent)')) - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'JsonToItemsTaskFactory', 'Debug', '$(NetCoreAppToolCurrent)')) - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'ILStrip', 'Debug', '$(NetCoreAppToolCurrent)')) - + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoTargetsTasks', 'Debug', '$(NetCoreAppToolCurrent)')) $([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'installer.tasks', 'Debug', '$(NetCoreAppToolCurrent)', 'installer.tasks.dll')) $([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'installer.tasks', 'Debug', '$(NetFrameworkToolCurrent)', 'installer.tasks.dll')) $([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'Crossgen2Tasks', 'Debug', '$(NetCoreAppToolCurrent)', 'Microsoft.NET.CrossGen.props')) @@ -100,9 +97,7 @@ $([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll')) $([MSBuild]::NormalizePath('$(WorkloadBuildTasksDir)', 'WorkloadBuildTasks.dll')) $([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll')) - $([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll')) - $([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll')) - $([MSBuild]::NormalizePath('$(ILStripTaskDir)', 'ILStrip.dll')) + $([MSBuild]::NormalizePath('$(MonoTargetsTasksDir)', 'MonoTargetsTasks.dll')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(Configuration)')) diff --git a/docs/design/mono/mobile-runtimeconfig-json.md b/docs/design/mono/mobile-runtimeconfig-json.md index 239826da05220e..76bd4aa117a5ee 100644 --- a/docs/design/mono/mobile-runtimeconfig-json.md +++ b/docs/design/mono/mobile-runtimeconfig-json.md @@ -44,7 +44,7 @@ The task should: ``` + AssemblyFile="$(MonoTargetsTasksAssemblyPath)" /> {MonoProjectRoot} {MonoAOTCompilerTasksAssemblyPath} {WasmAppBuilderTasksAssemblyPath} - {JsonToItemsTaskFactoryTasksAssemblyPath} - {RuntimeConfigParserTasksAssemblyPath} + {MonoTargetsTasksAssemblyPath} {MicrosoftNetCoreAppRuntimePackRidDir} diff --git a/eng/testing/linker/trimmingTests.targets b/eng/testing/linker/trimmingTests.targets index b2cb80e9b79874..05736702d9d007 100644 --- a/eng/testing/linker/trimmingTests.targets +++ b/eng/testing/linker/trimmingTests.targets @@ -91,11 +91,9 @@ .Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)') .Replace('{RepositoryEngineeringDir}', '$(RepositoryEngineeringDir)') .Replace('{MonoAOTCompilerDir}', '$(MonoAOTCompilerDir)') - .Replace('{JsonToItemsTaskFactoryDir}', '$(JsonToItemsTaskFactoryDir)') .Replace('{MonoProjectRoot}', '$(MonoProjectRoot)') .Replace('{MonoAOTCompilerTasksAssemblyPath}', '$(MonoAOTCompilerTasksAssemblyPath)') - .Replace('{JsonToItemsTaskFactoryTasksAssemblyPath}', '$(JsonToItemsTaskFactoryTasksAssemblyPath)') - .Replace('{RuntimeConfigParserTasksAssemblyPath}', '$(RuntimeConfigParserTasksAssemblyPath)') + .Replace('{MonoTargetsTasksAssemblyPath}', '$(MonoTargetsTasksAssemblyPath)') .Replace('{WasmAppBuilderTasksAssemblyPath}', '$(WasmAppBuilderTasksAssemblyPath)') .Replace('{MicrosoftNetCoreAppRuntimePackRidDir}', '$(MicrosoftNetCoreAppRuntimePackRidDir)') .Replace('{ProductVersion}', '$(ProductVersion)') diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 8a7036f14208f6..77b533e4b48fea 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -52,8 +52,8 @@ + AssemblyFile="$(MonoTargetsTasksAssemblyPath)" + Condition="'$(MonoTargetsTasksAssemblyPath)' != ''" /> + AssemblyFile="$(MonoTargetsTasksAssemblyPath)" /> diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 8d42aba4a4ecc0..2d04f9a01b1c5b 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -389,8 +389,7 @@ - - + diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj index 724b704f864b11..a38b1d301e61d2 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj @@ -6,18 +6,14 @@ - - - + - - - + diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/README.md b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/README.md index 9cb722152afdcd..0a0266015244db 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/README.md +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/README.md @@ -36,3 +36,19 @@ To use the task in a project, reference the NuGet package, with the appropriate ``` + +## ILStrip + +This is a task that removes the IL methods bodies from assemblies. Useful in conjunction with AOT compilation. + +``` + + + + + + + +``` + +The `OutputPath` metadata is optional. If it is not present, the items will be updated in place. diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/ILStripTask.props b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/ILStripTask.props deleted file mode 100644 index 84c0dbf11afa87..00000000000000 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/ILStripTask.props +++ /dev/null @@ -1,7 +0,0 @@ - - - $(MSBuildThisFileDirectory)..\tasks\net6.0\ILStrip.dll - $(MSBuildThisFileDirectory)..\tasks\net472\ILStrip.dll - - - diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeComponentManifest.props b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/MonoTargetsTasks.props similarity index 50% rename from src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeComponentManifest.props rename to src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/MonoTargetsTasks.props index d173ff67c2b882..7fe32897283ba8 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeComponentManifest.props +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/MonoTargetsTasks.props @@ -1,9 +1,15 @@ - $(MSBuildThisFileDirectory)..\tasks\net6.0\JsonToItemsTaskFactory.dll - $(MSBuildThisFileDirectory)..\tasks\net472\JsonToItemsTaskFactory.dll + $(MSBuildThisFileDirectory)..\tasks\net6.0\MonoTargetsTasks.dll + $(MSBuildThisFileDirectory)..\tasks\net472\MonoTargetsTasks.dll - + + + + + + + <_MonoRuntimeComponentSharedLibExt ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" /> <_MonoRuntimeComponentStaticLibExt ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" Output="true" /> diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeConfigParserTask.props b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeConfigParserTask.props deleted file mode 100644 index f81ae6a8bde35d..00000000000000 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/RuntimeConfigParserTask.props +++ /dev/null @@ -1,7 +0,0 @@ - - - $(MSBuildThisFileDirectory)..\tasks\net6.0\RuntimeConfigParser.dll - $(MSBuildThisFileDirectory)..\tasks\net472\RuntimeConfigParser.dll - - - diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/Sdk.props b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/Sdk.props index 8a7ede79242b1c..887d87842b47e2 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/Sdk.props +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Sdk/Sdk.props @@ -1,5 +1,3 @@ - - - + diff --git a/src/mono/wasm/build/README.md b/src/mono/wasm/build/README.md index 312b5308645c39..8d4920a7be5328 100644 --- a/src/mono/wasm/build/README.md +++ b/src/mono/wasm/build/README.md @@ -114,8 +114,8 @@ them for the new task assembly. 1. The task assembly dir, and its path need to be in two properties: ```xml - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'JsonToItemsTaskFactory', 'Debug', '$(NetCoreAppToolCurrent)')) - $([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoTargetsTasks', 'Debug', '$(NetCoreAppToolCurrent)')) + $([MSBuild]::NormalizePath('$(MonoTargetsTasksDir)', 'MonoTargetsTasks.dll')) ``` And this needs to be set in: diff --git a/src/mono/wasm/build/WasmApp.InTree.targets b/src/mono/wasm/build/WasmApp.InTree.targets index f8c26080f0268d..b4f2af25b0afd6 100644 --- a/src/mono/wasm/build/WasmApp.InTree.targets +++ b/src/mono/wasm/build/WasmApp.InTree.targets @@ -1,7 +1,7 @@ - + diff --git a/src/mono/wasm/build/WasmApp.LocalBuild.props b/src/mono/wasm/build/WasmApp.LocalBuild.props index e4fdffe990dece..939d6ce4eef85a 100644 --- a/src/mono/wasm/build/WasmApp.LocalBuild.props +++ b/src/mono/wasm/build/WasmApp.LocalBuild.props @@ -35,8 +35,7 @@ $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmAppBuilder', 'Debug', '$(_TargetFrameworkForNETCoreTasks)')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmBuildTasks', 'Debug', '$(_TargetFrameworkForNETCoreTasks)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoAOTCompiler', 'Debug', '$(_TargetFrameworkForNETCoreTasks)')) - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'RuntimeConfigParser', 'Debug', '$(_TargetFrameworkForNETCoreTasks)')) - $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'JsonToItemsTaskFactory', 'Debug', '$(_TargetFrameworkForNETCoreTasks)')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoTargetsTasks', 'Debug', '$(_TargetFrameworkForNETCoreTasks)')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'mono', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfig)')) <_MonoAotCrossCompilerPath>$([MSBuild]::NormalizePath($(MonoArtifactsPath), 'cross', '$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())', 'mono-aot-cross')) @@ -48,8 +47,7 @@ $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'microsoft.netcore.app.runtime.browser-wasm')) $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'MonoAOTCompiler')) - $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'RuntimeConfigParser')) - $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'JsonToItemsTaskFactory')) + $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'MonoTargetsTasks')) $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'WasmAppBuilder')) $([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'WasmBuildTasks')) @@ -67,8 +65,7 @@ $([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll')) $([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll')) $([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll')) - $([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll')) - $([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll')) + $([MSBuild]::NormalizePath('$(MonoTargetsTasksDir)', 'MonoTargetsTasks.dll')) diff --git a/src/mono/wasm/build/WasmApp.LocalBuild.targets b/src/mono/wasm/build/WasmApp.LocalBuild.targets index 47559bccb84288..65e328b9472975 100644 --- a/src/mono/wasm/build/WasmApp.LocalBuild.targets +++ b/src/mono/wasm/build/WasmApp.LocalBuild.targets @@ -22,7 +22,7 @@ - + true @@ -65,8 +65,7 @@ $([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll')) $([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll')) $([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll')) - $([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll')) - $([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll')) + $([MSBuild]::NormalizePath('$(MonoTargetsTasksDir)', 'MonoTargetsTasks.dll')) - diff --git a/src/tasks/ILStripTask/ILStrip.csproj b/src/tasks/ILStripTask/ILStrip.csproj deleted file mode 100644 index bb9c41f692e1cc..00000000000000 --- a/src/tasks/ILStripTask/ILStrip.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - $(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks) - Library - true - false - $(NoWarn),CA1050,CS0618,CS0649,CS8604,CS8602,CS8632,SYSLIB0003 - false - - - - - - - - - - - - - - - - - - <_PublishFramework Remove="@(_PublishFramework)" /> - <_PublishFramework Include="$(TargetFrameworks)" /> - - - - - - diff --git a/src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.csproj b/src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.csproj deleted file mode 100644 index 17799fbf6570c1..00000000000000 --- a/src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.csproj +++ /dev/null @@ -1,39 +0,0 @@ - - - $(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks) - Library - true - false - enable - - - - - - - - - - - - - - - - - - - - - - - - <_PublishFramework Remove="@(_PublishFramework)" /> - <_PublishFramework Include="$(TargetFrameworks)" /> - - - - - - - diff --git a/src/tasks/ILStripTask/ILStrip.cs b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs similarity index 75% rename from src/tasks/ILStripTask/ILStrip.cs rename to src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs index 8086e68b91785f..f1835b1fa5ecc9 100644 --- a/src/tasks/ILStripTask/ILStrip.cs +++ b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.cs @@ -1,87 +1,18 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.IO; using System.Collections; using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; using CilStrip.Mono.Cecil; using CilStrip.Mono.Cecil.Binary; using CilStrip.Mono.Cecil.Cil; using CilStrip.Mono.Cecil.Metadata; -public class ILStrip : Microsoft.Build.Utilities.Task +namespace AssemblyStripper { - /// - /// Assemblies to be stripped. - /// The assemblies will be modified in place if OutputPath metadata is not set. - /// - [Required] - public ITaskItem[] Assemblies { get; set; } = Array.Empty(); - - /// - /// Disable parallel stripping - /// - public bool DisableParallelStripping { get; set; } - - public override bool Execute() - { - if (Assemblies.Length == 0) - { - throw new ArgumentException($"'{nameof(Assemblies)}' is required.", nameof(Assemblies)); - } - - if (DisableParallelStripping) - { - foreach (var assemblyItem in Assemblies) - { - if (!StripAssembly(assemblyItem)) - return !Log.HasLoggedErrors; - } - } - else - { - Parallel.ForEach(Assemblies, - new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, - assemblyItem => StripAssembly(assemblyItem)); - } - - return !Log.HasLoggedErrors; - } - - private bool StripAssembly(ITaskItem assemblyItem) - { - string assemblyFile = assemblyItem.ItemSpec; - var outputPath = assemblyItem.GetMetadata("OutputPath"); - if (String.IsNullOrWhiteSpace(outputPath)) - { - outputPath = assemblyFile; - Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile}"); - } - else - { - Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile} to {outputPath}"); - } - - try - { - AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyFile); - AssemblyStripper.StripAssembly(assembly, outputPath); - } - catch (Exception ex) - { - Log.LogMessage(MessageImportance.Low, ex.ToString()); - Log.LogError($"ILStrip failed for {assemblyFile}: {ex.Message}"); - return false; - } - - return true; - } - - private class AssemblyStripper + public class AssemblyStripper { AssemblyDefinition assembly; BinaryWriter writer; @@ -266,12 +197,19 @@ void Write() stripped.MetadataRoot.Accept(metadata_writer); } - public static void StripAssembly(AssemblyDefinition assembly, string file) + internal static void StripAssembly(AssemblyDefinition assembly, string file) { using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None)) { new AssemblyStripper(assembly, new BinaryWriter(fs)).Strip(); } } + + public static void StripAssembly(string assemblyFile, string outputPath) + { + AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyFile); + AssemblyStripper.StripAssembly(assembly, outputPath); + + } } } diff --git a/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.csproj b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.csproj new file mode 100644 index 00000000000000..439b5b8b21b98c --- /dev/null +++ b/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper/AssemblyStripper.csproj @@ -0,0 +1,22 @@ + + + $(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks) + false + + disable + + $(NoWarn),CS0618,CS0649,SYSLIB0003 + + false + + + + + + + + + diff --git a/src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs b/src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs new file mode 100644 index 00000000000000..e5d6f0f0de5939 --- /dev/null +++ b/src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using CilStrip.Mono.Cecil; +using CilStrip.Mono.Cecil.Binary; +using CilStrip.Mono.Cecil.Cil; +using CilStrip.Mono.Cecil.Metadata; + +public class ILStrip : Microsoft.Build.Utilities.Task +{ + /// + /// Assemblies to be stripped. + /// The assemblies will be modified in place if OutputPath metadata is not set. + /// + [Required] + public ITaskItem[] Assemblies { get; set; } = Array.Empty(); + + /// + /// Disable parallel stripping + /// + public bool DisableParallelStripping { get; set; } + + public override bool Execute() + { + if (Assemblies.Length == 0) + { + throw new ArgumentException($"'{nameof(Assemblies)}' is required.", nameof(Assemblies)); + } + + int allowedParallelism = DisableParallelStripping ? 1 : Math.Min(Assemblies.Length, Environment.ProcessorCount); + if (BuildEngine is IBuildEngine9 be9) + allowedParallelism = be9.RequestCores(allowedParallelism); + ParallelLoopResult result = Parallel.ForEach(Assemblies, + new ParallelOptions { MaxDegreeOfParallelism = allowedParallelism }, + (assemblyItem, state) => + { + if (!StripAssembly(assemblyItem)) + state.Stop(); + }); + + if (!result.IsCompleted && !Log.HasLoggedErrors) + { + Log.LogError("Unknown failure occured while IL stripping assemblies. Check logs to get more details."); + } + + return !Log.HasLoggedErrors; + } + + private bool StripAssembly(ITaskItem assemblyItem) + { + string assemblyFile = assemblyItem.ItemSpec; + var outputPath = assemblyItem.GetMetadata("OutputPath"); + if (string.IsNullOrWhiteSpace(outputPath)) + { + outputPath = assemblyFile; + Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile}"); + } + else + { + Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile} to {outputPath}"); + } + + try + { + AssemblyStripper.AssemblyStripper.StripAssembly (assemblyFile, outputPath); + } + catch (Exception ex) + { + Log.LogMessage(MessageImportance.Low, ex.ToString()); + Log.LogError($"ILStrip failed for {assemblyFile}: {ex.Message}"); + return false; + } + + return true; + } + +} diff --git a/src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs b/src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs similarity index 98% rename from src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs rename to src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs index b0d710e77f7141..2134317e8927fd 100644 --- a/src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs +++ b/src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs @@ -12,17 +12,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -#if NET472 -namespace System.Diagnostics.CodeAnalysis { - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - - public class NotNullWhenAttribute : Attribute { - public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - public bool ReturnValue { get; } - } -} -#endif - namespace JsonToItemsTaskFactory { diff --git a/src/tasks/JsonToItemsTaskFactory/README.md b/src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/README.md similarity index 96% rename from src/tasks/JsonToItemsTaskFactory/README.md rename to src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/README.md index 619991ac13e993..aaebf91d761982 100644 --- a/src/tasks/JsonToItemsTaskFactory/README.md +++ b/src/tasks/MonoTargetsTasks/JsonToItemsTaskFactory/README.md @@ -34,7 +34,7 @@ Dictionary elements must have strings as values, and must include an `"Identity" To use the task, you need to reference the assembly and add the task to the project, as well as declare the task parameters that correspond to the properties and items you want to retrieve from the json blob. ```xml - diff --git a/src/tasks/RuntimeConfigParser/RuntimeConfigParser.csproj b/src/tasks/MonoTargetsTasks/MonoTargetsTasks.csproj similarity index 54% rename from src/tasks/RuntimeConfigParser/RuntimeConfigParser.csproj rename to src/tasks/MonoTargetsTasks/MonoTargetsTasks.csproj index c07e367def62ec..23b128cf333caf 100644 --- a/src/tasks/RuntimeConfigParser/RuntimeConfigParser.csproj +++ b/src/tasks/MonoTargetsTasks/MonoTargetsTasks.csproj @@ -1,40 +1,50 @@ $(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks) - Library - true false enable $(NoWarn),CA1050 - - $(NoWarn),CS8604,CS8602 - + - - + + + + + + + + + - + + + + + + + + - + <_PublishFramework Remove="@(_PublishFramework)" /> <_PublishFramework Include="$(TargetFrameworks)" /> + - diff --git a/src/tasks/RuntimeConfigParser/RuntimeConfigParser.cs b/src/tasks/MonoTargetsTasks/RuntimeConfigParser/RuntimeConfigParser.cs similarity index 100% rename from src/tasks/RuntimeConfigParser/RuntimeConfigParser.cs rename to src/tasks/MonoTargetsTasks/RuntimeConfigParser/RuntimeConfigParser.cs diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index 6ffee68f72477b..009a19e92c7753 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -37,7 +37,7 @@ %(Identity) - + @@ -147,13 +147,13 @@ TargetDir="WasmAppBuilder/"/> - + diff --git a/src/tests/Common/wasm-test-runner/WasmTestRunner.proj b/src/tests/Common/wasm-test-runner/WasmTestRunner.proj index e2eda44d7ffc02..ab92b77866e3c3 100644 --- a/src/tests/Common/wasm-test-runner/WasmTestRunner.proj +++ b/src/tests/Common/wasm-test-runner/WasmTestRunner.proj @@ -15,8 +15,7 @@ $(CORE_ROOT)\WasmAppBuilder\WasmAppBuilder.dll $(CORE_ROOT)\MonoAOTCompiler\MonoAOTCompiler.dll - $(CORE_ROOT)\JsonToItemsTaskFactory\JsonToItemsTaskFactory.dll - $(CORE_ROOT)\RuntimeConfigParser\RuntimeConfigParser.dll + $(CORE_ROOT)\MonoTargetsTasks\MonoTargetsTasks.dll BuildApp;$(WasmBuildAppDependsOn) diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index b817490bbdf6f5..43b57f5aa14e75 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -378,14 +378,10 @@ Include="$(ArtifactsBinDir)\MonoAOTCompiler\Debug\$(NetCoreAppToolCurrent)\**" TargetDir="MonoAOTCompiler/"/> + - - - + Include="$(ArtifactsBinDir)\MonoTargetsTasks\Debug\$(NetCoreAppToolCurrent)\**" + TargetDir="MonoTargetsTasks/"/>