Add more Linux packaging format (#89)

* Arch Linux packaging; make LIBEXECDIR configurable

* update docs

* resolve libexec and share from relative path

* AppImage packaging

* allow build AppImage on Windows host
This commit is contained in:
Cyano Hao 2023-01-03 12:18:02 +08:00 committed by GitHub
parent 9296877b86
commit 375e990e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 375 additions and 39 deletions

14
.gitattributes vendored Normal file
View File

@ -0,0 +1,14 @@
##########################
# AppImage on Windows host
##########################
# script run in docker
/packages/appimage/01-in-docker.sh eol=lf
# text files to be packed
/platform/linux/install.sh eol=lf
/platform/linux/redpandaide.desktop.in eol=lf
/platform/linux/templates/*/*.txt eol=lf
/platform/linux/templates/*/*.template eol=lf
/platform/linux/templates/*/*.fs eol=lf
/platform/linux/templates/*/*.vs eol=lf

6
.gitignore vendored
View File

@ -1,3 +1,7 @@
/.vs /.vs
/dist
/packages/appimage/*/*.AppImage
/packages/archlinux/*
!/packages/archlinux/PKGBUILD
*.bak *.bak
*.pro.user *.pro.user

View File

@ -13,4 +13,85 @@
# Linux # Linux
- Install gcc and qt5 - Install gcc and qt5
- Use qtcreator to open Red_Panda_CPP.pro - Open `Red_Panda_CPP.pro` with Qt Creator
qmake variables:
- `PREFIX`: default to `/usr/local`. It should be set to `/usr` or `/opt/redpanda-cpp` when packaging.
- `LIBEXECDIR`: directory for auxiliary executables, default to `$PREFIX/libexec`. Arch Linux uses `/usr/lib`.
## Ubuntu
### 1. Install Compiler
```bash
apt install gcc g++ make gdb gdbserver
```
### 2. Install Qt 5 and Other Dependencies
```bash
apt install qtbase5-dev qttools5-dev-tools libicu-dev libqt5svg5-dev git qterminal
```
### 3. Fetch Source Code
```bash
git clone https://github.com/royqh1979/RedPanda-CPP.git
```
### 4. Build
```bash
cd RedPanda-CPP/
qmake Red_Panda_CPP.pro
make -j$(nproc)
sudo make install
```
### 5. Run
```bash
RedPandaIDE
```
## Arch Linux
A reference PKGBUILD is available at `packages/archlinux`. Build RedPanda C++ with [makepkg](https://wiki.archlinux.org/title/Makepkg) and then install.
Enter `RedPandaIDE` to launch RedPanda C++.
Note that makepkg checks out HEAD of the repo, so any change should be committed before building.
## AppImage
1. Install dependency: cURL, Docker.
Extra requirements for Windows host:
- Docker uses WSL 2 based engine, or enable file sharing on the project folder (Settings > Resources > File sharing);
- PowerShell (previously “PowerShell Core”, not “Windows PowerShell”).
2. Prepare build environment. Linux host:
```bash
arch=x86_64 # or aarch64
curl -L -o packages/appimage/dockerfile-$arch/appimagetool-$arch.AppImage https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-$arch.AppImage
docker build -t redpanda-builder-$arch packages/appimage/dockerfile-$arch
```
Windows host:
```ps1
$arch = "x86_64" # or "aarch64" someday Docker is available on WoA
Invoke-WebRequest -OutFile packages/appimage/dockerfile-$arch/appimagetool-$arch.AppImage -Uri https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-$arch.AppImage
docker build -t redpanda-builder-$arch packages/appimage/dockerfile-$arch
```
3. Build AppImage. Linux host:
```bash
./packages/appimage/build-x86_64.sh # or *-aarch64.sh
```
Windows host:
```ps1
./packages/appimage/build-x86_64.ps1 # or *-aarch64.ps1 someday Docker is available on WoA
```
4. Run Red Panda C++.
```bash
./dist/RedPandaIDE-x86_64.AppImage # or *-aarch64.AppImage
```
Note: AppImage, in which format AppImageKit is shipped, is incompatable with QEMU user space emulator, so you cannot build AArch64 AppImage on x86-64, and vice versa.

View File

@ -1,55 +1,100 @@
# 依赖 # 依赖
小熊猫C++需要Qt 5(>=5.12) 小熊猫C++需要Qt 5(>=5.12)
# Windows # Windows
我使用msys2打包的最新版的GCC和MinGW-w64工具链来编译小熊猫C++。VC和其他版本的gcc不一定能够正常编译。 我使用msys2打包的最新版的GCC和MinGW-w64工具链来编译小熊猫C++。VC和其他版本的gcc不一定能够正常编译。
编译步骤: 编译步骤:
- 安装msys2 (https://www.msys2.org) - 安装msys2 (https://www.msys2.org)
- 使用msys2的pacman程序安装mingw-w64-x86_64-qt5和mingw-w64-x86_64-gcc - 使用msys2的pacman程序安装mingw-w64-x86_64-qt5和mingw-w64-x86_64-gcc
- 安装qtcreator - 安装qtcreator
- 使用qtcreator打开Red_Panda_CPP.pro文件 - 使用qtcreator打开Red_Panda_CPP.pro文件
# Linux # Linux
步骤: 步骤:
- 安装 gcc 和 qt5开发相关包 - 安装 gcc 和 qt5开发相关包
- 使用qtcreator打开Red_Panda_CPP.pro文件 - 使用qtcreator打开Red_Panda_CPP.pro文件
qmake 变量:
- `PREFIX`:默认值是 `/usr/local`。打包时应该定义为 `/usr``/opt/redpanda-cpp`
- `LIBEXECDIR`:辅助程序的路径,默认值是 `$PREFIX/libexec`。Arch Linux 使用 `/usr/lib`
## Ubuntu ## Ubuntu
### 1.安装编译器 ### 1.安装编译器
```text ```bash
apt install gcc g++ make gdb gdbserver apt install gcc g++ make gdb gdbserver
``` ```
### 2.安装QT5和依赖包 ### 2.安装QT5和依赖包
```text ```bash
apt install qtbase5-dev qttools5-dev-tools libicu-dev libqt5svg5-dev git qterminal apt install qtbase5-dev qttools5-dev-tools libicu-dev libqt5svg5-dev git qterminal
``` ```
### 3.下载源码 ### 3.下载源码
``` ```bash
git clone https://gitee.com/royqh1979/RedPanda-CPP.git git clone https://gitee.com/royqh1979/RedPanda-CPP.git
``` ```
### 4.编译 ### 4.编译
``` ```bash
cd cd RedPanda-CPP/ cd RedPanda-CPP/
qmake Red_Panda_CPP.pro qmake Red_Panda_CPP.pro
make -j8 make -j$(nproc)
sudo make install sudo make install
``` ```
### 5.运行 ### 5.运行
``` ```bash
RedPandaIDE RedPandaIDE
``` ```
## Arch Linux 及衍生版本
`packages/archlinux` 目录下提供了一个参考 PKGBUILD使用 [makepkg](https://wiki.archlinuxcn.org/wiki/Makepkg) 构建小熊猫 C++ 并安装。
小熊猫 C++ 可以通过 `RedPandaIDE` 命令启动。
注意makepkg 签出此存储库的 HEAD因此构建之前务必提交所有变更。
## AppImage
1. 安装依赖包cURL、Docker。
Windows 宿主的额外要求:
- Docker 使用基于 WSL 2 的引擎或者对此项目文件夹启用文件共享Settings > Resources > File sharing
- PowerShell曾用名 “PowerShell Core”不是 “Windows PowerShell”
2. 准备构建环境。Linux 宿主:
```bash
arch=x86_64 # 或 aarch64
curl -L -o packages/appimage/dockerfile-$arch/appimagetool-$arch.AppImage https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-$arch.AppImage
docker build -t redpanda-builder-$arch packages/appimage/dockerfile-$arch
```
Windows 宿主:
```ps1
$arch = "x86_64" # 或 "aarch64"(如果将来 Docker 支持 WoA
Invoke-WebRequest -OutFile packages/appimage/dockerfile-$arch/appimagetool-$arch.AppImage -Uri https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-$arch.AppImage
docker build -t redpanda-builder-$arch packages/appimage/dockerfile-$arch
```
3. 构建 AppImage。Linux 宿主:
```bash
./packages/appimage/build-x86_64.sh # 或 *-aarch64.sh
```
Windows 宿主:
```ps1
./packages/appimage/build-x86_64.ps1 # 或 *-aarch64.ps1如果将来 Docker 支持 WoA
```
4. 运行小熊猫 C++.
```bash
./dist/RedPandaIDE-x86_64.AppImage # 或 *-aarch64.AppImage
```
注意AppImage 与 QEMU 用户态模拟不兼容,使用此格式的 AppImageKit 工具自然不能用 QEMU 用户态模拟来运行。因此不能在 x86-64 系统上构建 AArch64 AppImage反之亦然。

View File

@ -29,6 +29,9 @@ else: VERSION = $${APP_VERSION}
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = /usr/local PREFIX = /usr/local
} }
isEmpty(LIBEXECDIR) {
LIBEXECDIR = $${PREFIX}/libexec
}
# windows 7 is the minimum windows version # windows 7 is the minimum windows version
win32: { win32: {
@ -36,6 +39,7 @@ DEFINES += _WIN32_WINNT=0x0601
} }
DEFINES += PREFIX=\\\"$${PREFIX}\\\" DEFINES += PREFIX=\\\"$${PREFIX}\\\"
DEFINES += LIBEXECDIR=\\\"$${LIBEXECDIR}\\\"
DEFINES += APP_NAME=\\\"$${APP_NAME}\\\" DEFINES += APP_NAME=\\\"$${APP_NAME}\\\"
DEFINES += REDPANDA_CPP_VERSION=\\\"$${APP_VERSION}\\\" DEFINES += REDPANDA_CPP_VERSION=\\\"$${APP_VERSION}\\\"

View File

@ -184,7 +184,9 @@ QString Settings::Dirs::appResourceDir() const
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return appDir(); return appDir();
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
return includeTrailingPathDelimiter(PREFIX)+"share/"+APP_NAME; // in AppImage PREFIX is not true, resolve from relative path
const static QString absoluteResourceDir(QDir(appDir()).absoluteFilePath("../share/" APP_NAME));
return absoluteResourceDir;
#elif defined(Q_OS_MACOS) #elif defined(Q_OS_MACOS)
// return QApplication::instance()->applicationDirPath(); // return QApplication::instance()->applicationDirPath();
return ""; return "";
@ -197,7 +199,10 @@ QString Settings::Dirs::appLibexecDir() const
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return appDir(); return appDir();
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
return includeTrailingPathDelimiter(PREFIX)+"libexec/"+APP_NAME; // in AppImage LIBEXECDIR is not true, resolve from relative path
const static QString relativeLibExecDir(QDir(PREFIX "/bin").relativeFilePath(LIBEXECDIR "/" APP_NAME));
const static QString absoluteLibExecDir(QDir(appDir()).absoluteFilePath(relativeLibExecDir));
return absoluteLibExecDir;
#elif defined(Q_OS_MACOS) #elif defined(Q_OS_MACOS)
return QApplication::instance()->applicationDirPath(); return QApplication::instance()->applicationDirPath();
#endif #endif

View File

@ -39,6 +39,9 @@ linux: {
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = /usr/local PREFIX = /usr/local
} }
isEmpty(LIBEXECDIR) {
LIBEXECDIR = $${PREFIX}/libexec
}
QMAKE_SUBSTITUTES += platform/linux/redpandaide.desktop.in QMAKE_SUBSTITUTES += platform/linux/redpandaide.desktop.in

View File

@ -0,0 +1,34 @@
#!/bin/bash
set -xe
# build RedPanda C++
mkdir -p /build/redpanda-build
cd /build/redpanda-build
/opt/qt5/bin/qmake PREFIX='/usr' QMAKE_RPATHDIR='/_PlaceHolder' /build/RedPanda-CPP/Red_Panda_CPP.pro
make -j$(nproc)
# install RedPanda C++ to AppDir
make install INSTALL_ROOT=/build/RedPandaIDE.AppDir
# setup AppImage resource
cd /build/RedPandaIDE.AppDir
ln -s usr/bin/RedPandaIDE AppRun
ln -s usr/share/applications/redpandaide.desktop redpandaide.desktop
ln -s usr/share/pixmaps/redpandaide.png redpandaide.png
ln -s usr/share/pixmaps/redpandaide.png .DirIcon
# copy dependency
mkdir -p usr/lib
cp /usr/lib64/libicu{data,i18n,uc}.so.?? usr/lib
patchelf --set-rpath '$ORIGIN' usr/lib/*.so*
patchelf --set-rpath '$ORIGIN/../lib' usr/bin/RedPandaIDE
patchelf --set-rpath '$ORIGIN/../../lib' usr/libexec/RedPandaCPP/*
# create AppImage
cd /build
appimagetool --appimage-extract-and-run RedPandaIDE.AppDir RedPandaIDE-$CARCH.AppImage
# copy back to host
mkdir -p /build/RedPanda-CPP/dist
/bin/cp RedPandaIDE-$CARCH.AppImage /build/RedPanda-CPP/dist

View File

@ -0,0 +1,7 @@
#!/usr/bin/env pwsh
Set-PSDebug -Trace 1
$arch = "aarch64"
docker run --rm -v "$(Get-Location):/build/RedPanda-CPP" -e CARCH=$arch redpanda-builder-$arch /build/RedPanda-CPP/packages/appimage/01-in-docker.sh

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -xe
arch=aarch64
docker run --rm -v $PWD:/build/RedPanda-CPP -e CARCH=$arch redpanda-builder-$arch /build/RedPanda-CPP/packages/appimage/01-in-docker.sh

View File

@ -0,0 +1,7 @@
#!/usr/bin/env pwsh
Set-PSDebug -Trace 1
$arch = "x86_64"
docker run --rm -v "$(Get-Location):/build/RedPanda-CPP" -e CARCH=$arch redpanda-builder-$arch /build/RedPanda-CPP/packages/appimage/01-in-docker.sh

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -xe
arch=x86_64
docker run --rm -v $PWD:/build/RedPanda-CPP -e CARCH=$arch redpanda-builder-$arch /build/RedPanda-CPP/packages/appimage/01-in-docker.sh

View File

@ -0,0 +1,35 @@
FROM quay.io/pypa/manylinux_2_28_aarch64
COPY appimagetool-aarch64.AppImage /usr/local/bin/appimagetool
RUN chmod +x /usr/local/bin/appimagetool && \
sed -i 's|^mirrorlist=|#mirrorlist=|g ; s|^# baseurl=https://repo.almalinux.org/almalinux|baseurl=https://mirror.sjtu.edu.cn/almalinux|g' /etc/yum.repos.d/almalinux*.repo && \
dnf install -y epel-release && \
sed -i 's|^metalink=|#metalink=|g ; s|^#baseurl=https\?://download.fedoraproject.org/pub/epel/|baseurl=https://mirrors.ustc.edu.cn/epel/|g' /etc/yum.repos.d/epel*.repo && \
dnf install -y fontconfig-devel freetype-devel libXrender-devel libicu-devel libxcb-devel libxkbcommon-devel libxkbcommon-x11-devel patchelf xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel
RUN mkdir -p /build/qt5 && \
cd /build/qt5 && \
curl -O 'https://mirrors.ustc.edu.cn/qtproject/official_releases/qt/5.15/5.15.7/submodules/qt{base,svg,tools}-everywhere-opensource-src-5.15.7.tar.xz' && \
tar xf qtbase-everywhere-opensource-src-5.15.7.tar.xz && \
cd qtbase-everywhere-src-5.15.7 && \
./configure \
-prefix /opt/qt5 \
-opensource -confirm-license \
-optimize-size -no-shared -static -platform linux-g++ -no-use-gold-linker \
-qt-zlib -qt-doubleconversion -qt-pcre -system-freetype -fontconfig -qt-harfbuzz -qt-libjpeg -qt-libpng -xcb -qt-sqlite \
-nomake examples -nomake tests -nomake tools && \
make -j$(nproc) && \
make install && \
cd /build/qt5 && \
tar xf qtsvg-everywhere-opensource-src-5.15.7.tar.xz && \
cd qtsvg-everywhere-src-5.15.7 && \
/opt/qt5/bin/qmake . && \
make -j$(nproc) && \
make install && \
cd /build/qt5 && \
tar xf qttools-everywhere-opensource-src-5.15.7.tar.xz && \
cd qttools-everywhere-src-5.15.7 && \
/opt/qt5/bin/qmake . && \
make -j$(nproc) && \
make install && \
cd / && \
rm -r /build/qt5

View File

@ -0,0 +1,34 @@
FROM quay.io/pypa/manylinux2014_x86_64
COPY appimagetool-x86_64.AppImage /usr/local/bin/appimagetool
RUN chmod +x /usr/local/bin/appimagetool && \
sed -i 's|^mirrorlist=|#mirrorlist=|g ; s|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' /etc/yum.repos.d/CentOS-*.repo && \
sed -i 's|^metalink=|#metalink=|g ; s|^#baseurl=https\?://download.example/pub/epel/|baseurl=https://mirrors.ustc.edu.cn/epel/|g' /etc/yum.repos.d/epel.repo && \
yum install -y fontconfig-devel freetype-devel libXrender-devel libicu-devel libxcb-devel libxkbcommon-devel patchelf
RUN mkdir -p /build/qt5 && \
cd /build/qt5 && \
curl -O 'https://mirrors.ustc.edu.cn/qtproject/archive/qt/5.12/5.12.12/submodules/qt{base,svg,tools}-everywhere-src-5.12.12.tar.xz' && \
tar xf qtbase-everywhere-src-5.12.12.tar.xz && \
cd qtbase-everywhere-src-5.12.12 && \
./configure \
-prefix /opt/qt5 \
-opensource -confirm-license \
-optimize-size -no-shared -static -platform linux-g++ -no-use-gold-linker \
-qt-zlib -qt-doubleconversion -qt-pcre -system-freetype -fontconfig -qt-harfbuzz -qt-libjpeg -qt-libpng -qt-xcb -qt-sqlite \
-nomake examples -nomake tests -nomake tools && \
make -j$(nproc) && \
make install && \
cd /build/qt5 && \
tar xf qtsvg-everywhere-src-5.12.12.tar.xz && \
cd qtsvg-everywhere-src-5.12.12 && \
/opt/qt5/bin/qmake . && \
make -j$(nproc) && \
make install && \
cd /build/qt5 && \
tar xf qttools-everywhere-src-5.12.12.tar.xz && \
cd qttools-everywhere-src-5.12.12 && \
/opt/qt5/bin/qmake . && \
make -j$(nproc) && \
make install && \
cd / && \
rm -r /build/qt5

View File

@ -0,0 +1,40 @@
_pkgname=RedPanda-CPP
pkgname=${_pkgname,,}-git
pkgver=2.7.r10.g0caaad84
pkgrel=1
pkgdesc='A fast, lightweight, open source, and cross platform C++ IDE (development version)'
arch=('i686' 'pentium4' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
url="https://github.com/royqh1979/$_pkgname"
license=('GPL3')
depends=(qt5-base qt5-svg gcc gdb)
makedepends=(git qt5-tools)
optdepends=(
'clang: alternate C/C++ compiler'
'qterminal: run in terminal'
'konsole: run in terminal (alternate)'
'git: git integration'
)
conflicts=("${_pkgname,,}")
provides=("${_pkgname,,}")
source=("$_pkgname::git+file://${PWD%packages/archlinux}")
sha256sums=('SKIP')
pkgver() {
cd "$srcdir/$_pkgname"
git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}
build() {
mkdir redpanda-build
cd redpanda-build
qmake \
PREFIX='/usr' \
LIBEXECDIR='/usr/lib' \
"$srcdir/$_pkgname/Red_Panda_CPP.pro"
make
}
package() {
cd redpanda-build
make INSTALL_ROOT="$pkgdir" install
}

View File

@ -4,12 +4,12 @@ Comment[zh_CN]=基于QT的轻量级C/C++集成开发环境
Exec=RedPandaIDE %F Exec=RedPandaIDE %F
GenericName=Red Panda C++ GenericName=Red Panda C++
GenericName[zh_CN]=小熊猫C++ GenericName[zh_CN]=小熊猫C++
MimeType=application/pdf MimeType=application/pdf;
Name=Red Panda C++ Name=Red Panda C++
Name[zh_CN]=小熊猫C++ Name[zh_CN]=小熊猫C++
StartupNotify=false StartupNotify=false
Terminal=false Terminal=false
Type=Application Type=Application
Categories=Development;Qt; Categories=Development;Qt;
Icon=$${PREFIX}/share/pixmaps/redpandaide.png Icon=$${PREFIX}/share/pixmaps/redpandaide
Path=$${PREFIX}/bin Path=$${PREFIX}/bin

View File

@ -26,6 +26,9 @@ SOURCES += \
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = /usr/local PREFIX = /usr/local
} }
isEmpty(LIBEXECDIR) {
LIBEXECDIR = $${PREFIX}/libexec
}
win32: { win32: {
!isEmpty(PREFIX) { !isEmpty(PREFIX) {
@ -39,8 +42,8 @@ QMAKE_CXXFLAGS += /source-charset:utf-8
} }
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = $${PREFIX}/libexec/$${APP_NAME} qnx: target.path = $${LIBEXECDIR}/$${APP_NAME}
else: unix:!android: target.path = $${PREFIX}/libexec/$${APP_NAME} else: unix:!android: target.path = $${LIBEXECDIR}/$${APP_NAME}
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target

View File

@ -41,6 +41,9 @@ CONFIG += embed_translations
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = /usr/local PREFIX = /usr/local
} }
isEmpty(LIBEXECDIR) {
LIBEXECDIR = $${PREFIX}/libexec
}
win32: { win32: {
!isEmpty(PREFIX) { !isEmpty(PREFIX) {
@ -49,6 +52,6 @@ win32: {
} }
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = $${PREFIX}/libexec/$${APP_NAME} qnx: target.path = $${LIBEXECDIR}/$${APP_NAME}
else: unix:!android: target.path = $${PREFIX}/libexec/$${APP_NAME} else: unix:!android: target.path = $${LIBEXECDIR}/$${APP_NAME}
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target

View File

@ -24,8 +24,11 @@ FORMS += \
isEmpty(PREFIX) { isEmpty(PREFIX) {
PREFIX = /usr/local PREFIX = /usr/local
} }
isEmpty(LIBEXECDIR) {
LIBEXECDIR = $${PREFIX}/libexec
}
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = $${PREFIX}/libexec/$${APP_NAME} qnx: target.path = $${LIBEXECDIR}/$${APP_NAME}
else: unix:!android: target.path = $${PREFIX}/libexec/$${APP_NAME} else: unix:!android: target.path = $${LIBEXECDIR}/$${APP_NAME}
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target