Skip to content

Commit

Permalink
BUG/ENH: Fix several issues pointed out.
Browse files Browse the repository at this point in the history
- Specify the OSX_DEPLOYMENT_TARGET to 10.9.
- Do not link to the actual libpython and instead create a dummy file
  that is used for linking.
- Correctly set the VTK_USE_X flag on APPLE and WIN32.
  • Loading branch information
prabhuramachandran committed Jan 31, 2018
1 parent b4be3da commit 1f7d851
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if(VTKPythonPackage_SUPERBUILD)

option(VTK_OPENGL_HAS_OSMESA "Use OSMesa for offscreen rendering" OFF)
mark_as_advanced(VTK_OPENGL_HAS_OSMESA)
if(VTK_OPENGL_HAS_OSMESA)
if(VTK_OPENGL_HAS_OSMESA OR APPLE OR WIN32)
set(VTK_USE_X OFF)
else()
set(VTK_USE_X ON)
Expand Down
33 changes: 30 additions & 3 deletions scripts/macos_build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,46 @@
from subprocess import check_call
import sys

SCRIPT_DIR = os.path.dirname(__file__)
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
STANDALONE_DIR = os.path.join(ROOT_DIR, "standalone-build")
PROJECT_NAME = "VTK"


def get_dummy_python_lib():
"""Since the python interpreter exports its symbol (see [1]), python modules
should not link against any python libraries. To ensure it is not the case,
we configure the project using an empty file as python library.
[1] "Note that libpythonX.Y.so.1 is not on the list of libraries that a
manylinux1 extension is allowed to link to. Explicitly linking to
libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking
works, extension modules that are loaded into the interpreter automatically
get access to all of the interpreter's symbols, regardless of whether or
not the extension itself is explicitly linked against libpython. [...]"
Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
"""
py_lib = os.path.join(
SCRIPT_DIR, 'internal',
'libpython-not-needed-symbols-exported-by-interpreter'
)

if not os.path.exists(py_lib):
with open(py_lib, 'w') as fp:
fp.write('')
return py_lib


def get_python_info():
py_exe = sys.executable
version = sys.version_info[:2]
py_ver = '{0}.{1}'.format(*version)
prefix = os.path.abspath(sys.prefix)
py_inc_dir = glob.glob(os.path.join(prefix, 'include', 'python*'))[0]
py_lib_dir = os.path.join(prefix, 'lib')
py_lib = os.path.join(py_lib_dir, 'libpython%s.dylib' % py_ver)
py_lib = get_dummy_python_lib()
return py_exe, py_ver, py_inc_dir, py_lib


Expand All @@ -26,6 +52,7 @@ def build_wheel(cleanup=False):
build_type = 'Release'
source_path = "%s/%s-source" % (STANDALONE_DIR, PROJECT_NAME)
build_path = "%s/%s-osx_%s" % (ROOT_DIR, PROJECT_NAME, py_ver)
osx_target="10.9"

# Clean up previous invocations
if cleanup and os.path.exists(build_path):
Expand All @@ -44,6 +71,7 @@ def build_wheel(cleanup=False):
"--",
"-DVTK_SOURCE_DIR:PATH=%s" % source_path,
"-DVTK_BINARY_DIR:PATH=%s" % build_path,
"-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=%s" % osx_target,
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % py_exe,
"-DPYTHON_INCLUDE_DIR:PATH=%s" % py_inc_dir,
"-DPYTHON_LIBRARY:FILEPATH=%s" % py_lib
Expand All @@ -59,4 +87,3 @@ def main():

if __name__ == '__main__':
main()

0 comments on commit 1f7d851

Please sign in to comment.