Skip to content

Commit

Permalink
Merge pull request #196 from brycehutchings/bryceh_nuget_gen_script
Browse files Browse the repository at this point in the history
Script to build NuGet package from OpenXR-SDK Release
  • Loading branch information
brycehutchings authored Jul 24, 2020
2 parents 51cade1 + 38218fb commit efd4721
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .azure-pipelines/build_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,24 @@ jobs:
inputs:
path: $(System.DefaultWorkingDirectory)/openxr_loader
artifact: openxr_loader_windows

- task: PowerShell@2
displayName: Stage loader and headers for NuGet
inputs:
filePath: $(System.DefaultWorkingDirectory)/.azure-pipelines/nuget/stage_nuget.ps1
arguments:
$(System.DefaultWorkingDirectory)/openxr_loader `
$(Build.SourcesDirectory)/specification/Makefile `
$(System.DefaultWorkingDirectory)/openxr_loader_staging
- task: NuGetCommand@2
displayName: Package for NuGet
inputs:
command: pack
packagesToPack: $(System.DefaultWorkingDirectory)/openxr_loader_staging/OpenXR.Loader.nuspec
packDestination: $(System.DefaultWorkingDirectory)/nuget
- task: PublishPipelineArtifact@1
displayName: Publish NuGet Package
condition: succeeded()
inputs:
path: $(System.DefaultWorkingDirectory)/nuget
artifact: NuGet
15 changes: 15 additions & 0 deletions .azure-pipelines/nuget/NugetTemplate/OpenXR.Loader.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>OpenXR.Loader</id>
<version></version>
<authors>Khronos Group</authors>
<owners>Khronos Group</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">Apache-2.0</license>
<licenseUrl>https://licenses.nuget.org/Apache-2.0</licenseUrl>
<projectUrl>https://github.com/KhronosGroup/OpenXR-SDK</projectUrl>
<description>Khronos OpenXR loader and headers required to build a Win32 or UWP OpenXR application</description>
<tags>native khronos openxr loader</tags>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OpenXRPackageRoot>$(MSBuildThisFileDirectory)..\..\</OpenXRPackageRoot>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Choose>
<When Condition="'$(ApplicationType)|$(ApplicationTypeRevision)' == 'Windows Store|10.0'">
<PropertyGroup>
<OpenXRLoaderBinaryRoot>$(OpenXRPackageRoot)native\$(Platform)_uwp\release</OpenXRLoaderBinaryRoot>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<OpenXRLoaderBinaryRoot>$(OpenXRPackageRoot)native\$(Platform)\release</OpenXRLoaderBinaryRoot>
</PropertyGroup>
</Otherwise>
</Choose>

<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(OpenXRPackageRoot)include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies);$(OpenXRLoaderBinaryRoot)\lib\openxr_loader.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>

<!-- Copy the OpenXR loader DLL to the output directory and include in packaging -->
<ItemGroup Condition="'$(OpenXRSkipLoaderCopy)'!='true'">
<None Include="$(OpenXRLoaderBinaryRoot)\bin\openxr_loader.dll">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DeploymentContent>true</DeploymentContent>
</None>
</ItemGroup>

<Target Name="EnsurePropsImported" BeforeTargets="PrepareForBuild">
<Error Condition="'$(OpenXRPackageRoot)'==''" Text="OpenXRPackageRoot property missing. Project is malformed. Try removing and re-adding the NuGet reference." />
</Target>

</Project>
74 changes: 74 additions & 0 deletions .azure-pipelines/nuget/stage_nuget.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
param(
[Parameter(Mandatory=$true, HelpMessage="Path to unzipped openxr_loader_windows OpenXR-SDK release asset")]
$SDKRelease,
[Parameter(Mandatory=$true, HelpMessage="Path to specification Makefile. Needed to extract the version")]
$SpecMakefile,
[Parameter(Mandatory=$true, HelpMessage="Path create staged nuget directory layout")]
$NugetStaging)

$ErrorActionPreference = "Stop"

if (-Not (Test-Path $SDKRelease)) {
Throw "SDK Release folder not found: $SDKRelease"
}
if (-Not (Test-Path $SpecMakefile)) {
Throw "Specification makefile not found: $SpecMakefile"
}

$NugetTemplate = Join-Path $PSScriptRoot "NugetTemplate"

if (Test-Path $NugetStaging) {
Remove-Item $NugetStaging -Recurse
}

#
# Extract version from Specification makefile
#
$VersionMatch = Select-String -Path $SpecMakefile -Pattern "^SPECREVISION\s*=\s*(.+)"
$SDKVersion = $VersionMatch.Matches[0].Groups[1]

#
# Start off using the NuGet template.
#
echo "Copy-Item $NugetTemplate $NugetStaging -Recurse"
Copy-Item $NugetTemplate $NugetStaging -Recurse

#
# Update the NuSpec
#
$NuSpecPath = Resolve-Path (Join-Path $NugetStaging "OpenXR.Loader.nuspec")
$xml = [xml](Get-Content $NuSpecPath)
$nsm = New-Object Xml.XmlNamespaceManager($xml.NameTable)
$nsm.AddNamespace("ng", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd")
$xml.SelectSingleNode("/ng:package/ng:metadata/ng:version", $nsm).InnerText = $SDKVersion
$xml.Save($NuSpecPath)

#
# Copy in the headers from the SDK release.
#
Copy-Item (Join-Path $SDKRelease "include") (Join-Path $NugetStaging "include") -Recurse

#
# Copy in the binaries from the SDK release.
#
function CopyLoader($Platform)
{
$PlatformSDKPath = Join-Path $SDKRelease "$Platform"
$NuGetPlatformPath = Join-Path $NugetStaging "native/$Platform/release"

$NugetLibPath = Join-Path $NuGetPlatformPath "lib"
New-Item $NugetLibPath -ItemType "directory" -Force
Copy-Item (Join-Path $PlatformSDKPath "lib/openxr_loader.lib") $NugetLibPath

$NugetBinPath = Join-Path $NuGetPlatformPath "bin"
New-Item $NugetBinPath -ItemType "directory" -Force
Copy-Item (Join-Path $PlatformSDKPath "bin/openxr_loader.dll") $NugetBinPath
}

# Currently there are no non-UWP ARM/ARM64 binaries available from the SDK release.
CopyLoader "x64"
CopyLoader "Win32"
CopyLoader "x64_uwp"
CopyLoader "Win32_uwp"
CopyLoader "arm64_uwp"
CopyLoader "arm_uwp"
1 change: 1 addition & 0 deletions changes/sdk/pr.196.gh.OpenXR-SDK-Source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modifications to Azure DevOps build pipeline to automatically generate a NuGet package.

0 comments on commit efd4721

Please sign in to comment.