Skip to content

Commit

Permalink
[Other] Generate Debian package and RPM package (#1043)
Browse files Browse the repository at this point in the history
* cpack deb

* cpack prerm script

* optim postinst script

* generate rpm package

* add build fd package doc

* update build fd package doc
  • Loading branch information
wang-xinyu authored Jan 10, 2023
1 parent df20b2a commit 3e5c219
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ if(WITH_ASCEND)
)
endif()

include(${PROJECT_SOURCE_DIR}/cmake/config_cpack.cmake)

############################### Building: FastDeploy Python Wheel #############################
if(BUILD_FASTDEPLOY_PYTHON)
add_definitions(-DBUILD_FASTDEPLOY_PYTHON)
Expand Down
38 changes: 38 additions & 0 deletions cmake/config_cpack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if(NOT UNIX)
return()
endif()

set(PACKAGE_SYS_VERSION "linux")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-aarch64")
else()
set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-x64")
endif()
if(WITH_GPU)
set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-gpu")
endif()

# set(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION ON)
set(CPACK_VERBATIM_VARIABLES TRUE)
set(CPACK_GENERATOR DEB RPM)
set(CPACK_THREADS 0)
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(CPACK_PACKAGE_VERSION "${FASTDEPLOY_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PACKAGE_SYS_VERSION}-${FASTDEPLOY_VERSION}")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")

set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
configure_file(cpack/debian_postinst.in cpack/postinst @ONLY)
configure_file(cpack/debian_prerm.in cpack/prerm @ONLY)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_BINARY_DIR}/cpack/postinst"
"${CMAKE_CURRENT_BINARY_DIR}/cpack/prerm")

set(CPACK_RPM_PACKAGE_AUTOREQ FALSE)
configure_file(cpack/rpm_postinst.in cpack/rpm_postinst @ONLY)
configure_file(cpack/rpm_postrm.in cpack/rpm_postrm @ONLY)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpack/rpm_postinst")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpack/rpm_postrm")

include(CPack)
42 changes: 42 additions & 0 deletions cpack/debian_postinst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

case "$1" in
configure)
PLATFORM=`uname`
FASTDEPLOY_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@

echo "=============== Information ======================"
echo "FastDeploy Library Path: $FASTDEPLOY_LIBRARY_PATH"
echo "Platform: $PLATFORM"
echo "=================================================="

