Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python and OCIO support #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 113 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ FROM aswf/ci-base:2023.1 as build-stage
RUN alias ll='ls -hl'
RUN yum update -y && yum install tree -y

# Notes on variable names:
# PYENV_VERSION is reserved by pyenv for python version to use
# PYTHON_VERSION is reserved by pybind11 for python version to build for (set latter)

# In order not to depend on the outer internet, this Dockerfile tries to only
# rely on local files. This means that before running it, you will need to
# have downloaded all of the tarballs required to compile the various
Expand All @@ -16,19 +20,20 @@ WORKDIR ${TARBALLS_ROOT}
COPY tarballs ${TARBALLS_ROOT}

# Compile ZLIB
ARG ZLIB_VERSION=1.3
ARG ZLIB_ROOT=/opt/zlib
WORKDIR ${ZLIB_ROOT}
RUN cp ${TARBALLS_ROOT}/zlib-1.3.tar.gz . \
&& tar -xvf zlib-1.3.tar.gz \
&& cd zlib-1.3 \
RUN cp ${TARBALLS_ROOT}/zlib-${ZLIB_VERSION}.tar.gz . \
&& tar -xvf zlib-${ZLIB_VERSION}.tar.gz \
&& cd zlib-${ZLIB_VERSION} \
&& cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${ZLIB_ROOT} \
&& cmake --build build --config Release --target install

# Compile OpenEXR
ARG OPENEXR_VERSION=2.4.15.0
ARG OPENEXR_ROOT=/opt/openexr
WORKDIR ${OPENEXR_ROOT}

