Skip to content

Commit efd4721

Browse files
Merge pull request #196 from brycehutchings/bryceh_nuget_gen_script
Script to build NuGet package from OpenXR-SDK Release
2 parents 51cade1 + 38218fb commit efd4721

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

.azure-pipelines/build_jobs.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,24 @@ jobs:
113113
inputs:
114114
path: $(System.DefaultWorkingDirectory)/openxr_loader
115115
artifact: openxr_loader_windows
116+
117+
- task: PowerShell@2
118+
displayName: Stage loader and headers for NuGet
119+
inputs:
120+
filePath: $(System.DefaultWorkingDirectory)/.azure-pipelines/nuget/stage_nuget.ps1
121+
arguments:
122+
$(System.DefaultWorkingDirectory)/openxr_loader `
123+
$(Build.SourcesDirectory)/specification/Makefile `
124+
$(System.DefaultWorkingDirectory)/openxr_loader_staging
125+
- task: NuGetCommand@2
126+
displayName: Package for NuGet
127+
inputs:
128+
command: pack
129+
packagesToPack: $(System.DefaultWorkingDirectory)/openxr_loader_staging/OpenXR.Loader.nuspec
130+
packDestination: $(System.DefaultWorkingDirectory)/nuget
131+
- task: PublishPipelineArtifact@1
132+
displayName: Publish NuGet Package
133+
condition: succeeded()
134+
inputs:
135+
path: $(System.DefaultWorkingDirectory)/nuget
136+
artifact: NuGet
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>OpenXR.Loader</id>
5+
<version></version>
6+
<authors>Khronos Group</authors>
7+
<owners>Khronos Group</owners>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<license type="expression">Apache-2.0</license>
10+
<licenseUrl>https://licenses.nuget.org/Apache-2.0</licenseUrl>
11+
<projectUrl>https://github.com/KhronosGroup/OpenXR-SDK</projectUrl>
12+
<description>Khronos OpenXR loader and headers required to build a Win32 or UWP OpenXR application</description>
13+
<tags>native khronos openxr loader</tags>
14+
</metadata>
15+
</package>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<OpenXRPackageRoot>$(MSBuildThisFileDirectory)..\..\</OpenXRPackageRoot>
4+
</PropertyGroup>
5+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<Choose>
4+
<When Condition="'$(ApplicationType)|$(ApplicationTypeRevision)' == 'Windows Store|10.0'">
5+
<PropertyGroup>
6+
<OpenXRLoaderBinaryRoot>$(OpenXRPackageRoot)native\$(Platform)_uwp\release</OpenXRLoaderBinaryRoot>
7+
</PropertyGroup>
8+
</When>
9+
<Otherwise>
10+
<PropertyGroup>
11+
<OpenXRLoaderBinaryRoot>$(OpenXRPackageRoot)native\$(Platform)\release</OpenXRLoaderBinaryRoot>
12+
</PropertyGroup>
13+
</Otherwise>
14+
</Choose>
15+
16+
<ItemDefinitionGroup>
17+
<ClCompile>
18+
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(OpenXRPackageRoot)include</AdditionalIncludeDirectories>
19+
</ClCompile>
20+
<Link>
21+
<AdditionalDependencies>%(AdditionalDependencies);$(OpenXRLoaderBinaryRoot)\lib\openxr_loader.lib</AdditionalDependencies>
22+
</Link>
23+
</ItemDefinitionGroup>
24+
25+
<!-- Copy the OpenXR loader DLL to the output directory and include in packaging -->
26+
<ItemGroup Condition="'$(OpenXRSkipLoaderCopy)'!='true'">
27+
<None Include="$(OpenXRLoaderBinaryRoot)\bin\openxr_loader.dll">
28+
<Link>%(Filename)%(Extension)</Link>
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
<DeploymentContent>true</DeploymentContent>
31+
</None>
32+
</ItemGroup>
33+
34+
<Target Name="EnsurePropsImported" BeforeTargets="PrepareForBuild">
35+
<Error Condition="'$(OpenXRPackageRoot)'==''" Text="OpenXRPackageRoot property missing. Project is malformed. Try removing and re-adding the NuGet reference." />
36+
</Target>
37+
38+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
param(
2+
[Parameter(Mandatory=$true, HelpMessage="Path to unzipped openxr_loader_windows OpenXR-SDK release asset")]
3+
$SDKRelease,
4+
[Parameter(Mandatory=$true, HelpMessage="Path to specification Makefile. Needed to extract the version")]
5+
$SpecMakefile,
6+
[Parameter(Mandatory=$true, HelpMessage="Path create staged nuget directory layout")]
7+
$NugetStaging)
8+
9+
$ErrorActionPreference = "Stop"
10+
11+
if (-Not (Test-Path $SDKRelease)) {
12+
Throw "SDK Release folder not found: $SDKRelease"
13+
}
14+
if (-Not (Test-Path $SpecMakefile)) {
15+
Throw "Specification makefile not found: $SpecMakefile"
16+
}
17+
18+
$NugetTemplate = Join-Path $PSScriptRoot "NugetTemplate"
19+
20+
if (Test-Path $NugetStaging) {
21+
Remove-Item $NugetStaging -Recurse
22+
}
23+
24+
#
25+
# Extract version from Specification makefile
26+
#
27+
$VersionMatch = Select-String -Path $SpecMakefile -Pattern "^SPECREVISION\s*=\s*(.+)"
28+
$SDKVersion = $VersionMatch.Matches[0].Groups[1]
29+
30+
#
31+
# Start off using the NuGet template.
32+
#
33+
echo "Copy-Item $NugetTemplate $NugetStaging -Recurse"
34+
Copy-Item $NugetTemplate $NugetStaging -Recurse
35+
36+
#
37+
# Update the NuSpec
38+
#
39+
$NuSpecPath = Resolve-Path (Join-Path $NugetStaging "OpenXR.Loader.nuspec")
40+
$xml = [xml](Get-Content $NuSpecPath)
41+
$nsm = New-Object Xml.XmlNamespaceManager($xml.NameTable)
42+
$nsm.AddNamespace("ng", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd")
43+
$xml.SelectSingleNode("/ng:package/ng:metadata/ng:version", $nsm).InnerText = $SDKVersion
44+
$xml.Save($NuSpecPath)
45+
46+
#
47+
# Copy in the headers from the SDK release.
48+
#
49+
Copy-Item (Join-Path $SDKRelease "include") (Join-Path $NugetStaging "include") -Recurse
50+
51+
#
52+
# Copy in the binaries from the SDK release.
53+
#
54+
function CopyLoader($Platform)
55+
{
56+
$PlatformSDKPath = Join-Path $SDKRelease "$Platform"
57+
$NuGetPlatformPath = Join-Path $NugetStaging "native/$Platform/release"
58+
59+
$NugetLibPath = Join-Path $NuGetPlatformPath "lib"
60+
New-Item $NugetLibPath -ItemType "directory" -Force
61+
Copy-Item (Join-Path $PlatformSDKPath "lib/openxr_loader.lib") $NugetLibPath
62+
63+
$NugetBinPath = Join-Path $NuGetPlatformPath "bin"
64+
New-Item $NugetBinPath -ItemType "directory" -Force
65+
Copy-Item (Join-Path $PlatformSDKPath "bin/openxr_loader.dll") $NugetBinPath
66+
}
67+
68+
# Currently there are no non-UWP ARM/ARM64 binaries available from the SDK release.
69+
CopyLoader "x64"
70+
CopyLoader "Win32"
71+
CopyLoader "x64_uwp"
72+
CopyLoader "Win32_uwp"
73+
CopyLoader "arm64_uwp"
74+
CopyLoader "arm_uwp"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Modifications to Azure DevOps build pipeline to automatically generate a NuGet package.

0 commit comments

Comments
 (0)