Skip to content

Commit 66d606a

Browse files
authored
[3.0] Overhaul SilkTouch configuration and DI (#2624)
* Initial commit for feature/silktouch-config-overhaul * Add Autofac and adapt the existing IServiceCollection code to use it * Remove EvaluatedConstant since this is old code and we can evaluate using Roslyn now * Begin removing keyed resolution and JSON config reading code * Remove IJobDependency/JobDependencies * Begin reworking SilkTouchGenerator * Combine IModContextProvider and IModContext because Provider's main job is to handle keyed resolution * Update mods to not use IOptionsSnapshot nor IJobDependency * Trim ServiceCollectionExtensions to isolate the code I need to keep * Work on new composition root * Get new setup roughly implemented and fix all compile errors * Remove old generator Resolve call * Removes jobs from SilkTouchConfiguration and fix private field naming * Remove unhelpful doc * Add ModRegistrationExtensions * Add RegisterMod helper * Add RegisterClangScraper * Use collection expressions for CLI option definitions * Fix Program class not being static * Implement generator job parallelism setting * Work on registration API * Translate Vulkan job JSON into C# * Replace RegisterMod helper with AsHierarchyAndInterfaces * Add separate SilkTouchModRegistrationContext for registering mods * Move function transformer registrations to TransformFunctions registration method * Also register FunctionTransformer alongside TransformFunctions * Use WithParameter to specifically inject the config param into each mod instead of registering it separately Mods shouldn't peek into other mod configs and this lets us register multiple of the same mod more easily. * Update CSharpier tool * Format SilkTouchRegistrationExtensions * Add extra spacing since CSharpier formatting is hard to read with fluent chains * Remove "DON'T USE CONSTRUCTOR-STYLE RECORDS" warning comments, no longer relevant * Change AddVTables Configuration to accept VTable types instead of IConfigurationSection * Add IModContextProvider back, but rename to IModContextFactory * Fix incorrect generator config * Migrate MS DI registration to use Autofac * Add SilkTouchHost class * Move Vulkan job definition to Program from SilkTouchHost * Add todos and edit docs * Rename parameter * Add new Silk.NET.SilkTouch.Jobs project * Migrate generator.json jobs to SilkTouch.Jobs * Split jobs into multiple files for readability and to save my scroll wheel * Fix compile errors in SilkTouch test project * Fix incorrect default AddVTables config * Remove usages ThreadLocals and JobKey when used for keyed resolution/job isolation * Remove more job key usages * Cleanup a few more job key usages * Change SilkTouchJob to be internal * Add registration methods for the different function transformers and update job definitions Microsoft also gets the default transformers added to match how the old DI setup always had them registered. * Generate all bindings except Microsoft on Windows * Add start of DocumentFactory * Work on DocumentFactory * Work on DocumentFactory API * Ensure using directives are well ordered * Implement DocumentFactory syntax walker and rewriter * Add using statement sorting to DocumentFactory * Register DocumentFactory by default * Handle headers during document initialization * Remove a few usages of ModCSharpSyntaxRewriter * Fix incorrect using directive sort order Forgot that these weren't bare namespaces. * Initialize the DocumentFactory with the default license header * Remove Mod class (not IMod) * Replace common namespace identification with a DefaultNamespace config option * Assume base.VisitCompilationUnit does not return null * Have DocumentFactory add a default namespace to documents without them * Remove header injection handling from MSBuildModContext * Update IModContext.WorkingDirectory doc comment * Work on removing ModCSharpSyntaxRewriter * Update remaining usages of ModCSharpSyntaxRewriter * Update mods to use DocumentFactory when adding documents * Fix duplicated doc header * Move SDL3 header txt up one level to match the other bindings * Change DefaultLicenseHeader to specify the API-specific header file for each job * Edit doc comment * Update and fix unit tests * Regenerate all bindings except Microsoft on Windows * Have AddVTables add using System.Runtime.CompilerServices to all vtables generated * Rework how using statements are gathered (WIP) * Rework how ClangScraper outputs documents * Cleanup * Unify the scrape and read from cache paths of ClangScraper This was driving me crazy * Fix source documents being dropped * Fix using statement formatting * Isolate using statements added by AddVTables * Regenerate all bindings except Microsoft on Windows * Move solution loading back to MSBuildModContextFactory * Fix solution cache race condition causing the solution to be loaded multiple times * Edit docs for SilkTouchHost * Update the using-the-generator docs * Update generator-mods docs * Fix incorrect branch used for docs links * Move GetLongestCommonPrefix and GetLongestCommonPath to ClangScraper * Remove WithMods
1 parent 76913ed commit 66d606a

916 files changed

Lines changed: 4036 additions & 3455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.config/dotnet-tools.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"csharpier": {
6-
"version": "0.29.2",
6+
"version": "1.3.0",
77
"commands": [
8-
"dotnet-csharpier"
9-
]
8+
"csharpier"
9+
],
10+
"rollForward": false
1011
}
1112
}
1213
}

