-
Notifications
You must be signed in to change notification settings - Fork 826
[WIP] Auto-generate IlLink.Substitutions.xml to Remove F# Metadata Resources #18592
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
Draft
Copilot
wants to merge
11
commits into
main
Choose a base branch
from
copilot/fix-18591
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0cd324b
Initial plan for issue
Copilot e01d09d
Merge branch 'main' into copilot/fix-18591
T-Gro 3912a52
Merge branch 'main' into copilot/fix-18591
T-Gro ab29090
Merge branch 'main' into copilot/fix-18591
T-Gro 3aff8db
Implement GenerateILLinkSubstitutions task for F# metadata trimming
Copilot 793060a
Add test for F# metadata resource trimming
Copilot d7202c8
Address PR feedback on ILLink.Substitutions.xml generation
Copilot 4b8ac74
Update src/FSharp.Build/GenerateILLinkSubstitutions.fs
T-Gro 67dafd8
Merge branch 'main' into copilot/fix-18591
T-Gro b4058d7
Merge branch 'main' into copilot/fix-18591
T-Gro 28d99ca
Update check.ps1 to report actual file sizes when expected length is …
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Build | ||
|
||
open System | ||
open System.IO | ||
open System.Text | ||
open Microsoft.Build.Framework | ||
open Microsoft.Build.Utilities | ||
|
||
/// <summary> | ||
/// MSBuild task that generates ILLink.Substitutions.xml file to remove F# metadata resources during IL linking. | ||
/// </summary> | ||
type GenerateILLinkSubstitutions() = | ||
inherit Task() | ||
|
||
/// <summary> | ||
/// Assembly name to use when generating resource names to be removed. | ||
/// </summary> | ||
[<Required>] | ||
member val AssemblyName = "" with get, set | ||
|
||
/// <summary> | ||
/// Intermediate output path for storing the generated file. | ||
/// </summary> | ||
[<Required>] | ||
member val IntermediateOutputPath = "" with get, set | ||
|
||
/// <summary> | ||
/// Generated embedded resource items. | ||
/// </summary> | ||
[<Output>] | ||
member val GeneratedItems = [| |] : ITaskItem[] with get, set | ||
|
||
override this.Execute() = | ||
try | ||
// Define the resource prefixes that need to be removed | ||
let resourcePrefixes = | ||
[| | ||
// Signature variants | ||
yield! [| for dataType in [| "Data"; "DataB" |] do | ||
for compression in [| ""; "Compressed" |] do | ||
yield $"FSharpSignature{compression}{dataType}" |] | ||
|
||
// Optimization variants | ||
yield! [| for dataType in [| "Data"; "DataB" |] do | ||
for compression in [| ""; "Compressed" |] do | ||
yield $"FSharpOptimization{compression}{dataType}" |] | ||
|
||
// Info variants | ||
yield "FSharpOptimizationInfo" | ||
yield "FSharpSignatureInfo" | ||
|] | ||
|
||
// Generate the XML content | ||
let sb = StringBuilder(4096) // pre-allocate capacity | ||
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>") |> ignore | ||
sb.AppendLine("<linker>") |> ignore | ||
sb.AppendLine($" <assembly fullname=\"{this.AssemblyName}\">") |> ignore | ||
|
||
// Add each resource entry with proper closing tag on the same line | ||
for prefix in resourcePrefixes do | ||
sb.AppendLine($" <resource name=\"{prefix}.{this.AssemblyName}\" action=\"remove\"></resource>") |> ignore | ||
|
||
// Close assembly and linker tags | ||
sb.AppendLine(" </assembly>") |> ignore | ||
sb.AppendLine("</linker>") |> ignore | ||
|
||
let xmlContent = sb.ToString() | ||
|
||
// Create a file in the intermediate output path | ||
let outputFileName = Path.Combine(this.IntermediateOutputPath, "ILLink.Substitutions.xml") | ||
Directory.CreateDirectory(this.IntermediateOutputPath) |> ignore | ||
File.WriteAllText(outputFileName, xmlContent) | ||
|
||
// Create a TaskItem for the generated file | ||
let item = TaskItem(outputFileName) :> ITaskItem | ||
item.SetMetadata("LogicalName", "ILLink.Substitutions.xml") | ||
|
||
this.GeneratedItems <- [| item |] | ||
true | ||
with ex -> | ||
this.Log.LogErrorFromException(ex, true) | ||
false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...Trimming/FSharpMetadataResource_Trimming_Test/FSharpMetadataResource_Trimming_Test.fsproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net9.0</TargetFrameworks> | ||
<LangVersion>preview</LangVersion> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> | ||
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder> | ||
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
T-Gro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../../artifacts/bin/fsc/Release/net9.0/fsc.dll</DotnetFscCompilerPath> | ||
<Fsc_DotNET_DotnetFscCompilerPath>$(MSBuildThisFileDirectory)../../../../artifacts/bin/fsc/Release/net9.0/fsc.dll</Fsc_DotNET_DotnetFscCompilerPath> | ||
<FSharpBuildAssemblyFile>$(MSBuildThisFileDirectory)../../../../artifacts/bin/FSharp.Build/Release/net9.0/FSharp.Build.dll</FSharpBuildAssemblyFile> | ||
<FSharpPreferNetFrameworkTools>False</FSharpPreferNetFrameworkTools> | ||
<FSharpPrefer64BitTools>True</FSharpPrefer64BitTools> | ||
</PropertyGroup> | ||
|
||
<!-- Import the custom targets file directly from the repository to use the latest version --> | ||
<Import Project="$(MSBuildThisFileDirectory)../../../../src/FSharp.Build/Microsoft.FSharp.NetSdk.props" /> | ||
<Import Project="$(MSBuildThisFileDirectory)../../../../src/FSharp.Build/Microsoft.FSharp.NetSdk.targets" /> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\Program.fs" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(MSBuildThisFileDirectory)../../../../eng/Versions.props" /> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FSharp.Core" Version="$(FSharpCorePreviewPackageVersionValue)"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.