Skip to content

Commit d18600d

Browse files
authored
Merge pull request #946 from microsoft/fix895
Add the WDK as a default metadata input
2 parents ed29c9e + c2db916 commit d18600d

File tree

11 files changed

+77
-8
lines changed

11 files changed

+77
-8
lines changed

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
66

77
<MetadataVersion>52.0.65-preview</MetadataVersion>
8+
<WDKMetadataVersion>0.7.3-experimental</WDKMetadataVersion>
89
<!-- <DiaMetadataVersion>0.2.185-preview-g7e1e6a442c</DiaMetadataVersion> -->
910
<ApiDocsVersion>0.1.41-alpha</ApiDocsVersion>
1011

@@ -25,6 +26,7 @@
2526
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
2627
<PackageVersion Include="Microsoft.Windows.SDK.Win32Docs" Version="$(ApiDocsVersion)" />
2728
<PackageVersion Include="Microsoft.Windows.SDK.Win32Metadata" Version="$(MetadataVersion)" />
29+
<PackageVersion Include="Microsoft.Windows.WDK.Win32Metadata" Version="$(WDKMetadataVersion)" />
2830
<PackageVersion Include="NuGet.Protocol" Version="6.5.0" />
2931
<PackageVersion Include="System.Collections.Immutable" Version="6.0.0" />
3032
<PackageVersion Include="System.Memory" Version="4.5.5" />

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ To update the metadata used as the source for code generation, you may install a
126126
dotnet add package Microsoft.Windows.SDK.Win32Metadata --prerelease
127127
```
128128

129-
Alternatively, you may set the `MicrosoftWindowsSdkWin32MetadataBasePath` property in your project file to the path of the directory containing `Windows.Win32.winmd`:
130-
131-
```xml
132-
<MicrosoftWindowsSdkWin32MetadataBasePath>c:\path\to\dir</MicrosoftWindowsSdkWin32MetadataBasePath>
133-
```
129+
CsWin32 also consumes the WDK from a similarly named package: `Microsoft.Windows.WDK.WDKMetadata`.
134130

135131
## Consuming daily builds
136132

src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
4949
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" GeneratePathProperty="true" PrivateAssets="none" />
5050
<PackageReference Include="Microsoft.Windows.SDK.Win32Docs" GeneratePathProperty="true" PrivateAssets="none" />
51+
<PackageReference Include="Microsoft.Windows.WDK.Win32Metadata" GeneratePathProperty="true" PrivateAssets="none" />
5152
<PackageReference Include="System.Memory" PrivateAssets="none" />
5253
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" PrivateAssets="none" />
5354
<PackageReference Include="System.Reflection.Metadata" />

src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.nuspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,33 @@
1717
<dependencies>
1818
<group targetFramework="net20">
1919
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="$MetadataVersion$" include="buildTransitive" />
20+
<dependency id="Microsoft.Windows.WDK.Win32Metadata" version="$WDKMetadataVersion$" include="buildTransitive" />
2021
<dependency id="Microsoft.Windows.SDK.Win32Docs" version="$ApiDocsVersion$" include="buildTransitive" />
2122
</group>
2223
<group targetFramework="net45">
2324
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="$MetadataVersion$" include="buildTransitive" />
25+
<dependency id="Microsoft.Windows.WDK.Win32Metadata" version="$WDKMetadataVersion$" include="buildTransitive" />
2426
<dependency id="Microsoft.Windows.SDK.Win32Docs" version="$ApiDocsVersion$" include="buildTransitive" />
2527
<dependency id="System.Memory" version="4.5.5" include="All" />
2628
<dependency id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" include="All" />
2729
</group>
2830
<group targetFramework="net461">
2931
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="$MetadataVersion$" include="buildTransitive" />
32+
<dependency id="Microsoft.Windows.WDK.Win32Metadata" version="$WDKMetadataVersion$" include="buildTransitive" />
3033
<dependency id="Microsoft.Windows.SDK.Win32Docs" version="$ApiDocsVersion$" include="buildTransitive" />
3134
<dependency id="System.Memory" version="4.5.5" include="All" />
3235
<dependency id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" include="All" />
3336
</group>
3437
<group targetFramework=".NETStandard1.1">
3538
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="$MetadataVersion$" include="buildTransitive" />
39+
<dependency id="Microsoft.Windows.WDK.Win32Metadata" version="$WDKMetadataVersion$" include="buildTransitive" />
3640
<dependency id="Microsoft.Windows.SDK.Win32Docs" version="$ApiDocsVersion$" include="buildTransitive" />
3741
<dependency id="System.Memory" version="4.5.5" include="All" />
3842
<dependency id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" include="All" />
3943
</group>
4044
<group targetFramework=".NETStandard2.0">
4145
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="$MetadataVersion$" include="buildTransitive" />
46+
<dependency id="Microsoft.Windows.WDK.Win32Metadata" version="$WDKMetadataVersion$" include="buildTransitive" />
4247
<dependency id="Microsoft.Windows.SDK.Win32Docs" version="$ApiDocsVersion$" include="buildTransitive" />
4348
<dependency id="System.Memory" version="4.5.5" include="All" />
4449
<dependency id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" include="All" />

src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.targets

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55

66
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
77
<PropertyGroup>
8-
<NuspecProperties>$(NuspecProperties);Version=$(Version);BaseOutputPath=$(OutputPath);MetadataVersion=$(MetadataVersion);ApiDocsVersion=$(ApiDocsVersion);PackageReleaseNotes=$(PackageReleaseNotes);commit=$(GitCommitId);</NuspecProperties>
8+
<NuspecProperties>
9+
$(NuspecProperties);
10+
Version=$(Version);
11+
BaseOutputPath=$(OutputPath);
12+
MetadataVersion=$(MetadataVersion);
13+
WDKMetadataVersion=$(WDKMetadataVersion);
14+
ApiDocsVersion=$(ApiDocsVersion);
15+
PackageReleaseNotes=$(PackageReleaseNotes);
16+
commit=$(GitCommitId);
17+
</NuspecProperties>
918
</PropertyGroup>
1019
</Target>
1120

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
public class DelegateTests : GeneratorTestBase
5+
{
6+
public DelegateTests(ITestOutputHelper logger)
7+
: base(logger)
8+
{
9+
}
10+
11+
[Theory]
12+
[CombinatorialData]
13+
public void InterestingDelegates(
14+
[CombinatorialValues(
15+
"LPD3DHAL_RENDERSTATECB")] // A delegate with a pointer parameter to a managed struct.
16+
string name,
17+
bool allowMarshaling)
18+
{
19+
var options = DefaultTestGeneratorOptions with
20+
{
21+
AllowMarshaling = allowMarshaling,
22+
};
23+
this.generator = this.CreateGenerator(options);
24+
Assert.True(this.generator.TryGenerate(name, CancellationToken.None));
25+
this.CollectGeneratedCode(this.generator);
26+
this.AssertNoDiagnostics();
27+
}
28+
}

test/Microsoft.Windows.CsWin32.Tests/ExternMethodTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@ public void AssociatedEnumOnParameterWithVoidReturn()
4444
this.CollectGeneratedCode(this.generator);
4545
this.AssertNoDiagnostics();
4646
}
47+
48+
/// <summary>
49+
/// Verifies that we can generate APIs from the WDK, which includes references to the SDK.
50+
/// </summary>
51+
[Fact]
52+
public void WdkMethod_NtCreateFile()
53+
{
54+
const string Method = "NtCreateFile";
55+
this.generator = this.CreateGenerator();
56+
Assert.True(this.generator.TryGenerate(Method, CancellationToken.None));
57+
this.CollectGeneratedCode(this.generator);
58+
this.AssertNoDiagnostics();
59+
}
4760
}

test/Microsoft.Windows.CsWin32.Tests/GeneratorTestBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public abstract class GeneratorTestBase : IDisposable, IAsyncLifetime
77
protected static readonly GeneratorOptions DefaultTestGeneratorOptions = new GeneratorOptions { EmitSingleFile = true };
88
protected static readonly string FileSeparator = new string('=', 140);
99
protected static readonly string MetadataPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!, "Windows.Win32.winmd");
10+
protected static readonly string WdkMetadataPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!, "Windows.Wdk.winmd");
11+
protected static readonly string[] DefaultMetadataPaths = new[] { MetadataPath, WdkMetadataPath };
1012
////protected static readonly string DiaMetadataPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!, "Microsoft.Dia.winmd");
1113
protected static readonly string ApiDocsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!, "apidocs.msgpack");
1214

@@ -319,7 +321,8 @@ protected async Task<CSharpCompilation> CreateCompilationAsync(ReferenceAssembli
319321
return compilation;
320322
}
321323

322-
protected SuperGenerator CreateGenerator(GeneratorOptions? options = null, CSharpCompilation? compilation = null, bool includeDocs = false) => this.CreateSuperGenerator(new[] { MetadataPath }, options, compilation, includeDocs);
324+
protected SuperGenerator CreateGenerator(GeneratorOptions? options = null, CSharpCompilation? compilation = null, bool includeDocs = false)
325+
=> this.CreateSuperGenerator(DefaultMetadataPaths, options, compilation, includeDocs);
323326

324327
protected SuperGenerator CreateSuperGenerator(string[] metadataPaths, GeneratorOptions? options = null, CSharpCompilation? compilation = null, bool includeDocs = false) =>
325328
SuperGenerator.Combine(metadataPaths.Select(path => new Generator(path, includeDocs ? Docs.Get(ApiDocsPath) : null, options ?? DefaultTestGeneratorOptions, compilation ?? this.compilation, this.parseOptions)));

test/Microsoft.Windows.CsWin32.Tests/HandleTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public void AvoidSafeHandles()
7474
Assert.Equal("HANDLE", Assert.IsType<QualifiedNameSyntax>(friendlyOverload.ParameterList.Parameters[0].Type).Right.Identifier.ValueText);
7575
}
7676

77+
[Fact]
78+
public void SafeHandleInWDK()
79+
{
80+
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions);
81+
Assert.True(this.generator.TryGenerate("OROpenHive", CancellationToken.None));
82+
this.CollectGeneratedCode(this.generator);
83+
this.AssertNoDiagnostics();
84+
}
85+
7786
/// <summary>
7887
/// Verifies that MSIHANDLE is wrapped with a SafeHandle even though it is a 32-bit handle.
7988
/// This is safe because we never pass SafeHandle directly to extern methods, so we can fix the length of the parameter or return value.

test/Microsoft.Windows.CsWin32.Tests/StructTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ public void FieldWithAssociatedEnum()
178178
[CombinatorialData]
179179
public void InterestingStructs(
180180
[CombinatorialValues(
181+
"DRIVER_OBJECT", // has an inline array of delegates
182+
"DEVICE_RELATIONS", // ends with an inline "flexible" array
183+
"D3DHAL_CONTEXTCREATEDATA", // contains a field that is a pointer to a struct that is normally managed
181184
"WSD_EVENT")] // has a pointer field to a managed struct
182185
string name,
183186
bool allowMarshaling)

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "0.2-beta",
3+
"version": "0.3-beta",
44
"assemblyVersion": {
55
"precision": "revision"
66
},

0 commit comments

Comments
 (0)