Skip to content

Commit 8c4f870

Browse files
committed
Emit '[Embedded]' attribute
1 parent b13f2d5 commit 8c4f870

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.Runt
6666
/// </summary>
6767
private readonly ConcurrentDictionary<GeneratedType, SourceText> manifestSources = new();
6868

69+
/// <summary>
70+
/// Emits any sources that are needed right after initialization.
71+
/// </summary>
72+
/// <param name="context">The input <see cref="IncrementalGeneratorPostInitializationContext"/> value to use.</param>
73+
private static void EmitPostInitializationSources(IncrementalGeneratorPostInitializationContext context)
74+
{
75+
// Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid
76+
// conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'.
77+
// When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors.
78+
context.AddEmbeddedAttributeDefinition();
79+
}
80+
6981
/// <summary>
7082
/// Extracts the <see cref="GenerationOptions"/> value for the current generation.
7183
/// </summary>

src/PolySharp.SourceGenerators/PolyfillsGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public sealed partial class PolyfillsGenerator : IIncrementalGenerator
1313
/// <inheritdoc/>
1414
public void Initialize(IncrementalGeneratorInitializationContext context)
1515
{
16+
// Emit any sources that are needed right after initialization
17+
context.RegisterPostInitializationOutput(EmitPostInitializationSources);
18+
1619
// Prepare all the generation options in a single incremental model
1720
IncrementalValueProvider<GenerationOptions> generationOptions =
1821
context.AnalyzerConfigOptionsProvider

0 commit comments

Comments
 (0)