-
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
Changes from 7 commits
0cd324b
e01d09d
3912a52
ab29090
3aff8db
793060a
d7202c8
4b8ac74
67dafd8
b4058d7
28d99ca
d4d92dc
18cb57d
b0a0781
dfeaf0e
96859b6
072d69c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
[<o>] | ||
Check failure on line 32 in src/FSharp.Build/GenerateILLinkSubstitutions.fs
|
||
T-Gro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
member val GeneratedItems = [| |] : ITaskItem[] with get, set | ||
|
||
T-Gro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
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> |
Uh oh!
There was an error while loading. Please reload this page.