run_with_env.cmd 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. :: From: https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor/run_with_env.cmd
  2. ::
  3. ::
  4. :: To build extensions for 64 bit Python 3, we need to configure environment
  5. :: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
  6. :: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
  7. ::
  8. :: To build extensions for 64 bit Python 2, we need to configure environment
  9. :: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
  10. :: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
  11. ::
  12. :: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific
  13. :: environment configurations.
  14. ::
  15. :: Note: this script needs to be run with the /E:ON and /V:ON flags for the
  16. :: cmd interpreter, at least for (SDK v7.0)
  17. ::
  18. :: More details at:
  19. :: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
  20. :: http://stackoverflow.com/a/13751649/163740
  21. ::
  22. :: Author: Olivier Grisel
  23. :: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
  24. ::
  25. :: Notes about batch files for Python people:
  26. ::
  27. :: Quotes in values are literally part of the values:
  28. :: SET FOO="bar"
  29. :: FOO is now five characters long: " b a r "
  30. :: If you don't want quotes, don't include them on the right-hand side.
  31. ::
  32. :: The CALL lines at the end of this file look redundant, but if you move them
  33. :: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
  34. :: case, I don't know why.
  35. @ECHO OFF
  36. SET COMMAND_TO_RUN=%*
  37. SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
  38. SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf
  39. :: Extract the major and minor versions, and allow for the minor version to be
  40. :: more than 9. This requires the version number to have two dots in it.
  41. SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
  42. IF "%PYTHON_VERSION:~3,1%" == "." (
  43. SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
  44. ) ELSE (
  45. SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
  46. )
  47. :: Based on the Python version, determine what SDK version to use, and whether
  48. :: to set the SDK for 64-bit.
  49. IF %MAJOR_PYTHON_VERSION% == 2 (
  50. SET WINDOWS_SDK_VERSION="v7.0"
  51. SET SET_SDK_64=Y
  52. ) ELSE (
  53. IF %MAJOR_PYTHON_VERSION% == 3 (
  54. SET WINDOWS_SDK_VERSION="v7.1"
  55. IF %MINOR_PYTHON_VERSION% LEQ 4 (
  56. SET SET_SDK_64=Y
  57. ) ELSE (
  58. SET SET_SDK_64=N
  59. IF EXIST "%WIN_WDK%" (
  60. :: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
  61. REN "%WIN_WDK%" 0wdf
  62. )
  63. )
  64. ) ELSE (
  65. ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
  66. EXIT 1
  67. )
  68. )
  69. IF %PYTHON_ARCH% == 64 (
  70. IF %SET_SDK_64% == Y (
  71. ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
  72. SET DISTUTILS_USE_SDK=1
  73. SET MSSdk=1
  74. "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
  75. "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
  76. ECHO Executing: %COMMAND_TO_RUN%
  77. call %COMMAND_TO_RUN% || EXIT 1
  78. ) ELSE (
  79. ECHO Using default MSVC build environment for 64 bit architecture
  80. ECHO Executing: %COMMAND_TO_RUN%
  81. call %COMMAND_TO_RUN% || EXIT 1
  82. )
  83. ) ELSE (
  84. ECHO Using default MSVC build environment for 32 bit architecture
  85. ECHO Executing: %COMMAND_TO_RUN%
  86. call %COMMAND_TO_RUN% || EXIT 1
  87. )