Skip to content

Commit

Permalink
Copy dll into source tree when building on windows
Browse files Browse the repository at this point in the history
There is no auditwheel-like tool for python wheels on windows, which
means segyio must manually bundle the segyio core dll with the wheel.
setuptools is *very* pick and assumes everything is relative paths
downwards, and always run from root in the source directory, which means
grabbing a copy of the just-in-time built dll is non-trivial.

On windows, copy the dll into the source directory, like version.py is
written by setuptools.This ensures setuptools find the dll when it's
making the python package, and copies it in accordingly.
  • Loading branch information
jokva committed Jan 26, 2018
1 parent cfdb92b commit 178c307
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python/segyio/version.py
python/segyio/segyio.dll
17 changes: 16 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ set(python ${PYTHON_EXECUTABLE})

if (NOT WIN32)
# setuptools on microsoft compilers doesn't support the --library-dir or
# --buil-dir flag and crashes, so only pass it on non-microsoft platforms
# --build-dir flag and crashes, so only pass it on non-microsoft platforms
set(setup-py-libdir build_ext
--rpath $<TARGET_FILE_DIR:segyio-shared>
--library-dirs $<TARGET_FILE_DIR:segyio-shared>)

set(install-no-rpath install_lib --build-dir build/install)
set(build-no-rpath --library-dirs $<TARGET_FILE_DIR:segyio-shared>
build --build-lib build/install)
else ()
set(copy-dll-to-src ${CMAKE_COMMAND} -E
copy $<TARGET_FILE:segyio-shared>
${CMAKE_CURRENT_SOURCE_DIR}/segyio/$<TARGET_FILE_NAME:segyio-shared>)
endif ()


set(setup-py ${CMAKE_SOURCE_DIR}/setup.py)
add_custom_target(
segyio-python ALL
Expand Down Expand Up @@ -68,6 +73,16 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_LINKER_FILE:segyio-shared>
$<TARGET_LINKER_FILE_NAME:segyio-shared>

# on windows, copy the freshly-built dll to the source directory. this
# voilates the cmake spirit (as does the version.py writing from
# setuptools-scm), but there's no auditwheel like tool to help fix the
# wheel, and the dll must still be bundled in order to make the package
# work. it's paired with package_data in setup.py. this is necessary
# because setup.py assumes all files to bundled with the package are
# relative downwards and in the package itself, with poor support for
# grabbing other files and adding to it later.
COMMAND ${copy-dll-to-src}

# install the lib in the build-dir so that the examples can load that from
# current working dir
COMMAND ${python} ${setup-py} ${setup-py-libdir} install_lib -d .
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def getversion():
url='https://github.com/Statoil/segyio',
package_dir={'' : src('python')},
packages=['segyio'],
package_data={'': ['License', 'README']},
package_data={ 'segyio': ['segyio.dll'], },
license='LGPL-3.0',
ext_modules=[Extension('segyio._segyio',
sources=[src('python/segyio/segyio.cpp')],
Expand Down

0 comments on commit 178c307

Please sign in to comment.