build-scripts/winrtbuild.ps1
author Sam Lantinga
Tue, 10 Jan 2017 08:54:33 -0800
changeset 10806 36f40b8cc979
parent 9942 e82bfd942409
child 10911 1863707d9df8
permissions -rw-r--r--
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
     1 #
     2 # winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
     3 #    across all WinRT platforms, in all of their supported, CPU architectures.
     4 #
     5 # Initial version written by David Ludwig <dludwig@pobox.com>
     6 #
     7 # This script can be launched from Windows Explorer by double-clicking
     8 # on winrtbuild.bat
     9 #
    10 # Output will be placed in the following subdirectories of the SDL source
    11 # tree:
    12 #   * VisualC-WinRT\lib\  -- final .dll, .lib, and .pdb files
    13 #   * VisualC-WinRT\obj\  -- intermediate build files
    14 #
    15 # Recommended Dependencies:
    16 #   * Windows 8.1 or higher
    17 #   * Powershell 4.0 or higher (included as part of Windows 8.1)
    18 #   * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
    19 #   * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
    20 #   * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
    21 #     Windows Phone 8.1, as needed
    22 #
    23 # Commom parameters/variables may include, but aren't strictly limited to:
    24 #   * PlatformToolset: the name of one of Visual Studio's build platforms.
    25 #     Different PlatformToolsets output different binaries.  One
    26 #     PlatformToolset exists for each WinRT platform.  Possible values
    27 #     may include:
    28 #       - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
    29 #       - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
    30 #       - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
    31 #       - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
    32 #   * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
    33 #   * VSProjectName: the internal name of a Visual Studio or Visual C++ project
    34 #     file.  Some of Visual Studio's own build tools use this name when
    35 #     calculating paths for build-output.
    36 #   * Platform: a Visual Studio platform name, which often maps to a CPU
    37 #     CPU architecture.  Possible values may include: "Win32" (for 32-bit x86),
    38 #     "ARM", or "x64" (for 64-bit x86).
    39 #
    40 
    41 # Base version of SDL, used for packaging purposes
    42 $SDLVersion = "2.0.4"
    43 
    44 # Gets the .bat file that sets up an MSBuild environment, given one of
    45 # Visual Studio's, "PlatformToolset"s.
    46 function Get-MSBuild-Env-Launcher
    47 {
    48     param(
    49         [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
    50     )
    51 
    52     if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
    53         return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
    54     }
    55     if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
    56         return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
    57     }
    58     if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
    59         return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    60     }
    61     if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
    62         return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    63     }
    64     if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015
    65         return "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
    66     }
    67     return ""
    68 }
    69 
    70 # Gets a string that identifies the build-variant of SDL/WinRT that is specific
    71 # to a particular Visual Studio PlatformToolset.
    72 function Get-SDL-WinRT-Variant-Name
    73 {
    74     param(
    75         [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
    76 
    77         # If true, append a string to this function's output, identifying the
    78         # build-variant's minimum-supported version of Visual Studio.
    79         [switch]$IncludeVSSuffix = $false
    80     )
    81 
    82     if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
    83         if ($IncludeVSSuffix) {
    84             return "WinRT80_VS2012"
    85         } else {
    86             return "WinRT80"
    87         }
    88     }
    89     if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
    90         if ($IncludeVSSuffix) {
    91             return "WinPhone80_VS2012"
    92         } else {
    93             return "WinPhone80"
    94         }
    95     }
    96     if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
    97         if ($IncludeVSSuffix) {
    98             return "WinRT81_VS2013"
    99         } else {
   100             return "WinRT81"
   101         }
   102     }
   103     if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
   104         if ($IncludeVSSuffix) {
   105             return "WinPhone81_VS2013"
   106         } else {
   107             return "WinPhone81"
   108         }
   109     }
   110     if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015 project files
   111         if ($IncludeVSSuffix) {
   112             return "UWP_VS2015"
   113         } else {
   114             return "UWP"
   115         }
   116     }
   117     return ""
   118 }
   119 
   120 # Returns the internal name of a Visual Studio Project.
   121 #
   122 # The internal name of a VS Project is encoded inside the project file
   123 # itself, inside a set of <ProjectName></ProjectName> XML tags.
   124 function Get-VS-ProjectName
   125 {
   126     param(
   127         [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
   128     )
   129 
   130     # For now, just do a regex for the project name:
   131     $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
   132     foreach ($match in $matches) {
   133         if ($match.Groups.Count -ge 1) {
   134             return $match.Groups[1].Value
   135         }
   136     }
   137     return $null
   138 }
   139 
   140 # Build a specific variant of SDL/WinRT
   141 function Build-SDL-WinRT-Variant
   142 {
   143     #
   144     # Read in arguments:
   145     #
   146     param (
   147         # name of an SDL project file, minus extensions and
   148         # platform-identifying suffixes
   149         [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
   150 
   151         [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
   152 
   153         [Parameter(Mandatory=$true,Position=3)][string]$Platform
   154     )
   155 
   156     #
   157     # Derive other properties from read-in arguments:
   158     #
   159 
   160     # The .bat file to setup a platform-appropriate MSBuild environment:
   161     $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
   162 
   163     # The full path to the VS Project that'll be built:
   164     $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
   165 
   166     # The internal name of the VS Project, used in some post-build steps:
   167     $VSProjectName = Get-VS-ProjectName $VSProjectPath
   168 
   169     # Where to place output binaries (.dll, .lib, and .pdb files):
   170     $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
   171 
   172     # Where to place intermediate build files:
   173     $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
   174 
   175     #
   176     # Build the VS Project:
   177     #
   178     cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Configuration=Release /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
   179     $BuildResult = $?
   180 
   181     #
   182     # Move .dll files into place.  This fixes a problem whereby MSBuild may
   183     # put output files into a sub-directory of $OutDir, rather than $OutDir
   184     # itself.
   185     #
   186     if (Test-Path "$OutDir\$VSProjectName\") {
   187         Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
   188     }
   189 
   190     #
   191     # Clean up unneeded files in $OutDir:
   192     #
   193     if (Test-Path "$OutDir\$VSProjectName\") {
   194         Remove-Item -Recurse "$OutDir\$VSProjectName"
   195     }
   196     Remove-Item "$OutDir\*.exp"
   197     Remove-Item "$OutDir\*.ilk"
   198     Remove-Item "$OutDir\*.pri"
   199 
   200     #
   201     # All done.  Indicate success, or failure, to the caller:
   202     #
   203     #echo "RESULT: $BuildResult" | Out-Host
   204     return $BuildResult
   205 }
   206 
   207 
   208 #
   209 # Build each variant, with corresponding .dll, .lib, and .pdb files:
   210 #
   211 $DidAnyDLLBuildFail = $false
   212 $DidAnyNugetBuildFail = $false
   213 
   214 # Build for Windows Phone 8.0, via VC++ 2012:
   215 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyDLLBuildFail = $true }
   216 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyDLLBuildFail = $true }
   217 
   218 # Build for Windows Phone 8.1, via VC++ 2013:
   219 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyDLLBuildFail = $true }
   220 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyDLLBuildFail = $true }
   221 
   222 # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
   223 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyDLLBuildFail = $true }
   224 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyDLLBuildFail = $true }
   225 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyDLLBuildFail = $true }
   226 
   227 # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
   228 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyDLLBuildFail = $true }
   229 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyDLLBuildFail = $true }
   230 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyDLLBuildFail = $true }
   231 
   232 # Build for Windows 10, via VC++ 2015
   233 if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM"))        { $DidAnyDLLBuildFail = $true }
   234 if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32"))      { $DidAnyDLLBuildFail = $true }
   235 if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64"))        { $DidAnyDLLBuildFail = $true }
   236 
   237 # Build NuGet packages, if possible
   238 if ($DidAnyDLLBuildFail -eq $true) {
   239     Write-Warning -Message "Unable to build all variants.  NuGet packages will not be built."
   240     $DidAnyNugetBuildFail = $true
   241 } else {
   242     $NugetPath = (Get-Command -CommandType Application nuget.exe | %{$_.Path}) 2> $null
   243     if ("$NugetPath" -eq "") {
   244         Write-Warning -Message "Unable to find nuget.exe.  NuGet packages will not be built."
   245         $DidAnyNugetBuildFail = $true
   246     } else {
   247         Write-Host -ForegroundColor Cyan "Building SDL2 NuGet packages..."
   248         Write-Host -ForegroundColor Cyan "... via NuGet install: $NugetPath"
   249         $NugetOutputDir = "$PSScriptRoot\..\VisualC-WinRT\lib\nuget"
   250         Write-Host -ForegroundColor Cyan "...  output directory: $NugetOutputDir"
   251         $SDLHGRevision = $($(hg log -l 1 --repository "$PSScriptRoot\.." | select-string "changeset") -Replace "changeset:\W*(\d+).*",'$1') 2>$null
   252         Write-Host -ForegroundColor Cyan "...       HG Revision: $SDLHGRevision"
   253 
   254         # Base options to nuget.exe
   255         $NugetOptions = @("pack", "PACKAGE_NAME_WILL_GO_HERE", "-Output", "$NugetOutputDir")
   256 
   257         # Try attaching hg revision to NuGet package:
   258         $NugetOptions += "-Version"
   259         if ("$SDLHGRevision" -eq "") {
   260             Write-Warning -Message "Unable to find the Mercurial revision (maybe hg.exe can't be found?).  NuGet packages will not have this attached to their name."
   261             $NugetOptions += "$SDLVersion-Unofficial"
   262         } else {
   263             $NugetOptions += "$SDLVersion.$SDLHGRevision-Unofficial"
   264         }
   265 
   266         # Create NuGet output dir, if not yet created:
   267         if ($(Test-Path "$NugetOutputDir") -eq $false) {
   268             New-Item "$NugetOutputDir" -type directory
   269         }
   270 
   271         # Package SDL2:
   272         $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2-WinRT.nuspec"
   273         &"$NugetPath" $NugetOptions -Symbols
   274         if ( ! $? ) { $DidAnyNugetBuildFail = $true }
   275 
   276         # Package SDL2main:
   277         $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2main-WinRT-NonXAML.nuspec"
   278         &"$NugetPath" $NugetOptions
   279         if ( ! $? ) { $DidAnyNugetBuildFail = $true }
   280     }
   281 }
   282 
   283 
   284 # Let the script's caller know whether or not any errors occurred.
   285 # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
   286 if ($DidAnyDLLBuildFail -eq $true) {
   287     Write-Error -Message "Unable to build all known variants of SDL2 for WinRT"
   288     exit 1
   289 } elseif ($DidAnyNugetBuildFail -eq $true) {
   290     Write-Warning -Message "Unable to build NuGet packages"
   291     exit 0  # Should NuGet package build failure lead to a non-failing result code instead?
   292 } else {
   293     exit 0
   294 }