Skip to content

Commit

Permalink
Fix linux / mac wheels
Browse files Browse the repository at this point in the history
Signed-off-by: Rémi Achard <remiachard@gmail.com>
  • Loading branch information
remia committed Jul 6, 2023
1 parent 9e21f4d commit 1dbce4f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ endif()
option(OCIO_USE_SSE "Specify whether to enable SSE CPU performance optimizations" ON)
option(OCIO_USE_OIIO_FOR_APPS "Request OIIO to build apps (ociolutimage, ocioconvert and ociodisplay), the default uses OpenEXR." OFF)

option(OCIO_NO_SONAME "Disable version symlink for OpenColorIO library" OFF)
set (OCIO_PYTHON_INSTALL_RPATH "" CACHE STRING
"Specify the RPATHs to install for the Python module (darwin and linux only)")


###############################################################################
# GPU configuration
Expand Down
46 changes: 38 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ def get_version():
shutil.rmtree(dirpath)


# Remove symlinks as Python wheels do not support them at the moment.
# Rename the remaining dylib to the expected install name (major.minor).
def patch_symlink(folder):
if sys.platform.startswith("darwin"):
VERSION_REGEX = re.compile(
r"^libOpenColorIO.(?P<major>\d+).(?P<minor>\d+).\d+.dylib$")
NAME_PATTERN = "libOpenColorIO.{major}.{minor}.dylib"
elif sys.platform.startswith("linux"):
VERSION_REGEX = re.compile(
r"^libOpenColorIO.so.(?P<major>\d+).(?P<minor>\d+).\d+$")
NAME_PATTERN = "libOpenColorIO.so.{major}.{minor}"
else:
return

# First remove all symlinks in the folder
for f in os.listdir(folder):
filepath = os.path.join(folder, f)
if os.path.islink(filepath):
os.remove(filepath)

# Then match the remaining OCIO dynamic lib and rename it
for f in os.listdir(folder):
filepath = os.path.join(folder, f)
match = VERSION_REGEX.search(f)
if match:
res = match.groupdict()
new_filename = NAME_PATTERN.format(
major=res["major"], minor=res["minor"])
new_filepath = os.path.join(folder, new_filename)
os.rename(filepath, new_filepath)
break


# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
"win32": "Win32",
Expand Down Expand Up @@ -79,8 +112,6 @@ def build_extension(self, ext):
# Not used on MSVC, but no harm
"-DCMAKE_BUILD_TYPE={}".format(cfg),
"-DBUILD_SHARED_LIBS=ON",
# Wheels do not support symlinks resulting in OCIO lib duplicated 3 times otherwise
"-DOCIO_NO_SONAME=ON",
"-DOCIO_BUILD_DOCS=ON",
"-DOCIO_BUILD_APPS=ON",
"-DOCIO_BUILD_TESTS=OFF",
Expand Down Expand Up @@ -139,13 +170,10 @@ def build_extension(self, ext):
# When building the wheel, the install step is not executed so we need
# to have the correct RPATH directly from the build tree output.
cmake_args += ["-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON"]
# Install custom RPATH matching the wheel layout
if sys.platform.startswith("linux"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("$ORIGIN")]
cmake_args += ["-DOCIO_PYTHON_INSTALL_RPATH={}".format("$ORIGIN/..")]
elif sys.platform.startswith("darwin"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("@loader_path")]
cmake_args += ["-DOCIO_PYTHON_INSTALL_RPATH={}".format("@loader_path/..")]
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("$ORIGIN;$ORIGIN/..")]
if sys.platform.startswith("darwin"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("@loader_path;@loader_path/..")]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
Expand All @@ -166,6 +194,8 @@ def build_extension(self, ext):
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)

patch_symlink(extdir)


# For historical reason, we use PyOpenColorIO as the import name
setup(
Expand Down
1 change: 0 additions & 1 deletion src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ set_target_properties(OpenColorIO PROPERTIES
LINK_OPTIONS "${CUSTOM_LINK_FLAGS}"
VERSION ${OpenColorIO_VERSION}
SOVERSION ${SOVERSION}
NO_SONAME ${OCIO_NO_SONAME}
PUBLIC_HEADER "${INSTALL_HEADERS}"
)

Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ if(UNIX)
set_property(TARGET PyOpenColorIO PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

if (UNIX AND NOT CMAKE_SKIP_RPATH AND NOT OCIO_PYTHON_INSTALL_RPATH)
if (UNIX AND NOT CMAKE_SKIP_RPATH AND NOT CMAKE_INSTALL_RPATH)
# Update the default RPATH so the Python binding dynamic library can find the OpenColorIO
# dynamic library based on the default installation directory structure.
if (APPLE)
Expand Down

0 comments on commit 1dbce4f

Please sign in to comment.