Skip to content

Commit 1ba6d78

Browse files
Create wheels on Windows (#1015)
* Create wheels on Windows * Statically link run-time libraries on Windows for Python 2.7 * Remove condition in CMakeLists.txt for hiding C++ symbols * Simplify Python 2.7 Windows wheels build.
1 parent 03d3708 commit 1ba6d78

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

.github/workflows/python-package.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,36 @@ jobs:
6666
fail_ci_if_error: true
6767

6868
package_wheels:
69-
name: Package wheels on ${{ matrix.os }}
7069
needs: build
7170
runs-on: ${{ matrix.os }}
7271
strategy:
7372
matrix:
74-
os: [ubuntu-latest, macOS-latest]
73+
os: [ubuntu-latest, macos-latest, windows-latest]
7574
python-build: [cp27*, cp37*, cp38*]
76-
7775
steps:
7876
- uses: actions/checkout@v2
7977

80-
# Used to host cibuildwheel
81-
- uses: actions/setup-python@v2
82-
83-
- name: Install cibuildwheel
84-
run: python -m pip install cibuildwheel==1.10.0
78+
# cibuildwheel 1.12.0 gates Python 2.7 wheels builds
79+
# by using two environment variables, DISTUTILS_USE_SDK and MSSdk.
80+
# https://cibuildwheel.readthedocs.io/en/1.x/cpp_standards/#windows-and-python-27
81+
# Note that normally these are used by setuptools/distutils, but in our case
82+
# they are really just used for cibuildwheel as we don't use any of the
83+
# setuptools/distutils build tools. Our builds are entirely handled
84+
# by CMake. CMake is able to find the right toolchain, thanks to
85+
# the -A argument that we specify in the setup.py to set the
86+
# target platform (x86, x64, etc).
87+
- name: Set Windows Python 2.7 environment variables
88+
if: matrix.python-build == 'cp27*' && runner.os == 'Windows'
89+
shell: bash
90+
run: |
91+
echo "DISTUTILS_USE_SDK=1" >> $GITHUB_ENV
92+
echo "MSSdk=1" >> $GITHUB_ENV
8593
8694
- name: Build wheels
87-
run: python -m cibuildwheel --output-dir wheelhouse
88-
# TODO: Solve for the 32-bit errors in windows python 2.7:
89-
# https://github.com/pybind/cmake_example/blob/master/.github/workflows/wheels.yml#L66
95+
uses: pypa/cibuildwheel@v1.12.0
96+
with:
97+
output-dir: wheelhouse
9098
env:
91-
CIBW_SKIP: cp27-win*
9299
CIBW_BUILD: ${{ matrix.python-build }}
93100

94101
- uses: actions/upload-artifact@v2

CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,23 @@ if(OTIO_SHARED_LIBS)
103103
else()
104104
message(STATUS "Building static libs")
105105
set(OTIO_SHARED_OR_STATIC_LIB "STATIC")
106-
if (OTIO_PYTHON_INSTALL AND NOT MSVC)
106+
if (OTIO_PYTHON_INSTALL)
107107
# If we're compiling for pybind, we can hide all our symbols, they'll only be called from pybind
108-
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
108+
# Note that this has no effect on Windows.
109+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
109110
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
111+
112+
if(MSVC AND Python_VERSION_MAJOR VERSION_LESS 3)
113+
# Statically link run-time library (vcruntime and msvcp)
114+
# See https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-160
115+
# This allows us to compile OTIO bindings with a newer MSVC version
116+
# than the one used by the interpreter where OTIO will be installed.
117+
# This is only required for Python < 3 because only these are
118+
# compiled with an older compiler (9.0). CPython 3.5+ uses at least
119+
# Visual C++ 14.X.
120+
# See https://wiki.python.org/moin/WindowsCompilers#Which_Microsoft_Visual_C.2B-.2B-_compiler_to_use_with_a_specific_Python_version_.3F
121+
add_compile_options(/MT)
122+
endif()
110123
endif()
111124
endif()
112125

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
SOURCE_DIR = os.path.abspath(os.path.dirname(__file__))
2929

30+
PLAT_TO_CMAKE = {
31+
"win32": "Win32",
32+
"win-amd64": "x64",
33+
}
3034

3135
INSTALL_REQUIRES = [
3236
'pyaaf2~=1.4.0',
@@ -103,8 +107,7 @@ def generate_cmake_arguments(self):
103107
]
104108

105109
if platform.system() == "Windows":
106-
if sys.maxsize > 2**32:
107-
cmake_args += ['-A', 'x64']
110+
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
108111

109112
cxx_coverage = bool(os.environ.get("OTIO_CXX_COVERAGE_BUILD"))
110113
if cxx_coverage and not os.environ.get("OTIO_CXX_BUILD_TMP_DIR"):

0 commit comments

Comments
 (0)