RUN cp ${TARBALLS_ROOT}/OpenEXR_v2.4.15.0.tar.gz . \
RUN cp ${TARBALLS_ROOT}/OpenEXR_v${OPENEXR_VERSION}.tar.gz . \
&& tar -xvf OpenEXR_* \
&& mv openexr-*/* . \
&& mv openexr-*/.[!.]* .
Expand All @@ -38,21 +43,23 @@ RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${OPEN
&& cmake --build build --target install --config Release

# Compile Boost
ARG BOOST_VERSION=1_81_0
ARG BOOST_ROOT=/opt/boost
WORKDIR ${BOOST_ROOT}/download
RUN cp ${TARBALLS_ROOT}/boost_1_81_0.tar.bz2 . \
&& tar --bzip2 -xvf boost_1_81_0.tar.bz2
RUN cd boost_1_81_0 \
RUN cp ${TARBALLS_ROOT}/boost_${BOOST_VERSION}.tar.bz2 . \
&& tar --bzip2 -xvf boost_${BOOST_VERSION}.tar.bz2
RUN cd boost_${BOOST_VERSION} \
&& ./bootstrap.sh --prefix=${BOOST_ROOT} \
&& ./b2 install \
&& rm -rf ${BOOST_ROOT}/download

# libtiff
ARG LIBTIFF_VERION=4.0.10
ARG TIFF_ROOT=/opt/tiff
WORKDIR ${TIFF_ROOT}/download
RUN cp ${TARBALLS_ROOT}/tiff-4.0.10.tar.gz . \
&& tar -xvf tiff-4.0.10.tar.gz
RUN cd tiff-4.0.10 \
RUN cp ${TARBALLS_ROOT}/tiff-${LIBTIFF_VERION}.tar.gz . \
&& tar -xvf tiff-${LIBTIFF_VERION}.tar.gz
RUN cd tiff-${LIBTIFF_VERION} \
&& ./configure --prefix=${TIFF_ROOT} \
&& cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${TIFF_ROOT} \
Expand All @@ -61,39 +68,112 @@ RUN cd tiff-4.0.10 \
&& make install

# libraw
ARG LIBRAW_VERSION=0.21.1
ARG LIBRAW_ROOT=/opt/libraw
WORKDIR ${LIBRAW_ROOT}/download
RUN cp ${TARBALLS_ROOT}/LibRaw-0.21.1.tar.gz . \
&& tar -xvf LibRaw-0.21.1.tar.gz
RUN cd LibRaw-0.21.1 \
RUN cp ${TARBALLS_ROOT}/LibRaw-${LIBRAW_VERSION}.tar.gz . \
&& tar -xvf LibRaw-${LIBRAW_VERSION}.tar.gz
RUN cd LibRaw-${LIBRAW_VERSION} \
&& autoreconf -fiv \
&& ./configure --prefix /opt/libraw \
&& make install \
&& cd ../.. && rm -rf download

ARG OIIO_ROOT=/opt/OpenImageIO
WORKDIR ${OIIO_ROOT}

RUN cp ${TARBALLS_ROOT}/OpenImageIO_v2.4.15.0.tar.gz . \
&& tar -xvf OpenImageIO_v2.4.15.0.tar.gz
WORKDIR ${OIIO_ROOT}/OpenImageIO-2.4.15.0

# Compile libjpeg-turbo
# TODO: Use a tarball here too
# https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md
RUN cd src/build-scripts \
&& ./build_libjpeg-turbo.bash

# Copy and compile OpenImageIO
RUN pwd \
ARG LIBJPEGTURBO_VERSION=3.0.0
ARG JPEGTurbo_ROOT=/opt/libjpeg-turbo
ARG LIBJPEGTURBO_INSTALL_DIR=${JPEGTurbo_ROOT}/dist
WORKDIR ${JPEGTurbo_ROOT}
RUN cp ${TARBALLS_ROOT}/libjpeg-turbo_v${LIBJPEGTURBO_VERSION}.tar.gz . \
&& tar -xvf libjpeg-*
RUN cd libjpeg-turbo-${LIBJPEGTURBO_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${LIBJPEGTURBO_INSTALL_DIR} \
.. \
&& cmake --build . --config Release --target install

# OpenColorIO tar build
ARG OPENCOLORIO_VERSION=2.3.0
ARG OpenColorIO_ROOT=/opt/OpenColorIO
ARG OpenColorIO_INSTALL_DIR=${OpenColorIO_ROOT}/dist
WORKDIR ${OpenColorIO_ROOT}
RUN cp ${TARBALLS_ROOT}/OpenColorIO_v${OPENCOLORIO_VERSION}.tar.gz . \
&& tar -xvf OpenColorIO_v${OPENCOLORIO_VERSION}.tar.gz
RUN cd OpenColorIO-${OPENCOLORIO_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${OpenColorIO_INSTALL_DIR} \
-DCMAKE_CXX_FLAGS="-Wno-unused-function -Wno-deprecated-declarations -Wno-cast-qual -Wno-write-strings" \
-DOCIO_BUILD_APPS=OFF -DOCIO_BUILD_NUKE=OFF \
-DOCIO_BUILD_DOCS=OFF -DOCIO_BUILD_TESTS=OFF \
-DOCIO_BUILD_GPU_TESTS=OFF \
-DOCIO_BUILD_PYTHON=OFF -DOCIO_BUILD_PYGLUE=OFF \
-DOCIO_BUILD_JAVA=OFF \
-DBUILD_SHARED_LIBS=ON \
.. \
&& cmake --build . --config Release --target install
# Fix weird syntax error that occurs from build
# Uncertain if $ZLIB_VERSION will match the version OCIO uses. Originally the OCIO build here uses 1.3
RUN sed -i "s;.\#define ZLIB_VERSION \"${ZLIB_VERSION}\"; ;g" ${OpenColorIO_INSTALL_DIR}/lib64/cmake/OpenColorIO/OpenColorIOConfig.cmake


# Install specific python with pyenv
ARG PYTHON_PYENV_VERSION=2.3.31
ARG PYTHON_VERSION_FULL=3.9.10
ARG PYENV_BASE_DIR=/opt/pyenv
WORKDIR ${PYENV_BASE_DIR}
RUN cp ${TARBALLS_ROOT}/pyenv-${PYTHON_PYENV_VERSION}.tar.gz . \
&& tar -xvf pyenv-${PYTHON_PYENV_VERSION}.tar.gz \
&& mkdir pyenv-${PYTHON_PYENV_VERSION}/cache \
&& cp ${TARBALLS_ROOT}/Python-${PYTHON_VERSION_FULL}.tar.xz pyenv-${PYTHON_PYENV_VERSION}/cache/
ENV PYENV_ROOT=${PYENV_BASE_DIR}/pyenv-${PYTHON_PYENV_VERSION}
# python versions are defined per pyenv
ENV PATH ${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}
RUN pyenv install ${PYTHON_VERSION_FULL}
RUN pyenv global ${PYTHON_VERSION_FULL}
RUN pyenv rehash

# Compile pybind11
ARG PYBIND11_VERSION=2.11.1
ARG PYTHON_VERSION_SHORT=3.9
ENV PYBIND11_PYTHON_VERSION ${PYTHON_VERSION_SHORT}
ENV PYTHON_VERSION ${PYTHON_VERSION_SHORT}
ARG PYBIND11_ROOT=/opt/pybind11
ARG PYBIND11_INSTALL_DIR=/opt/pybind11/dist
WORKDIR ${PYBIND11_ROOT}
RUN cp ${TARBALLS_ROOT}/pybind11-${PYBIND11_VERSION}.tar.gz . \
&& tree -L 2 -d \
&& tar -xvf pybind11-*
RUN cd pybind11-${PYBIND11_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${PYBIND11_INSTALL_DIR} \
-DPYBIND11_TEST=OFF \
-DPYBIND11_PYTHON_VERSION=${PYTHON_VERSION} \
.. \
&& cmake --build . --config Release --target install

# Compile OpenImageIO
ARG OPENIMAGEIO_VESION=2.4.15.0
ARG OIIO_ROOT=/opt/OpenImageIO
WORKDIR ${OIIO_ROOT}
RUN cp ${TARBALLS_ROOT}/OpenImageIO_v${OPENIMAGEIO_VESION}.tar.gz . \
&& tar -xvf OpenImageIO_v${OPENIMAGEIO_VESION}.tar.gz
RUN cd OpenImageIO-${OPENIMAGEIO_VESION} \
&& tree -L 2 -d \
&& make -j $(nproc) USE_PYTHON=0 USE_TBB=0 USE_NUKE=0 BUILD_SHARED_LIBS=1 USE_QT=0 \
&& make -j $(nproc) USE_PYTHON=1 USE_TBB=0 USE_NUKE=0 BUILD_SHARED_LIBS=1 USE_QT=0 \
Boost_ROOT=${BOOST_ROOT} \
ZLIB_ROOT=${ZLIB_ROOT}/build \
LibRaw_ROOT=${LIBRAW_ROOT} \
TIFF_ROOT=${TIFF_ROOT} \
OpenEXR_ROOT=${OPENEXR_ROOT}/dist \
JPEGTurbo_ROOT=${OIIO_ROOT}/src/build-scripts/ext/dist \
OpenColorIO_ROOT=${OpenColorIO_INSTALL_DIR} \
JPEGTurbo_ROOT=${LIBJPEGTURBO_INSTALL_DIR} \
Imath_DIR=${OPENEXR_ROOT}/dist/lib64/cmake/Imath

# Create a tarball of the OIIO build
Expand All @@ -106,22 +186,22 @@ RUN yum install patchelf -y

# Copy all the .so files needed by OIIO, except for the ones
# that should be installed on the system (so in /usr and /lib)
RUN ldd ${OIIO_ROOT}/OpenImageIO-2.4.15.0/dist/lib64/libOpenImageIO.so \
RUN ldd ${OIIO_ROOT}/OpenImageIO-${OPENIMAGEIO_VESION}/dist/lib64/libOpenImageIO.so \
| awk '{ print $3 }' | tr -s '\n' \
| grep '/opt' \
> libs_to_copy.txt \
&& mkdir third-party-libs \
&& xargs -a libs_to_copy.txt cp -t third-party-libs \
&& cp ${OIIO_ROOT}/OpenImageIO-2.4.15.0/src/build-scripts/ext/dist/lib64/*.so.* third-party-libs
&& cp ${LIBJPEGTURBO_INSTALL_DIR}/lib64/*.so.* third-party-libs

# Flatten all of the libs into the lib64 directory
# and patch their RPATH
RUN cp -r ${OIIO_ROOT}/OpenImageIO-2.4.15.0/dist . \
RUN cp -r ${OIIO_ROOT}/OpenImageIO-${OPENIMAGEIO_VESION}/dist . \
&& mv third-party-libs/* dist/lib64 \
&& rm -rf dist/lib64/cmake \
&& rm -rf dist/lib64/pkgconfig \
&& rmdir third-party-libs \
&& patchelf --set-rpath '$ORIGIN' dist/lib64/*
&& patchelf --set-rpath '$ORIGIN' $(find dist/lib64/ -maxdepth 1 -type f)

# Patch the binaries
RUN patchelf --set-rpath '$ORIGIN/../lib64' dist/bin/*
Expand Down
11 changes: 11 additions & 0 deletions download_tarballs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mkdir -p tarballs
cd tarballs

# TODO: add sha256 checks for every tarball
# TODO: add tarball support for fmtlib & Tessil (downloaded automatically by OIIO)

# Boost
[ ! -f boost_1_81_0.tar.bz2 ] && wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.bz2
Expand All @@ -19,5 +20,15 @@ cd tarballs
[ ! -f OpenEXR_v2.4.15.0.tar.gz ] && wget https://github.com/AcademySoftwareFoundation/openexr/archive/refs/tags/v3.2.1.tar.gz -O OpenEXR_v2.4.15.0.tar.gz
# OpenImageIO
[ ! -f OpenImageIO_v2.4.15.0.tar.gz ] && wget https://github.com/AcademySoftwareFoundation/OpenImageIO/archive/refs/tags/v2.4.15.0.tar.gz -O OpenImageIO_v2.4.15.0.tar.gz
# OpenColorIO
[ ! -f OpenColorIO_v2.3.0.tar.gz ] && wget https://github.com/AcademySoftwareFoundation/OpenColorIO/archive/refs/tags/v2.3.0.tar.gz -O OpenColorIO_v2.3.0.tar.gz
# Zlib
[ ! -f zlib-1.3.tar.gz ] && wget https://github.com/madler/zlib/releases/download/v1.3/zlib-1.3.tar.gz
# pybind11
[ ! -f pybind11-2.11.1.tar.gz ] && wget https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz -O pybind11-2.11.1.tar.gz
# pyenv
[ ! -f pyenv-2.3.31.tar.gz ] && wget https://github.com/pyenv/pyenv/archive/refs/tags/v2.3.31.tar.gz -O pyenv-2.3.31.tar.gz
# python for pyenv
# Make sure the downloaded version of pyenv supports the downloaded version of python.
[ ! -f Python-3.9.10.tar.xz ] && wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tar.xz