diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0b95263..e2d8768 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: '6.0.x'
+ dotnet-version: '7.0.x'
include-prerelease: true
- name: Build Product and Package
run: dotnet build src/create_package.proj -c ${{ matrix.flavor }}
@@ -51,7 +51,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: '6.0.x'
+ dotnet-version: '7.0.x'
include-prerelease: true
- name: Build Product and Package
run: dotnet build src\create_package.proj -c ${{ matrix.flavor }}
@@ -76,7 +76,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: '6.0.x'
+ dotnet-version: '7.0.x'
include-prerelease: true
- name: Build Product and Package
run: dotnet build src/create_package.proj -c ${{ matrix.flavor }}
diff --git a/DNNE.sln b/DNNE.sln
index ecd656b..f4fe97e 100644
--- a/DNNE.sln
+++ b/DNNE.sln
@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "platform", "platform", "{95
src\platform\platform.c = src\platform\platform.c
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dnne-analyzers", "src\dnne-analyzers\dnne-analyzers.csproj", "{2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -47,6 +49,10 @@ Global
{451402EC-4AE5-425A-9835-9D36A55E8081}.Debug|Any CPU.Build.0 = Debug|Any CPU
{451402EC-4AE5-425A-9835-9D36A55E8081}.Release|Any CPU.ActiveCfg = Release|Any CPU
{451402EC-4AE5-425A-9835-9D36A55E8081}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/readme.md b/readme.md
index bfe4e5f..a17dd7a 100644
--- a/readme.md
+++ b/readme.md
@@ -83,7 +83,7 @@ struct some_data
};
```
-The following attributes can be used to enable the above scenario. They must be defined by the project in order to be used - DNNE provides no assembly to reference. Refer to [`ExportingAssembly`](./test/ExportingAssembly/Dnne.Attributes.cs) for an example.
+The following attributes can be used to enable the above scenario. They are automatically generated into projects referencing DNNE, because DNNE provides no assembly to reference. If your build system or IDE does not support source generators (e.g., you're using a version older than Visual Studio 2022, or .NET Framework with `packages.config`), you will have to define these types yourself:
```CSharp
namespace DNNE
@@ -98,7 +98,8 @@ namespace DNNE
/// - stdint.h
/// - dnne.h
///
- internal class C99DeclCodeAttribute : System.Attribute
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter, Inherited = false)]
+ internal sealed class C99DeclCodeAttribute : System.Attribute
{
public C99DeclCodeAttribute(string code) { }
}
@@ -109,7 +110,8 @@ namespace DNNE
///
/// The level of indirection should be included in the supplied string.
///
- internal class C99TypeAttribute : System.Attribute
+ [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
+ internal sealed class C99TypeAttribute : System.Attribute
{
public C99TypeAttribute(string code) { }
}
@@ -196,12 +198,13 @@ In addition to providing declaration code directly, users can also supply `#incl
### Experimental attribute
-There are scenarios where updating `UnmanagedCallersOnlyAttribute` may take time. In order to enable independent development and experimentation, the `DNNE.ExportAttribute` is also respected. This type can be modified to suit one's needs and `dnne-gen` updated to respect those changes at source gen time. The user should define the following in their assembly. They can then modify the attribute and `dnne-gen` as needed.
+There are scenarios where updating `UnmanagedCallersOnlyAttribute` may take time. In order to enable independent development and experimentation, the `DNNE.ExportAttribute` is also respected. Like other DNNE attributes, this type is also automatically generated into projects referencing the DNNE package. This type can be modified to suit one's needs (by tweaking the generated source in `dnne-analyzers`) and `dnne-gen` updated as needed to respect those changes at source gen time.
``` CSharp
namespace DNNE
{
- internal class ExportAttribute : Attribute
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+ internal sealed class ExportAttribute : Attribute
{
public ExportAttribute() { }
public string EntryPoint { get; set; }
diff --git a/src/dnne-analyzers/AnalyzerReleases.Shipped.md b/src/dnne-analyzers/AnalyzerReleases.Shipped.md
new file mode 100644
index 0000000..85c2ce9
--- /dev/null
+++ b/src/dnne-analyzers/AnalyzerReleases.Shipped.md
@@ -0,0 +1,9 @@
+; Shipped analyzer releases
+; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
+
+## Release 1.0
+
+### New Rules
+
+Rule ID | Category | Severity | Notes
+--------|----------|----------|-------
diff --git a/src/dnne-analyzers/AnalyzerReleases.Unshipped.md b/src/dnne-analyzers/AnalyzerReleases.Unshipped.md
new file mode 100644
index 0000000..6a6dd08
--- /dev/null
+++ b/src/dnne-analyzers/AnalyzerReleases.Unshipped.md
@@ -0,0 +1,2 @@
+; Unshipped analyzer release
+; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
diff --git a/src/dnne-analyzers/AttributesGenerator.cs b/src/dnne-analyzers/AttributesGenerator.cs
new file mode 100644
index 0000000..7ab906e
--- /dev/null
+++ b/src/dnne-analyzers/AttributesGenerator.cs
@@ -0,0 +1,89 @@
+using Microsoft.CodeAnalysis;
+
+namespace DNNE;
+
+///
+/// A generator that generates all the necessary DNNE attributes.
+///
+[Generator(LanguageNames.CSharp)]
+public sealed class AttributesGenerator : IIncrementalGenerator
+{
+ ///
+ public void Initialize(IncrementalGeneratorInitializationContext context)
+ {
+ context.RegisterPostInitializationOutput(static context =>
+ {
+ context.AddSource("DnneAttributes.g.cs", """
+ //
+ #pragma warning disable
+
+ namespace DNNE
+ {
+ ///
+ /// Defines a C export. Can be used when updating to use UnmanagedCallersOnlyAttribute would take more time.
+ ///
+ [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)]
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
+ internal sealed class ExportAttribute : global::System.Attribute
+ {
+ ///
+ /// Creates a new instance.
+ ///
+ public ExportAttribute()
+ {
+ }
+
+ ///
+ /// Gets or sets the entry point to use to produce the C export.
+ ///
+ public string EntryPoint { get; set; }
+ }
+
+ ///
+ /// Provides C code to be defined early in the generated C header file.
+ ///
+ ///
+ /// This attribute is respected on an exported method declaration or on a parameter for the method.
+ /// The following header files will be included prior to the code being defined.
+ ///
+ /// - stddef.h
+ /// - stdint.h
+ /// - dnne.h
+ ///
+ ///
+ [global::System.AttributeUsage(global::System.AttributeTargets.Method | global::System.AttributeTargets.Parameter, Inherited = false)]
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
+ internal sealed class C99DeclCodeAttribute : global::System.Attribute
+ {
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The C code to be defined in the generated C header file.
+ public C99DeclCodeAttribute(string code)
+ {
+ }
+ }
+
+ ///
+ /// Defines the C type to be used.
+ ///
+ ///
+ /// The level of indirection should be included in the supplied string.
+ ///
+ [global::System.AttributeUsage(global::System.AttributeTargets.Parameter | global::System.AttributeTargets.ReturnValue, Inherited = false)]
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
+ internal sealed class C99TypeAttribute : global::System.Attribute
+ {
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The C type to be used.
+ public C99TypeAttribute(string code)
+ {
+ }
+ }
+ }
+ """);
+ });
+ }
+}
diff --git a/src/dnne-analyzers/DNNE.Analyzers.targets b/src/dnne-analyzers/DNNE.Analyzers.targets
new file mode 100644
index 0000000..ae0bdb5
--- /dev/null
+++ b/src/dnne-analyzers/DNNE.Analyzers.targets
@@ -0,0 +1,105 @@
+
+
+
+
+
+ <_DnneAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'DNNE'" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @(DnneCurrentCompilerAssemblyIdentity->'%(Version)')
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
diff --git a/src/dnne-analyzers/dnne-analyzers.csproj b/src/dnne-analyzers/dnne-analyzers.csproj
new file mode 100644
index 0000000..abfac91
--- /dev/null
+++ b/src/dnne-analyzers/dnne-analyzers.csproj
@@ -0,0 +1,18 @@
+
+
+
+ netstandard2.0
+ DNNE
+ 11.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/dnne-pkg/dnne-pkg.csproj b/src/dnne-pkg/dnne-pkg.csproj
index af2ba2b..7f390f8 100644
--- a/src/dnne-pkg/dnne-pkg.csproj
+++ b/src/dnne-pkg/dnne-pkg.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -37,6 +37,9 @@
+
+ false
+
TargetFramework=$(TargetFramework)
false
@@ -57,6 +60,8 @@
$(BuildDest)net472/
$(PseudoPackageRoot)tools/
$(ToolsDest)platform/
+ $(PseudoPackageRoot)analyzers/
+ $(AnalyzersDest)dotnet/cs
@@ -66,16 +71,19 @@
+
+
+
diff --git a/src/msbuild/DNNE.targets b/src/msbuild/DNNE.targets
index 3b13ed9..ef9c09f 100644
--- a/src/msbuild/DNNE.targets
+++ b/src/msbuild/DNNE.targets
@@ -23,6 +23,8 @@ DNNE.targets
-->
+
+
$(DnneNativeBinaryName)
diff --git a/test/DNNE.UnitTests/DNNE.UnitTests.csproj b/test/DNNE.UnitTests/DNNE.UnitTests.csproj
index aae19f3..84977f5 100644
--- a/test/DNNE.UnitTests/DNNE.UnitTests.csproj
+++ b/test/DNNE.UnitTests/DNNE.UnitTests.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
true
false
diff --git a/test/ExportingAssembly/Dnne.Attributes.cs b/test/ExportingAssembly/Dnne.Attributes.cs
deleted file mode 100644
index 93a2750..0000000
--- a/test/ExportingAssembly/Dnne.Attributes.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2020 Aaron R Robinson
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is furnished
-// to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
-// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-using System;
-
-namespace DNNE
-{
- internal class ExportAttribute : System.Attribute
- {
- public ExportAttribute() { }
- public string EntryPoint { get; set; }
- }
-
- internal class C99TypeAttribute : System.Attribute
- {
- public C99TypeAttribute(string code) { }
- }
-
- internal class C99DeclCodeAttribute : System.Attribute
- {
- public C99DeclCodeAttribute(string code) { }
- }
-}
\ No newline at end of file
diff --git a/test/ExportingAssembly/ExportingAssembly.csproj b/test/ExportingAssembly/ExportingAssembly.csproj
index 986be29..9d2aff5 100644
--- a/test/ExportingAssembly/ExportingAssembly.csproj
+++ b/test/ExportingAssembly/ExportingAssembly.csproj
@@ -4,6 +4,10 @@
$(PseudoPackage)build/DNNE.targets
+
+
+
+
@@ -15,6 +19,9 @@
1591
+
+ true
+
true
true
/TP
@@ -30,7 +37,6 @@
-