‎.silktouch/openal-clangsharp.stout‎

0 Bytes
Binary file not shown.

‎.silktouch/opencl-clangsharp.stout‎

232 Bytes
Binary file not shown.

‎.silktouch/opengl-clangsharp.stout‎

0 Bytes
Binary file not shown.

‎.silktouch/openxr-clangsharp.stout‎

-6.05 KB
Binary file not shown.

‎.silktouch/sdl-clangsharp.stout‎

35 Bytes
Binary file not shown.

‎.silktouch/vulkan-clangsharp.stout‎

190 KB
Binary file not shown.

‎Directory.Packages.props‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<!-- Analyzers -->
2222
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0" />
2323
<!-- SilkTouch -->
24+
<PackageVersion Include="Autofac" Version="9.3.4" />
25+
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="11.0.2" />
2426
<PackageVersion Include="ClangSharp.PInvokeGenerator" Version="21.1.8.4" />
2527
<PackageVersion Include="CSharpier.Core" Version="1.3.0" />
2628
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />

‎Silk.NET.slnx‎

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
11
<Solution>
2-
<Folder Name="/docs/">
3-
<File Path="docs/CHANGELOG.md" />
4-
<File Path="docs/CODEOWNERS" />
5-
<File Path="docs/CODE_OF_CONDUCT.md" />
6-
<File Path="docs/CONTRIBUTING.md" />
7-
<File Path="docs/README.md" />
8-
</Folder>
9-
<Folder Name="/eng/">
10-
<Project Path="eng/build/Silk.NET.NUKE.csproj" />
11-
</Folder>
12-
<Folder Name="/eng/benchmarks/">
13-
<Project Path="eng/benchmarks/Silk.NET.Maths.Benchmarks/Silk.NET.Maths.Benchmarks.csproj" />
14-
</Folder>
15-
<Folder Name="/examples/" />
16-
<Folder Name="/examples/CSharp/" />
17-
<Folder Name="/examples/CSharp/OpenAL/">
18-
<Project Path="examples/CSharp/OpenAL/Tutorial001.HelloSound/OpenAL.Tutorial001.HelloSound.csproj" />
19-
</Folder>
2+
<Folder Name="/docs/">
3+
<File Path="docs/CHANGELOG.md" />
4+
<File Path="docs/CODEOWNERS" />
5+
<File Path="docs/CODE_OF_CONDUCT.md" />
6+
<File Path="docs/CONTRIBUTING.md" />
7+
<File Path="docs/README.md" />
8+
</Folder>
9+
<Folder Name="/eng/">
10+
<Project Path="eng/build/Silk.NET.NUKE.csproj" />
11+
</Folder>
12+
<Folder Name="/eng/benchmarks/">
13+
<Project Path="eng/benchmarks/Silk.NET.Maths.Benchmarks/Silk.NET.Maths.Benchmarks.csproj" />
14+
</Folder>
15+
<Folder Name="/examples/" />
16+
<Folder Name="/examples/CSharp/" />
17+
<Folder Name="/examples/CSharp/OpenAL/">
18+
<Project Path="examples/CSharp/OpenAL/Tutorial001.HelloSound/OpenAL.Tutorial001.HelloSound.csproj" />
19+
</Folder>
2020
<Folder Name="/examples/CSharp/OpenCL/">
2121
<Project Path="examples/CSharp/OpenCL/Tutorial001.SimpleKernel/OpenCL.Tutorial001.SimpleKernel.csproj" />
2222
</Folder>
23-
<Folder Name="/examples/CSharp/SDL/">
24-
<Project Path="examples/CSharp/SDL/Tutorial001.HelloWindow/SDL.Tutorial001.HelloWindow.csproj" />
25-
</Folder>
26-
<Folder Name="/scripts/">
27-
<File Path="scripts/azure-pipelines.yml" />
28-
<File Path="scripts/build.ps1" />
29-
<File Path="scripts/build.sh" />
30-
<File Path="scripts/cibuild.cmd" />
31-
<File Path="scripts/cibuild.sh" />
32-
</Folder>
33-
<Folder Name="/Solution Items/">
34-
<File Path=".editorconfig" />
35-
<File Path=".gitattributes" />
36-
<File Path=".gitignore" />
37-
<File Path="Directory.Build.props" />
38-
<File Path="Directory.Build.targets" />
39-
<File Path="Directory.Packages.props" />
40-
<File Path="generator.json" />
41-
<File Path="LICENSE.md" />
42-
<File Path="Silk.NET.sln.DotSettings" />
43-
</Folder>
44-
<Folder Name="/sources/">
45-
<File Path="sources/Directory.Build.props" />
46-
<File Path="sources/Directory.Build.targets" />
47-
<Project Path="sources/Playground/Playground.csproj" />
48-
</Folder>
49-
<Folder Name="/sources/Core/">
50-
<Project Path="sources/Core/Core/Silk.NET.Core.csproj" />
51-
<Project Path="sources/Core/Silk.NET/Silk.NET.csproj" />
52-
</Folder>
53-
<Folder Name="/sources/Maths/">
54-
<Project Path="sources/Maths/Maths/Silk.NET.Maths.csproj" />
55-
</Folder>
56-
<Folder Name="/sources/OpenAL/">
57-
<Project Path="sources/OpenAL/OpenAL/Silk.NET.OpenAL.csproj" />
58-
<Project Path="sources/OpenAL/Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj" />
59-
</Folder>
60-
<Folder Name="/sources/OpenCL/">
61-
<Project Path="sources/OpenCL/OpenCL/Silk.NET.OpenCL.csproj" />
62-
</Folder>
63-
<Folder Name="/sources/OpenGL/">
64-
<Project Path="sources/OpenGL/OpenGL/Silk.NET.OpenGL.csproj" />
65-
</Folder>
66-
<Folder Name="/sources/OpenXR/">
67-
<Project Path="sources/OpenXR/OpenXR/Silk.NET.OpenXR.csproj" />
68-
</Folder>
69-
<Folder Name="/sources/SDL/">
70-
<Project Path="sources/SDL/Native/Silk.NET.SDL.Native.csproj" />
71-
<Project Path="sources/SDL/SDL/Silk.NET.SDL.csproj" />
72-
</Folder>
73-
<Folder Name="/sources/SilkTouch/">
74-
<Project Path="sources/SilkTouch/SilkTouch/Silk.NET.SilkTouch.csproj" />
75-
</Folder>
76-
<Folder Name="/sources/Vulkan/">
77-
<Project Path="sources/Vulkan/Vulkan/Silk.NET.Vulkan.csproj" />
78-
</Folder>
79-
<Folder Name="/sources/Win32/" />
80-
<Folder Name="/sources/Windowing/">
81-
<Project Path="sources/Windowing/Windowing/Silk.NET.Windowing.csproj" />
82-
</Folder>
83-
<Folder Name="/tests/">
84-
<File Path="tests/Directory.Build.props" />
85-
<File Path="tests/Directory.Build.targets" />
86-
</Folder>
87-
<Folder Name="/tests/Core/">
88-
<Project Path="tests/Core/Core/Silk.NET.Core.UnitTests.csproj" />
89-
</Folder>
90-
<Folder Name="/tests/Maths/">
91-
<Project Path="tests/Maths/Maths/Silk.NET.Maths.Tests.csproj" />
92-
</Folder>
93-
<Folder Name="/tests/SDL/">
94-
<Project Path="tests/SDL/SDL/Silk.NET.SDL.UnitTests.csproj" />
95-
</Folder>
96-
<Folder Name="/tests/SilkTouch/">
97-
<Project Path="tests/SilkTouch/SilkTouch/Silk.NET.SilkTouch.UnitTests.csproj" />
98-
</Folder>
23+
<Folder Name="/examples/CSharp/SDL/">
24+
<Project Path="examples/CSharp/SDL/Tutorial001.HelloWindow/SDL.Tutorial001.HelloWindow.csproj" />
25+
</Folder>
26+
<Folder Name="/scripts/">
27+
<File Path="scripts/azure-pipelines.yml" />
28+
<File Path="scripts/build.ps1" />
29+
<File Path="scripts/build.sh" />
30+
<File Path="scripts/cibuild.cmd" />
31+
<File Path="scripts/cibuild.sh" />
32+
</Folder>
33+
<Folder Name="/Solution Items/">
34+
<File Path=".editorconfig" />
35+
<File Path=".gitattributes" />
36+
<File Path=".gitignore" />
37+
<File Path="Directory.Build.props" />
38+
<File Path="Directory.Build.targets" />
39+
<File Path="Directory.Packages.props" />
40+
<File Path="LICENSE.md" />
41+
<File Path="Silk.NET.sln.DotSettings" />
42+
</Folder>
43+
<Folder Name="/sources/">
44+
<File Path="sources/Directory.Build.props" />
45+
<File Path="sources/Directory.Build.targets" />
46+
<Project Path="sources/Playground/Playground.csproj" />
47+
</Folder>
48+
<Folder Name="/sources/Core/">
49+
<Project Path="sources/Core/Core/Silk.NET.Core.csproj" />
50+
<Project Path="sources/Core/Silk.NET/Silk.NET.csproj" />
51+
</Folder>
52+
<Folder Name="/sources/Maths/">
53+
<Project Path="sources/Maths/Maths/Silk.NET.Maths.csproj" />
54+
</Folder>
55+
<Folder Name="/sources/OpenAL/">
56+
<Project Path="sources/OpenAL/OpenAL/Silk.NET.OpenAL.csproj" />
57+
<Project Path="sources/OpenAL/Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj" />
58+
</Folder>
59+
<Folder Name="/sources/OpenCL/">
60+
<Project Path="sources/OpenCL/OpenCL/Silk.NET.OpenCL.csproj" />
61+
</Folder>
62+
<Folder Name="/sources/OpenGL/">
63+
<Project Path="sources/OpenGL/OpenGL/Silk.NET.OpenGL.csproj" />
64+
</Folder>
65+
<Folder Name="/sources/OpenXR/">
66+
<Project Path="sources/OpenXR/OpenXR/Silk.NET.OpenXR.csproj" />
67+
</Folder>
68+
<Folder Name="/sources/SDL/">
69+
<Project Path="sources/SDL/Native/Silk.NET.SDL.Native.csproj" />
70+
<Project Path="sources/SDL/SDL/Silk.NET.SDL.csproj" />
71+
</Folder>
72+
<Folder Name="/sources/SilkTouch/">
73+
<Project Path="sources/SilkTouch/Jobs/Silk.NET.SilkTouch.Jobs.csproj" />
74+
<Project Path="sources/SilkTouch/SilkTouch/Silk.NET.SilkTouch.csproj" />
75+
</Folder>
76+
<Folder Name="/sources/Vulkan/">
77+
<Project Path="sources/Vulkan/Vulkan/Silk.NET.Vulkan.csproj" />
78+
</Folder>
79+
<Folder Name="/sources/Win32/" />
80+
<Folder Name="/sources/Windowing/">
81+
<Project Path="sources/Windowing/Windowing/Silk.NET.Windowing.csproj" />
82+
</Folder>
83+
<Folder Name="/tests/">
84+
<File Path="tests/Directory.Build.props" />
85+
<File Path="tests/Directory.Build.targets" />
86+
</Folder>
87+
<Folder Name="/tests/Core/">
88+
<Project Path="tests/Core/Core/Silk.NET.Core.UnitTests.csproj" />
89+
</Folder>
90+
<Folder Name="/tests/Maths/">
91+
<Project Path="tests/Maths/Maths/Silk.NET.Maths.Tests.csproj" />
92+
</Folder>
93+
<Folder Name="/tests/SDL/">
94+
<Project Path="tests/SDL/SDL/Silk.NET.SDL.UnitTests.csproj" />
95+
</Folder>
96+
<Folder Name="/tests/SilkTouch/">
97+
<Project Path="tests/SilkTouch/SilkTouch/Silk.NET.SilkTouch.UnitTests.csproj" />
98+
</Folder>
9999
</Solution>