# Find all the .so files' path
ALL_SO_FILES=`find $FASTDEPLOY_LIBRARY_PATH -name "*.so*"`
for SO_FILE in $ALL_SO_FILES;do
LIBS_DIRECOTRIES[${#LIBS_DIRECOTRIES[@]}]=${SO_FILE%/*}
done

# Remove the dumplicate directories
LIBS_DIRECOTRIES=($(awk -v RS=' ' '!a[$1]++' <<< ${LIBS_DIRECOTRIES[@]}))

IMPORT_PATH=""
for LIB_DIR in ${LIBS_DIRECOTRIES[@]};do
echo "Found Library Directory: $LIB_DIR"
echo ${LIB_DIR} >> @CMAKE_INSTALL_PREFIX@/@[email protected]
done

if [ ! -d /etc/ld.so.conf.d ]; then
mkdir -p /etc/ld.so.conf.d
fi
ln -sf @CMAKE_INSTALL_PREFIX@/@[email protected] /etc/ld.so.conf.d

ldconfig

echo "FastDeploy is successfully installed and configured."
echo "Now please get started with FastDeploy examples at $FASTDEPLOY_LIBRARY_PATH/examples."
echo "And don't forget to set FASTDEPLOY_INSTALL_DIR=$FASTDEPLOY_LIBRARY_PATH in cmake when building examples."
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
esac
12 changes: 12 additions & 0 deletions cpack/debian_prerm.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

case "$1" in
remove|deconfigure)
rm -f /etc/ld.so.conf.d/@[email protected]
rm @CMAKE_INSTALL_PREFIX@/@[email protected]
rm -rf @CMAKE_INSTALL_PREFIX@/third_libs/install/tensorrt/lib/

ldconfig
echo "FastDeploy is going to be uninstalled."
;;
esac
35 changes: 35 additions & 0 deletions cpack/rpm_postinst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

PLATFORM=`uname`
FASTDEPLOY_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@

echo "=============== Information ======================"
echo "FastDeploy Library Path: $FASTDEPLOY_LIBRARY_PATH"
echo "Platform: $PLATFORM"
echo "=================================================="

# Find all the .so files' path
ALL_SO_FILES=`find $FASTDEPLOY_LIBRARY_PATH -name "*.so*"`
for SO_FILE in $ALL_SO_FILES;do
LIBS_DIRECOTRIES[${#LIBS_DIRECOTRIES[@]}]=${SO_FILE%/*}
done

# Remove the dumplicate directories
LIBS_DIRECOTRIES=($(awk -v RS=' ' '!a[$1]++' <<< ${LIBS_DIRECOTRIES[@]}))

IMPORT_PATH=""
for LIB_DIR in ${LIBS_DIRECOTRIES[@]};do
echo "Found Library Directory: $LIB_DIR"
echo ${LIB_DIR} >> @CMAKE_INSTALL_PREFIX@/@[email protected]
done

if [ ! -d /etc/ld.so.conf.d ]; then
mkdir -p /etc/ld.so.conf.d
fi
ln -sf @CMAKE_INSTALL_PREFIX@/@[email protected] /etc/ld.so.conf.d

ldconfig

echo "FastDeploy is successfully installed and configured."
echo "Now please get started with FastDeploy examples at $FASTDEPLOY_LIBRARY_PATH/examples."
echo "And don't forget to set FASTDEPLOY_INSTALL_DIR=$FASTDEPLOY_LIBRARY_PATH in cmake when building examples."
8 changes: 8 additions & 0 deletions cpack/rpm_postrm.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

rm -f /etc/ld.so.conf.d/@[email protected]
rm @CMAKE_INSTALL_PREFIX@/@[email protected]
rm -rf @CMAKE_INSTALL_PREFIX@/third_libs/install/tensorrt/lib/

ldconfig
echo "FastDeploy has been uninstalled."
39 changes: 39 additions & 0 deletions docs/cn/faq/build_fastdeploy_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
中文 | [English](../../en/faq/build_fastdeploy_package.md)

# 编译FastDeploy C++安装包

FastDeploy提供了Debian安装包和RPM安装包的打包工具,用于生成FastDeploy C++ SDK的安装包。相比于Tar压缩包,安装包具有以下优势:
- 安装时,自动运行脚本来配置lib路径,不需要用户手动设置LD_LIBRARY_PATH等环境变量
- 自动管理依赖库关系和版本,自动安装依赖项

## Debian安装包

Debian安装包适用于Debian系列的Linux发行版,例如Ubuntu

```
# 设置编译选项,运行cmake和make
cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy
make -j
# 运行cpack,生成.deb安装包
cpack -G DEB
# 安装.deb
dpkg -i xxx.deb
```

## RPM安装包

RPM安装包适用于RedHat系列的Linux发行版,例如CentOS

```
# 设置编译选项,运行cmake和make
cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy
make -j
# 运行cpack,生成.rpm安装包
cpack -G RPM
# 安装.rpm
rpm -i xxx.rpm
```
39 changes: 39 additions & 0 deletions docs/en/faq/build_fastdeploy_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
English | [中文](../../cn/faq/build_fastdeploy_package.md)

# Build FastDeploy C++ SDK Installation Package

FastDeploy provides packaging tools for Debian installation packages and RPM installation packages, which are used to generate installation packages for FastDeploy C++ SDK. Compared with the Tar compression package, the installation package has the following advantages:
- During installation, the script is automatically run to configure the lib path, so that users don't need to manually set environment variables such as LD_LIBRARY_PATH
- Automatically manage dependencies and versions, and automatically install dependencies

## Debian Package

Debian Package is for Linux distributions of the Debian family, such as Ubuntu

```
# Setup build options, run cmake and make
cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy
make -j
# Run cpack to generate a .deb package
cpack -G DEB
# Install .deb package
dpkg -i xxx.deb
```

## RPM Package

RPM Package is for Linux distributions of the RedHat family, such as CentOS

```
# Setup build options, run cmake and make
cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy
make -j
# Run cpack to generate a .rpm package
cpack -G RPM
# Install .rpm package
rpm -i xxx.rpm
```

0 comments on commit 3e5c219

Please sign in to comment.