Skip to content

3.0 SilkTouch tweaks #878

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

Merged
merged 7 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ resharper_web_config_module_not_resolved_highlighting = warning
resharper_web_config_type_not_resolved_highlighting = warning
resharper_web_config_wrong_module_highlighting = warning

# Silk Touch options
silk_touch_vtable_generate = true
silk_touch_vtable_tree_emit_assert = true
silk_touch_sealed_vtable_creation = true
silk_touch_vtable_preload = false
silk_touch_telemetry = false
silk_touch_compact_file_format = true

[*.{appxmanifest,asax,ascx,aspx,build,config,cs,cshtml,csproj,dbml,discomap,dtd,fs,fsi,fsscript,fsx,htm,html,jsproj,lsproj,master,ml,mli,njsproj,nuspec,proj,props,razor,resw,resx,skin,StyleCop,targets,tasks,vb,vbproj,xaml,xamlx,xml,xoml,xsd}]
indent_style = space
indent_size = 4
Expand Down
9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<!-- See https://github.com/NuGet/Home/wiki/Centrally-managing-NuGet-package-versions -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
42 changes: 42 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project>
<!--
This file tracks all package versions used in Silk.NET, including tests.
For more information what this is see https://github.com/NuGet/Home/wiki/Centrally-managing-NuGet-package-versions
-->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.12.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.0-2.final" />
<PackageVersion Include="System.Text.Json" Version="6.0.0-preview.6.21352.12" />
<PackageVersion Include="ClangSharp.PInvokeGenerator" Version="12.0.0-beta2" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.4.1" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0-preview.6.21352.12" />
<PackageVersion Include="Microsoft.Build.Framework" Version="16.10.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.0-2.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.0.0-2.final" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageVersion Include="NuGet.Protocol" Version="5.8.0" />
<PackageVersion Include="Nuke.Common" Version="6.0.1" />
<PackageVersion Include="Ultz.Bcl.Half" Version="1.0.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageVersion Include="xunit" Version="2.4.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageVersion Include="Statiq.Core" Version="1.0.0-beta.48" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.42" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.11.0" />
<PackageVersion Include="Statiq.App" Version="1.0.0-beta.48" />
<PackageVersion Include="Statiq.Feeds" Version="1.0.0-beta.48" />
<PackageVersion Include="Statiq.Markdown" Version="1.0.0-beta.48" />
<PackageVersion Include="Statiq.Razor" Version="1.0.0-beta.48" />
<PackageVersion Include="Statiq.Yaml" Version="1.0.0-beta.48" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
</ItemGroup>
</Project>
20 changes: 17 additions & 3 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Maths", "src\libra
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{FD15E196-1C63-47D6-8AD5-64F015120B4B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "experiments", "experiments", "{1565E50D-3BF1-407E-842A-169F4F86513D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastructure", "{F07CABFC-DC6A-4B5B-BC56-B10EEC2C0BFA}"
ProjectSection(SolutionItems) = preProject
src\infrastructure\.gitignore = src\infrastructure\.gitignore
Expand Down Expand Up @@ -71,6 +69,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Core", "src\librar
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Vulkan", "src\bindings\Silk.NET.Vulkan\Silk.NET.Vulkan.csproj", "{AF6E05E0-9C51-4D52-AC7E-056714CAC5F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Maths.Tests", "tests\Silk.NET.Maths.Tests\Silk.NET.Maths.Tests.csproj", "{A0726B46-F2F6-4996-A640-1BD01EEBAF07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Statiq", "src\infrastructure\Silk.NET.Statiq\Silk.NET.Statiq.csproj", "{ED11DCF5-E925-417A-99E0-B8AD615874EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Statiq.TableOfContents", "src\infrastructure\Silk.NET.Statiq.TableOfContents\Silk.NET.Statiq.TableOfContents.csproj", "{A11CC2E1-51C3-4DE8-A4B3-F05D37EDAB8C}"
Expand Down Expand Up @@ -271,6 +273,18 @@ Global
{AF6E05E0-9C51-4D52-AC7E-056714CAC5F4}.Release|x64.Build.0 = Release|Any CPU
{AF6E05E0-9C51-4D52-AC7E-056714CAC5F4}.Release|x86.ActiveCfg = Release|Any CPU
{AF6E05E0-9C51-4D52-AC7E-056714CAC5F4}.Release|x86.Build.0 = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|x64.ActiveCfg = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|x64.Build.0 = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|x86.ActiveCfg = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Debug|x86.Build.0 = Debug|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|Any CPU.Build.0 = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|x64.ActiveCfg = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|x64.Build.0 = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|x86.ActiveCfg = Release|Any CPU
{A0726B46-F2F6-4996-A640-1BD01EEBAF07}.Release|x86.Build.0 = Release|Any CPU
{ED11DCF5-E925-417A-99E0-B8AD615874EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED11DCF5-E925-417A-99E0-B8AD615874EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED11DCF5-E925-417A-99E0-B8AD615874EA}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -340,7 +354,6 @@ Global
{C9718C94-2F21-4E8D-B55D-8F0B1A131346} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
{7A2A3176-DBA1-4026-AF65-8E36B4F09B01} = {C9718C94-2F21-4E8D-B55D-8F0B1A131346}
{FD15E196-1C63-47D6-8AD5-64F015120B4B} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
{1565E50D-3BF1-407E-842A-169F4F86513D} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
{F07CABFC-DC6A-4B5B-BC56-B10EEC2C0BFA} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
{9020C7C6-C366-4BD3-8C8A-F81394EC7174} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
{8238D9F3-E158-4633-8017-B29AA3AD61F7} = {EA3CA547-452A-4D9E-BDB3-3BC5D7F15ACA}
Expand All @@ -358,6 +371,7 @@ Global
{46A89F89-77B3-4679-A82F-04A552545B16} = {8238D9F3-E158-4633-8017-B29AA3AD61F7}
{69CF4437-59F7-4304-9AE1-4B58E1A93367} = {C9718C94-2F21-4E8D-B55D-8F0B1A131346}
{AF6E05E0-9C51-4D52-AC7E-056714CAC5F4} = {9020C7C6-C366-4BD3-8C8A-F81394EC7174}
{A0726B46-F2F6-4996-A640-1BD01EEBAF07} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
{ED11DCF5-E925-417A-99E0-B8AD615874EA} = {F07CABFC-DC6A-4B5B-BC56-B10EEC2C0BFA}
{A11CC2E1-51C3-4DE8-A4B3-F05D37EDAB8C} = {F07CABFC-DC6A-4B5B-BC56-B10EEC2C0BFA}
{62901DA5-46F5-40E6-B680-D55F3AAE0323} = {F07CABFC-DC6A-4B5B-BC56-B10EEC2C0BFA}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All JSON configuration structures are represented by C# records in the Silk.NET.

### Project Configuration

Each project has its own JSON configuration file which defines what each generator does for that particular project. This file should be added by the user as an `AdditionalFiles` file, with the name `silktouch.json` unless the `silktouch_config_file` `.editorconfig` option is used to override this with a new file name or file path (either absolute or relative).
Each project has its own JSON configuration file which defines what each generator does for that particular project. This file should be added by the user as an `AdditionalFiles` file, with the name `silktouch.json` unless the `silktouch_config_file` `.editorconfig` option in the source generator format factor or the `config` option in the CLI form factor are used to override this with a new file name or file path (either absolute or relative).

Each generator has its own specific configuration structure, which is outlined in XML documentation in the `Config.cs` file as well as the markdown documents for each individual generator.

Expand All @@ -22,6 +22,13 @@ The project configuration also provides a (relative or absolute) path to a file

The global configuration contains variables which aren't specific to a particular project or generation process/job. Stuff like the License Header, which doesn't need to be duplicated across every single project configuration.

### CLI Configuration
The CLI has 3 ways to be configured:
- Command line parameters, possible formats are "key1=value1 --key2=value2 /key3=value3 --key4 value4 /key5 value5"
- A JSON file, with the path taken either from the config option `config` or by default silktouch.json (in the working directory)
- Environment Variables, prefixed with SilkTouch_ (to configure hierarchical data, use two underscores like `set SilkTouch_Parent__Root=value`)
The CLI uses the Microsoft.Extensions.Configuration package for this, for more information on how to use the above options see [here](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) (note that we do not use user secrets)

## Generation

### SilkTouch "Context"
Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup Condition="'$(SilkEnableSourceLink)' != 'false' And '$(SilkSourceLinkExempt)' == ''">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All"/>
</ItemGroup>
<PropertyGroup Condition="'$(SilkSourceLinkExempt)' != ''">
<IncludeSymbols>false</IncludeSymbols>
<SymbolPackageFormat></SymbolPackageFormat>
</PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
</Project>
2 changes: 1 addition & 1 deletion src/benchmarks/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<NoWarn>1591</NoWarn>
<NoWarn>1591;$(NoWarn)</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)../Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using Silk.NET.SilkTouch.Configuration.Json;
using Ultz.Extensions.Logging;

namespace Silk.NET.SilkTouch.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Silk.NET.SilkTouch.Configuration;
Expand All @@ -12,10 +13,6 @@ namespace Silk.NET.SilkTouch.Generation
/// </summary>
/// <param name="AssemblyName">The name of the assembly represented by the C# project.</param>
/// <param name="Compilation">The Roslyn compilation, containing all C# compiler info (such as syntax trees)</param>
/// <param name="Configuration">The project-specific configuration for this project.</param>
/// <param name="GlobalConfiguration">
/// The global/common configuration referenced by the <see cref="Configuration"/>'s
/// <see cref="ProjectConfiguration.GlobalConfigFile"/>.</param>
/// <param name="BaseDirectory">
/// The "base directory", used as the root for all relative paths referenced elsewhere in the configuration. This is
/// usually the same folder in which the C# project file (<c>csproj</c>) is contained.
Expand All @@ -24,9 +21,8 @@ public sealed record SilkTouchContext
(
string AssemblyName,
Compilation Compilation,
ProjectConfiguration Configuration,
GlobalConfiguration? GlobalConfiguration,
string BaseDirectory
string BaseDirectory,
IServiceProvider ServiceProvider
)
{
// Internal Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ public sealed class SilkTouchGenerator
/// <summary>
/// Creates a <see cref="SilkTouchGenerator"/> for the given <see cref="FormFactor"/>.
/// </summary>
/// <param name="serviceProvider">The service provider used to resolve dependencies</param>
/// <param name="formFactor">The form factor this generator is running within.</param>
public SilkTouchGenerator(FormFactors formFactor) => FormFactor = formFactor;

public SilkTouchGenerator(IServiceProvider serviceProvider, FormFactors formFactor)
{
ServiceProvider = serviceProvider;
FormFactor = formFactor;
}

// Public Properties

/// <summary>
/// The service provider used to resolve dependencies
/// </summary>
public IServiceProvider ServiceProvider { get; }

/// <summary>
/// The form factor this generator is running within.
/// </summary>
Expand All @@ -44,16 +55,6 @@ public sealed class SilkTouchGenerator
/// </summary>
public string? AssemblyName { get; private set; }

/// <summary>
/// The common/global configuration variables.
/// </summary>
public GlobalConfiguration? GlobalConfiguration { get; private set; }

/// <summary>
/// The project-specific configuration for this project.
/// </summary>
public ProjectConfiguration? ThisConfiguration { get; private set; }

/// <summary>
/// The "base directory" of this project, used as the root of all relative paths referenced in the
/// <see cref="ProjectConfiguration"/>.
Expand Down Expand Up @@ -133,8 +134,6 @@ public bool Begin
IsActive = true;
Compilation = compilation;
AssemblyName = assemblyName;
GlobalConfiguration = projectConfig?.GetGlobalConfiguration(baseDir);
ThisConfiguration = projectConfig;
BaseDirectory = baseDir;
return true;
}
Expand Down Expand Up @@ -165,8 +164,6 @@ public void End()
IsActive = false;
Compilation = null;
AssemblyName = null;
GlobalConfiguration = null;
ThisConfiguration = null;
BaseDirectory = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.0-2.final" />
<PackageReference Include="System.Text.Json" Version="6.0.0-preview.6.21352.12" />
<PackageReference Include="Ultz.Extensions.Logging" Version="4.1.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Humanizer.Core" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Silk.NET.SilkTouch.Configuration;
using Silk.NET.SilkTouch.Generation;
using Ultz.Extensions.Logging;

namespace Silk.NET.SilkTouch.Emitter
{
Expand All @@ -19,33 +22,33 @@ public static class EmitterGenerationExtensions
/// <returns>Whether the overloader was started successfully.</returns>
public static bool RunEmitter(this SilkTouchGenerator generator)
{
var logger = generator.ServiceProvider.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(RunEmitter));
var configuration = generator.ServiceProvider.GetService<IOptions<EmitterConfiguration>>();
if (!generator.IsActive ||
generator.AssemblyName is null ||
generator.Compilation is null ||
generator.ThisConfiguration is null ||
generator.BaseDirectory is null)
{
// generator is not active, move along...
Log.Debug("Generator is not active.");
logger.LogDebug("Generator is not active");
return false;
}

// run the emitter if the config indicates we should.
if (generator.ThisConfiguration?.Emitter is null ||
((generator.ThisConfiguration?.Emitter?.FormFactors ?? EmitterGenerator.DefaultFormFactors) &
if (configuration is null ||
((configuration.Value.FormFactors ?? EmitterGenerator.DefaultFormFactors) &
generator.FormFactor) == 0)
{
Log.Trace("Emitter is not configured to run.");
logger.LogTrace("Emitter is not configured to run");
return false;
}

var ctx = new SilkTouchContext
(
generator.AssemblyName,
generator.Compilation,
generator.ThisConfiguration!,
generator.GlobalConfiguration,
generator.BaseDirectory
generator.BaseDirectory,
generator.ServiceProvider
);

EmitterGenerator.Run(ctx);
Expand Down
Loading