Skip to content

Commit

Permalink
Create wheels on Windows (#1015)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
JeanChristopheMorinPerso committed Sep 24, 2021
1 parent 03d3708 commit 1ba6d78
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,36 @@ jobs:
fail_ci_if_error: true

package_wheels:
name: Package wheels on ${{ matrix.os }}
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
python-build: [cp27*, cp37*, cp38*]

steps:
- uses: actions/checkout@v2

# Used to host cibuildwheel
- uses: actions/setup-python@v2

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

- uses: actions/upload-artifact@v2
Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,23 @@ if(OTIO_SHARED_LIBS)
else()
message(STATUS "Building static libs")
set(OTIO_SHARED_OR_STATIC_LIB "STATIC")
if (OTIO_PYTHON_INSTALL AND NOT MSVC)
if (OTIO_PYTHON_INSTALL)
# If we're compiling for pybind, we can hide all our symbols, they'll only be called from pybind
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Note that this has no effect on Windows.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

if(MSVC AND Python_VERSION_MAJOR VERSION_LESS 3)
# Statically link run-time library (vcruntime and msvcp)
# See https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-160
# This allows us to compile OTIO bindings with a newer MSVC version
# than the one used by the interpreter where OTIO will be installed.
# This is only required for Python < 3 because only these are
# compiled with an older compiler (9.0). CPython 3.5+ uses at least
# Visual C++ 14.X.
# See https://wiki.python.org/moin/WindowsCompilers#Which_Microsoft_Visual_C.2B-.2B-_compiler_to_use_with_a_specific_Python_version_.3F
add_compile_options(/MT)
endif()
endif()
endif()

Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

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

PLAT_TO_CMAKE = {
"win32": "Win32",
"win-amd64": "x64",
}

INSTALL_REQUIRES = [
'pyaaf2~=1.4.0',
Expand Down Expand Up @@ -103,8 +107,7 @@ def generate_cmake_arguments(self):
]

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

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

0 comments on commit 1ba6d78

Please sign in to comment.