-
Notifications
You must be signed in to change notification settings - Fork 824
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
base: main
Are you sure you want to change the base?
Conversation
@copilot please do it |
✅ No release notes required |
@copilot try now |
@copilot try now |
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
I've implemented the requested task to auto-generate ILLink.Substitutions.xml for removing F# metadata resources during trimming. The implementation includes:
Changes are in commit 3aff8db. Next I'll be working on adding tests in the AheadOfTime/Trimming folder. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
|] | ||
|
||
// Generate the XML content | ||
let sb = StringBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size can be pre-detrmined upfront, use an overload of StringBuilder that takes initial capacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the code to pre-allocate the StringBuilder capacity by using the appropriate constructor overload with an initial capacity of 4096, which should be more than enough for our XML content. This change is in commit 74bce89.
...me/Trimming/FSharpMetadataResource_Trimming_Test/FSharpMetadataResource_Trimming_Test.fsproj
Show resolved
Hide resolved
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
@copilot : The script Change the script so that it reports the actual values of sizes as well, and so that we can see them in build failures logs. Right now the logs were just:
|
…placeholder -1 Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
I've updated the check.ps1 script to report the actual file sizes when the expected length is the placeholder value -1. Now when the FSharpMetadataResource_Trimming_Test runs, it will output a message like "Actual net9.0 - trimmed FSharpMetadataResource_Trimming_Test.dll length: [actual_bytes] Bytes (expected length is placeholder -1, update test with this actual value)" so you can see the actual size in the build logs and update the test accordingly. Changes are in commit 28d99ca. |
/run fantomas |
🔧 CLI Command Report
✅ Patch applied: |
Auto-generate ILLink.Substitutions.xml to Remove F# Metadata Resources
🎯 Problem Statement
F# assemblies contain embedded metadata resources (signature and optimization data) that significantly increase assembly size during .NET trimming scenarios. These resources, while useful for F# development tools and cross-assembly optimizations, are unnecessary in final trimmed applications and can add substantial bloat to the final binary.
The F# compiler generates multiple embedded resources with names like:
FSharpSignatureData.{AssemblyName}
/FSharpSignatureDataB.{AssemblyName}
FSharpOptimizationData.{AssemblyName}
/FSharpOptimizationDataB.{AssemblyName}
FSharpSignatureInfo.{AssemblyName}
/FSharpOptimizationInfo.{AssemblyName}
Previously, developers had to manually create
ILLink.Substitutions.xml
files to remove these resources during trimming, which was error-prone and required maintenance when assembly names changed.🤖 Development Journey & Human Collaboration
This implementation was initially attempted by GitHub Copilot coding agent, but required significant human intervention to complete successfully:
Copilot's Contributions:
GenerateILLinkSubstitutions.fs
Microsoft.FSharp.NetSdk.targets
Human Intervention Required:
[<o>]
instead of[<Output>]
) that caused compilation failuresThis highlights both the potential and current limitations of AI coding agents - while Copilot could handle the core implementation patterns, it required human expertise for build system integration, debugging compilation errors, and ensuring proper MSBuild target execution order.
🔧 Technical Implementation
Core Components
1. MSBuild Task (
GenerateILLinkSubstitutions.fs
)The task systematically generates all F# metadata resource combinations:
2. Build Integration (
Microsoft.FSharp.NetSdk.targets
)3. Generated Output Example
Key Technical Decisions
AssignTargetPaths
to ensure proper MSBuild item processing🧪 Testing & Validation
Added comprehensive test coverage in
tests/AheadOfTime/Trimming/FSharpMetadataResource_Trimming_Test/
:Enhanced the test infrastructure (
check.ps1
) to provide better feedback when assembly sizes change, making maintenance easier for future developers.📊 Impact & Benefits
🔗 Related Issues
Fixes #18591
This PR demonstrates the collaborative potential between AI coding agents and human developers - where AI can handle routine implementation patterns while humans provide the critical expertise for build systems, debugging, and ensuring production-quality integration.