‎docs/for-contributors/Generator/generator-mods.md‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ ideally, no communication is done at all so that mods are kept completely standa
2727

2828
### Mod Configuration
2929

30-
Mods are configured through the generator config JSON file. Silk's config file is named `generator.json` and is located
31-
at the root of the Silk.NET repository. This config file can be used as reference for your own config files. In
32-
addition, most mods have a configuration class located in their source code with additional documentation.
30+
Mods are configured as part of bindings generation jobs in a separate C# project. Silk's own configuration project is
31+
the
32+
[`Silk.NET.SilkTouch.Jobs`](https://github.com/dotnet/Silk.NET/blob/develop/3.0/sources/SilkTouch/Jobs/Program.cs)
33+
project. This project can be used as reference for your own SilkTouch configuration projects. More information about
34+
using the SilkTouch generator can be found in the [Using the Generator](using-the-generator.md) documentation.
3335

3436
## Available Mods
3537

@@ -186,7 +188,7 @@ development and iteration, the generator is typically set up so that platform-sp
186188

187189
Usage recommendations:
188190

189-
This mod is configured differently from the rest of the mods. The JSON mod configuration follows the same pattern as the
191+
This mod is configured differently from the rest of the mods. The C# mod configuration follows the same pattern as the
190192
rest of the mods, but the bulk of the configuration comes in the form of `.rsp` files. These `.rsp` files represent the
191193
command line arguments passed to ClangSharpPInvokeGenerator. More information about how to use this mod and how to
192194
configure the generator as a whole is found in the [Using the Generator](using-the-generator.md) documentation.
@@ -373,16 +375,12 @@ Name affix categories:
373375

374376
Example name affix configurations for `PrettifyNames`:
375377

376-
```
377-
"SharedPrefix": {
378-
"Remove": true
379-
}
378+
```cs
379+
["SharedPrefix"] = new() { Remove = true },
380380
```
381381

382-
```
383-
"SharedPrefix": {
384-
"IsDiscriminator": true
385-
}
382+
```cs
383+
["SharedPrefix"] = new() { IsDiscriminator = true },
386384
```
387385

388386
Usage recommendations:
@@ -465,8 +463,8 @@ This is a monolithic mod that handles behavior specific to Khronos-style APIs su
465463

466464
Because this mod is intended more for internal use rather than public use, the documentation here will focus on
467465
decisions made during the development of the mod and other internal details rather than the exact usage of the mod.
468-
For information relating to how the mod should be used, please use Silk's `generator.json` configuration, source code,
469-
and `MixKhronosDataTests` as a reference.
466+
For information relating to how the mod should be used, please use Silk's own configuration, source code, and
467+
`MixKhronosDataTests` as a reference.
470468

471469
(TODO: Document major decisions relating to `MixKhronosData`. This is difficult because of the mod's long development
472470
history, and while this section is already massive, it still does not cover everything the mod does. This should be done

0 commit comments

Comments
 (0)