From 8ac19d2a5e4a3d959e650fb4dcc2d76fa975eac8 Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Sat, 1 Oct 2022 00:32:42 +0800 Subject: [PATCH] add pip packaging --- .gitignore | 3 ++- CMakeLists.txt | 4 ++-- Makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 22 +++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 0179b220bbd..e094213612c 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,5 @@ docs/python_api/ docs/conf.py docs/Doxyfile docs/getting_started.rst -docs/tensorboard.md \ No newline at end of file +docs/tensorboard.md +wheels diff --git a/CMakeLists.txt b/CMakeLists.txt index ae4b1a9e7b6..869a22297ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,7 +234,7 @@ if(NOT DEFINED Python3_FIND_REGISTRY) # Only consider PATH variable on Windows by default set(Python3_FIND_REGISTRY NEVER) endif() -find_package(Python3 3.6...<3.10 +find_package(Python3 3.6...<3.11 COMPONENTS Interpreter Development ) if (Python3_FOUND) @@ -244,7 +244,7 @@ if (Python3_FOUND) "Deprecated path to the Python executable (for 3rdparty only)" FORCE) else() if (BUILD_PYTHON_MODULE) - message(FATAL_ERROR "BUILD_PYTHON_MODULE=ON requires Python 3.6-3.9. Please ensure it is in PATH.") + message(FATAL_ERROR "BUILD_PYTHON_MODULE=ON requires Python 3.6-3.10. Please ensure it is in PATH.") endif() endif() diff --git a/Makefile b/Makefile new file mode 100644 index 00000000000..03d7049cb9b --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +PROJECT_SOURCE_DIR ?= $(abspath ./) +BUILD_DIR ?= $(PROJECT_SOURCE_DIR)/build +INSTALL_DIR ?= $(BUILD_DIR)/install +NUM_JOB ?= 8 +PYTHON_EXECUTABLE ?= $(shell which python3.7) +WHEELS_DIR ?= $(PROJECT_SOURCE_DIR)/wheels + +all: + @echo nothing special +clean: + rm -rf $(BUILD_DIR) +force_clean: + docker run --rm -v `pwd`:`pwd` -w `pwd` -it alpine/make make clean + +CMAKE_ARGS ?= \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_FILAMENT_FROM_SOURCE=ON \ + -DBUILD_GUI=OFF \ + -DBUILD_PYTHON_MODULE=ON -DPYTHON_EXECUTABLE=$(PYTHON_EXECUTABLE) \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_WEBRTC=OFF \ + -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) +build: + mkdir -p $(WHEELS_DIR) + mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && \ + cmake $(CMAKE_ARGS) $(PROJECT_SOURCE_DIR) && \ + make -j$(NUM_JOBS) && \ + make install pip-package && \ + cp lib/python_package/pip_package/*.whl $(WHEELS_DIR) + +.PHONY: all clean force_clean build + +build_py36_conda: + conda env list | grep '^py36 ' && PYTHON_EXECUTABLE=python BUILD_DIR=$(BUILD_DIR)/py36 conda run --no-capture-output -n py36 make build +build_py37_conda: + conda env list | grep '^py37 ' && PYTHON_EXECUTABLE=python BUILD_DIR=$(BUILD_DIR)/py37 conda run --no-capture-output -n py37 make build +build_py38_conda: + conda env list | grep '^py38 ' && PYTHON_EXECUTABLE=python BUILD_DIR=$(BUILD_DIR)/py38 conda run --no-capture-output -n py38 make build +build_py39_conda: + conda env list | grep '^py39 ' && PYTHON_EXECUTABLE=python BUILD_DIR=$(BUILD_DIR)/py39 conda run --no-capture-output -n py39 make build +build_py310_conda: + conda env list | grep '^py310 ' && PYTHON_EXECUTABLE=python BUILD_DIR=$(BUILD_DIR)/py310 conda run --no-capture-output -n py310 make build +build_wheels_for_conda: build_py36_conda build_py37_conda build_py38_conda build_py39_conda build_py310_conda +.PHONY: build_python_all build_py36 build_py37 build_py38 build_py39 build_py310 + +build_python_all: build_wheels_for_conda +.PHONY: build_python_all + +upload_wheels: + python3 -m pip install twine + twine upload wheels/* -r local + +# https://github.com/orgs/cubao/packages/container/package/build-env-manylinux2014-x64 +MANYLINUX_TAG := ghcr.io/cubao/build-env-manylinux2014-x64:latest +test_in_manylinux: + docker run --rm -v `pwd`:`pwd` -w `pwd` -it $(MANYLINUX_TAG) bash +build_wheels_in_manylinux: + docker run --rm -v `pwd`:`pwd` -w `pwd` -it $(MANYLINUX_TAG) make build_python_all diff --git a/README.md b/README.md index dbf1afa1a23..45f4539ead8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ +> base on + +## packaging pip wheels + +interactive + +``` +make test_in_manylinux +make build_py36_conda +... +``` + +build all wheels + +``` +make build_wheels_in_manylinux +``` + +all wheels goes to `wheels/` dir. + +--- +