forked from google-ai-edge/mediapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dockerfiles to allow users to build their own wheels
PiperOrigin-RevId: 714278145
- Loading branch information
1 parent
953080d
commit 765452e
Showing
3 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# 2025 Copyright 2020 The MediaPipe Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# A docker image that contains the PyPA aarch64rp4 manylinux2014 toolchain and | ||
# bazel 6.5.0. The image produces MediaPipe rasberryPi wheels for Python 3.12. | ||
# and puts the output wheel files in /wheelhouse/. | ||
# | ||
# Usage: | ||
# $ docker build -f Dockerfile.manylinux2014_aarch64rp4 -t mp_manylinux_aarch64rp4 . | ||
# $ docker create -ti --name mp_pip_package_container mp_manylinux_aarch64rp4:latest | ||
# $ docker cp mp_pip_package_container:/wheelhouse/. wheelhouse/ | ||
# $ docker rm -f mp_pip_package_container | ||
|
||
FROM quay.io/pypa/manylinux2014_aarch64 | ||
|
||
# Install Bazel | ||
RUN curl -L -o bazel https://github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-linux-arm64 | ||
RUN chmod +x bazel | ||
RUN mv ./bazel /usr/local/bin | ||
|
||
# Copy Protobuf Compiler binary | ||
ARG PROTOC_ZIP=protoc-3.19.1-linux-aarch_64.zip | ||
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/$PROTOC_ZIP | ||
RUN unzip -o $PROTOC_ZIP -d /usr/local bin/protoc | ||
RUN unzip -o $PROTOC_ZIP -d /usr/local 'include/*' | ||
RUN rm -f $PROTOC_ZIP | ||
|
||
# Install Clang 18 | ||
RUN yum install -y wget gcc-c++ cmake | ||
RUN mkdir /tmp/llvm-project && wget -qO - https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-18.1.8.tar.gz | tar -xz -C /tmp/llvm-project --strip-components 1 && \ | ||
mkdir /tmp/llvm-project/build && cd /tmp/llvm-project/build && cmake -DLLVM_ENABLE_PROJECTS='clang;lld' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-18/ ../llvm && \ | ||
make -j$(nproc) && make -j$(nproc) install && rm -rf /tmp/llvm-project | ||
|
||
# Install OpenGL | ||
RUN yum install -y -v mesa-libGL mesa-libGL-devel mesa-libEGL mesa-libEGL-devel | ||
RUN yum install -y -v mesa-libGLES-devel | ||
|
||
# Install EPEL 7, Java 11, and other small packages. | ||
RUN yum install -y -v https://archives.fedoraproject.org/pub/archive/epel/7/aarch64/Packages/e/epel-release-7-12.noarch.rpm | ||
RUN yum install -y -v java-11-openjdk java-11-openjdk-devel zip emacs portaudio-devel | ||
|
||
# Install OpenSSL. | ||
RUN curl -OL https://www.openssl.org/source/openssl-1.1.1.tar.gz | ||
RUN tar -xvzf openssl-1.1.1.tar.gz && cd openssl-1.1.1 && \ | ||
./Configure linux-aarch64 --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib && \ | ||
make -j$(($(nproc)+1)) && \ | ||
make install | ||
RUN echo 'LD_LIBRARY_PATH=/usr/local/ssl/lib:${LD_LIBRARY_PATH}' >> /etc/environment | ||
RUN rm openssl-1.1.1.tar.gz | ||
RUN rm openssl-1.1.1 -r | ||
|
||
# Install OpenCV. | ||
WORKDIR /tmp/bazel_build | ||
RUN git clone https://github.com/opencv/opencv.git | ||
RUN mkdir opencv/release | ||
RUN cd /tmp/bazel_build/opencv && git checkout 4.10.0 && cd release && cmake .. \ | ||
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang -DCMAKE_CXX_COMPILER=/usr/lib/llvm-18/bin/clang++ \ | ||
-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local \ | ||
-DBUILD_SHARED_LIBS=OFF -DBUILD_LIST=imgproc,core \ | ||
-DWITH_ITT=OFF -DWITH_IPP=OFF -DBUILD_EXAMPLES=OFF \ | ||
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_ts=OFF \ | ||
-DCV_ENABLE_INTRINSICS=ON -DWITH_EIGEN=ON -DWITH_PTHREADS=ON -DWITH_PTHREADS_PF=ON | ||
RUN cd /tmp/bazel_build/opencv/release && make -j 16 && make install | ||
|
||
# Compile Python 3.12 | ||
WORKDIR /tmp/bazel_build | ||
RUN curl -O https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz | ||
RUN tar -xzf Python-3.12.0.tgz && cd Python-3.12.0 && \ | ||
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure && \ | ||
./configure --enable-optimizations --with-openssl=/usr/local/ssl --with-openssl-rpath=auto && \ | ||
make altinstall | ||
|
||
COPY . /mediapipe/ | ||
WORKDIR /mediapipe | ||
|
||
# Set version number | ||
RUN MP_VERSION_NUMBER=$(awk '/MEDIAPIPE_FULL_VERSION/ {split($0, a, "="); print a[2]}' version.bzl | sed 's/[" ]//g') && \ | ||
sed -i "s/__version__ = 'dev'/__version__ = '${MP_VERSION_NUMBER}'/g" setup.py | ||
|
||
# Set build flags for MediaPipe and OpenCV. | ||
RUN echo "build --client_env=CC=/usr/lib/llvm-18/bin/clang++" >> .bazelrc && \ | ||
echo "build --define=xnn_enable_avxvnniint8=false" >> .bazelrc && \ | ||
sed -i "s/path = \"\/usr\"/path = \"\/usr\/local\"/g" WORKSPACE && \ | ||
echo 'cc_library(name = "opencv", srcs = ["lib64/libopencv_imgproc.a", "lib64/libopencv_core.a"],hdrs = glob(["include/opencv4/opencv2/**/*.h*"]), includes = ["include/opencv4/"], linkstatic = 1, visibility = ["//visibility:public"])' > third_party/opencv_linux.BUILD && \ | ||
sed -i "s|bazel_command.append('--define=OPENCV=source')|pass|g" setup.py | ||
|
||
# Apply diff to reduce the number of OpenCV dependencies. | ||
RUN patch -p1 < mediapipe_python_build.diff | ||
|
||
ARG PYTHON_BIN="/opt/python/cp312-cp312/bin/python3.12" | ||
RUN ln -sf $PYTHON_BIN /usr/bin/python && \ | ||
ln -sf $PYTHON_BIN /usr/bin/python3 && \ | ||
$PYTHON_BIN -m pip install wheel "numpy<2" auditwheel && \ | ||
$PYTHON_BIN setup.py bdist_wheel clean --all | ||
RUN auditwheel repair dist/*.whl | ||
|
||
RUN mkdir /wheelhouse/ && cp dist/* /wheelhouse/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright 2025 The MediaPipe Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# A docker image that contains the PyPA manylinux2014 toolchain and | ||
# bazel 6.5.0 and opencv 4.10 static libraries. The image produces MediaPipe | ||
# manylinux wheels and puts the output wheel files in /wheelhouse/. | ||
# | ||
# Usage: | ||
# $ DOCKER_BUILDKIT=1 docker build -f Dockerfile.manylinux_2_28_x86_64 -t mp_manylinux . --build-arg "PYTHON_BIN=/opt/python/cp312-cp312/bin/python3.12" | ||
# $ docker create -ti --name mp_pip_package_container mp_manylinux:latest | ||
# $ docker cp mp_pip_package_container:/wheelhouse/. wheelhouse/ | ||
# $ docker rm -f mp_pip_package_container | ||
|
||
# Make a container for MediaPipe | ||
FROM quay.io/pypa/manylinux_2_28_x86_64 | ||
|
||
|
||
ARG MEDIAPIPE_DISABLE_GPU=1 | ||
ENV MEDIAPIPE_DISABLE_GPU=${MEDIAPIPE_DISABLE_GPU} | ||
|
||
RUN yum install -y java-11-openjdk-devel zip | ||
WORKDIR /tmp/bazel_build | ||
ADD https://github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-dist.zip bazel.zip | ||
RUN unzip bazel.zip | ||
RUN rm -f bazel.zip | ||
ENV PATH="/opt/python/cp36-cp36m/bin:${PATH}" | ||
ENV EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" | ||
ENV BAZEL_LINKLIBS=-lm:-lstdc++ | ||
RUN ./compile.sh | ||
RUN cp /tmp/bazel_build/output/bazel /bin/bazel | ||
|
||
|
||
# Install Clang 18 | ||
RUN --mount=type=cache,target=/var/cache/dnf dnf install -y wget gcc-c++ && dnf clean all | ||
RUN mkdir /tmp/llvm-project && wget -qO - https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-18.1.8.tar.gz | tar -xz -C /tmp/llvm-project --strip-components 1 && \ | ||
mkdir /tmp/llvm-project/build && cd /tmp/llvm-project/build && cmake -DLLVM_ENABLE_PROJECTS='clang;lld' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-18/ ../llvm && \ | ||
make -j$(nproc) && make -j$(nproc) install && rm -rf /tmp/llvm-project | ||
|
||
# Install OpenGL | ||
RUN yum install -y mesa-libGL mesa-libGL-devel mesa-libEGL mesa-libEGL-devel | ||
RUN yum install -y mesa-libGLES-devel | ||
|
||
# Install Java, zip, emacs, and portaudio. | ||
RUN yum install -y epel-release && yum install -y java-11-openjdk \ | ||
java-11-openjdk-devel zip emacs portaudio-devel | ||
|
||
# Copy Protobuf Compiler binary | ||
ARG PROTOC_ZIP=protoc-25.1-linux-x86_64.zip | ||
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.1/$PROTOC_ZIP | ||
RUN unzip -o $PROTOC_ZIP -d /usr/local bin/protoc | ||
RUN unzip -o $PROTOC_ZIP -d /usr/local 'include/*' | ||
RUN rm -f $PROTOC_ZIP | ||
|
||
# Install OpenCV. | ||
RUN yum install -y cmake | ||
WORKDIR /tmp/bazel_build | ||
RUN git clone https://github.com/opencv/opencv.git | ||
RUN mkdir opencv/release | ||
RUN cd /tmp/bazel_build/opencv && git checkout 4.10.0 && cd release && cmake .. \ | ||
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang -DCMAKE_CXX_COMPILER=/usr/lib/llvm-18/bin/clang++ \ | ||
-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local \ | ||
-DBUILD_SHARED_LIBS=OFF -DBUILD_LIST=imgproc,core \ | ||
-DWITH_ITT=OFF -DWITH_IPP=OFF -DBUILD_EXAMPLES=OFF \ | ||
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_ts=OFF \ | ||
-DCV_ENABLE_INTRINSICS=ON -DWITH_EIGEN=ON -DWITH_PTHREADS=ON -DWITH_PTHREADS_PF=ON | ||
RUN cd /tmp/bazel_build/opencv/release && make -j 16 && make install | ||
|
||
COPY . /mediapipe/ | ||
WORKDIR /mediapipe | ||
|
||
# Set version number | ||
RUN export MP_VERSION_NUMBER=$(awk '/MEDIAPIPE_FULL_VERSION/ {split($0, a, "="); print a[2]}' version.bzl | sed 's/[" ]//g') && \ | ||
sed -i "s/__version__ = 'dev'/__version__ = '${MP_VERSION_NUMBER}'/g" setup.py | ||
|
||
# Set build flags for MediaPipe and OpenCV. | ||
RUN echo "build --client_env=CC=/usr/lib/llvm-18/bin/clang++" >> .bazelrc && \ | ||
echo "build --define=xnn_enable_avxvnniint8=false" >> .bazelrc && \ | ||
echo 'cc_library(name = "opencv", srcs = ["local/lib64/libopencv_imgproc.a", "local/lib64/libopencv_core.a"],hdrs = glob(["local/include/opencv4/opencv2/**/*.h*"]), includes = ["local/include/opencv4/"], linkstatic = 1, visibility = ["//visibility:public"])' > third_party/opencv_linux.BUILD && \ | ||
sed -i "s|bazel_command.append('--define=OPENCV=source')|pass|g" setup.py | ||
|
||
# Apply diff to reduce the number of OpenCV dependencies. | ||
RUN patch -p1 < mediapipe_python_build.diff | ||
|
||
ARG PYTHON_BIN="/opt/python/cp312-cp312/bin/python3.12" | ||
RUN $PYTHON_BIN -m pip install --upgrade pip setuptools | ||
RUN $PYTHON_BIN -m pip install wheel "numpy<2" auditwheel torch pyaudio | ||
RUN ln -sf $PYTHON_BIN /usr/bin/python && \ | ||
ln -sf $PYTHON_BIN /usr/bin/python3 && \ | ||
$PYTHON_BIN setup.py bdist_wheel clean --all | ||
RUN auditwheel repair dist/*-cp312-cp312-linux_x86_64.whl | ||
|
||
RUN mkdir /wheelhouse/ && cp dist/* /wheelhouse/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
diff --git a/mediapipe/python/BUILD b/mediapipe/python/BUILD | ||
index 5837be764..8b2ae4541 100644 | ||
--- a/mediapipe/python/BUILD | ||
+++ b/mediapipe/python/BUILD | ||
@@ -21,18 +21,13 @@ package(default_visibility = ["//visibility:public"]) | ||
pybind_extension( | ||
name = "_framework_bindings", | ||
srcs = ["framework_bindings.cc"], | ||
- linkopts = select({ | ||
- "//third_party:opencv_source_build": [], | ||
- "//conditions:default": [ | ||
- "-lopencv_core", | ||
- "-lopencv_imgproc", | ||
- "-lopencv_highgui", | ||
- "-lopencv_video", | ||
- "-lopencv_features2d", | ||
- "-lopencv_calib3d", | ||
- "-lopencv_imgcodecs", | ||
- ], | ||
- }), | ||
+ linkopts = [ | ||
+ "-L/usr/local/lib64/libopencv_core.a", | ||
+ "-L/usr/local/lib64/libopencv_imgproc.a", | ||
+ "-lm", | ||
+ "-lpthread", | ||
+ "-lstdc++", | ||
+ ], | ||
module_name = "_framework_bindings", | ||
deps = [ | ||
":builtin_calculators", |