-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split server-only (grains) APIs to our Server package
Related codegen is also moved there, with a detection for the project having the server package installed. Due to an issue with Orleans codec generation (see dotnet/orleans#9092), end to end tests are failing since state is not being properly serialized for actor messages. We can only ship this rework once that's fixed. Otherwise, we'll need to move serialization codegen back to the actor/domain project (which unfortunately brings a larger dependency on Orleans, which is undesirable).
- Loading branch information
Showing
23 changed files
with
173 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,25 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Devlooped.CloudActors; | ||
|
||
[Generator(LanguageNames.CSharp)] | ||
public class CloudActorsGenerator : IIncrementalGenerator | ||
{ | ||
public void Initialize(IncrementalGeneratorInitializationContext context) | ||
{ | ||
context.RegisterImplementationSourceOutput(context.CompilationProvider, (ctx, compilation) => | ||
{ | ||
ctx.AddSource($"CloudActors.cs", | ||
$$""" | ||
// <auto-generated/> | ||
[assembly: Devlooped.CloudActors] | ||
namespace Devlooped | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.Assembly)] | ||
class CloudActorsAttribute : System.Attribute { } | ||
} | ||
"""); | ||
}); | ||
} | ||
} |
File renamed without changes.
This file contains 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
62 changes: 62 additions & 0 deletions
62
src/CloudActors.Server.CodeAnalysis/ActorsAssemblyGenerator.cs
This file contains 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,62 @@ | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
using static Devlooped.CloudActors.AnalysisExtensions; | ||
|
||
namespace Devlooped.CloudActors; | ||
|
||
/// <summary> | ||
/// Analyzes referenced assemblies from current compilation and emits an attribute | ||
/// for each one that instructs the Orleans code generator to inspect the assembly | ||
/// and generate code for it: GenerateCodeForDeclaringAssembly. | ||
/// This allows us to avoid polluting the domain/actor assemblies with Orleans-specifics | ||
/// other than the [GenerateSerializer] attribute and state classes, but which have no | ||
/// implementations. Grains and everything else are generated in the project referencing | ||
/// the Orleans.Server package only. | ||
/// </summary> | ||
[Generator(LanguageNames.CSharp)] | ||
public class ActorsAssemblyGenerator : IIncrementalGenerator | ||
{ | ||
public void Initialize(IncrementalGeneratorInitializationContext context) | ||
{ | ||
var options = context.GetOrleansOptions(); | ||
var assemblies = context.CompilationProvider | ||
.SelectMany((x, _) => x.GetUsedAssemblyReferences().Select(r => new { Compilation = x, Reference = r })) | ||
.Select((x, _) => x.Compilation.GetAssemblyOrModuleSymbol(x.Reference)) | ||
.Where(x => x is IAssemblySymbol asm && asm.GetAttributes().Any( | ||
a => "Devlooped.CloudActorsAttribute".Equals(a.AttributeClass?.ToDisplayString(FullName)))) | ||
.Select((x, _) => (IAssemblySymbol)x!) | ||
.Collect(); | ||
|
||
context.RegisterImplementationSourceOutput(assemblies.Combine(options), GenerateCode); | ||
} | ||
|
||
static void GenerateCode(SourceProductionContext ctx, (ImmutableArray<IAssemblySymbol>, OrleansGeneratorOptions) source) | ||
{ | ||
var (assemblies, options) = source; | ||
|
||
// Don't duplicate any of the already generated code for the current assembly | ||
options = options with { Compilation = options.Compilation.RemoveAllSyntaxTrees() }; | ||
|
||
var output = new StringBuilder().AppendLine( | ||
""" | ||
// <auto-generated/> | ||
using Orleans; | ||
"""); | ||
|
||
foreach (var type in assemblies.Select(x => x.GetAllTypes() | ||
.FirstOrDefault(x => x.ContainingType == null && options.Compilation.IsSymbolAccessibleWithin(x, options.Compilation.Assembly)))) | ||
{ | ||
if (type == null) | ||
continue; | ||
|
||
// [assembly: GenerateCodeForDeclaringAssembly(typeof(TestDomain.Account))] | ||
output.AppendLine($"[assembly: GenerateCodeForDeclaringAssembly(typeof({type.ToDisplayString(FullName)}))]"); | ||
} | ||
|
||
var orleans = OrleansGenerator.GenerateCode(options, output.ToString(), "References", ctx.CancellationToken); | ||
|
||
ctx.AddSource($"CloudActors.orleans.cs", orleans); | ||
} | ||
} |
This file contains 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
11 changes: 11 additions & 0 deletions
11
src/CloudActors.Server.CodeAnalysis/Devlooped.CloudActors.Server.targets
This file contains 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,11 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<IsCloudActorsServer>true</IsCloudActorsServer> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<CompilerVisibleProperty Include="IsCloudActorsServer" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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
8 changes: 8 additions & 0 deletions
8
src/CloudActors.Server.CodeAnalysis/Properties/launchSettings.json
This file contains 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,8 @@ | ||
{ | ||
"profiles": { | ||
"CodeAnalysis": { | ||
"commandName": "DebugRoslynComponent", | ||
"targetProject": "..\\Tests\\Tests.csproj" | ||
} | ||
} | ||
} |
This file contains 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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 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.