[other] 一点点关于ShiroDEB的介绍~
Tofloor
default avatar
Shiroko
deepin
2023-11-17 09:51
Author

大家好啊,我是垫棍Shiroko,今天来点大家想看的东西。

这俩月一直在写一个叫做“ShiroDEB”的脚本集,觉得差不多了现在端上来水一下帖。

icon.png

什么是ShiroDEB?

ShiroDEB是我为了减少软件打包过程中重复劳动而付出了更多劳动的一套脚本工具,核心思想来自Arch系的PKGBUILD,通过一系列预定义的步骤来产生软件包。一次编写,更新不愁(和CI更配喔)。

范例(SVG动画可能在某些浏览器上无法正常播放):

为什么需要“构建脚本”

通常一个软件包的上游更新不会对其构建流程产生很大的影响,就算是二进制产物也不会有什么很大的变化,所以每次更新的流程几乎都是相同的。把这一部分内容固定下来,之后的更新基本上就是一个先改一下版本号,然后运行 shirodeb make的过程了。版本号甚至也可以自动获取~

这一方式的优点在于,可以使用构建服务器来自动触发打包的流程,实现软件包的自动更新(我暂时还没有开始搞CI部分)。同时,发布出去的构建脚本对于其他用户来讲也可以直接进行版本号的修改,然后构建出软件包,自己进行测试和使用。哪怕原始的构建脚本不能使用,也有一定的参考价值,也可以在此基础上干预一些编译参数,实现客制化。

栗:Remmina的构建脚本

# This file is a configuration file and is not meant to be executed export PACKAGE="org.remmina" export NAME="Remmina" export VERSION="1.4.32" export FREERDP_VERSION="2.11.2" export ARCH=$(utils.misc.get_current_arch) export URL=( "https://gitlab.com/Remmina/Remmina/-/archive/v${VERSION}/Remmina-v${VERSION}.tar.bz2" "https://github.com/FreeRDP/FreeRDP/archive/refs/tags/${FREERDP_VERSION}.zip" ) export REQUIRED_PERMISSIONS="" export DESC1="GTK+ Remote Desktop Client" export DESC2="Remote access screen and file sharing to your desktop. Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks." export DEPENDS="libatk1.0-0, libavahi-client3, libavahi-common3, libavahi-ui-gtk3-0, libayatana-appindicator3-1, libc6, libcairo2, libgcrypt20, libgdk-pixbuf2.0-0, libglib2.0-0, libgtk-3-0, libice6, libjson-glib-1.0-0, libpango-1.0-0, libsm6, libsodium23, libsoup2.4-1, libssh-4, libssl1.1, libvte-2.91-0, libx11-6, libxext6, default-dbus-session-bus | dbus-session-bus, libusb-1.0-0, libgcrypt20, libsodium23, libssh-4, libvte-2.91-0, libappindicator3-1, libvncserver1, libvncclient1" export BUILD_DEPENDS="libusb-1.0-0-dev libgcrypt20-dev libsodium-dev libssh-dev libvte-2.91-dev libappindicator3-dev libvncserver-dev libpulse-dev" export SECTION="utils" export PROVIDE="" export HOMEPAGE="https://remmina.org/" function build() { pushd $SRC_DIR export DESTDIR=${PKG_DIR} # modify package name for file in $(find ./Remmina-v${VERSION} -type f -exec grep -Iq . {} \; -print); do sed -i "s/org.remmina.Remmina/${PACKAGE}/g" $file 2>/dev/null done for file in $(find . -type f -name "org.remmina.Remmina*"); do mv $file ${file/org.remmina.Remmina/org.remmina} done # build FreeRDP pushd FreeRDP-${FREERDP_VERSION} cmake -B build -DCMAKE_INSTALL_PREFIX=/opt/apps/${PACKAGE}/files/ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF && cmake --build build -j $(nproc) && cmake --build build --target install popd echo $DESTDIR # build Remmina pushd Remmina-v${VERSION} cmake -B build -DCMAKE_INSTALL_PREFIX=/opt/apps/${PACKAGE}/files/ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_PREFIX_PATH=$DESTDIR/opt/apps/${PACKAGE}/files/ && cmake --build build -j $(nproc) && cmake --build build --target install popd popd # remove devel files dev_files=$(find $APP_DIR -type d \ -name "include" \ -or -name "pkgconfig" \ -or -name "cmake") for dev_file in ${dev_files[@]}; do rm -rf $dev_file done # copy share mkdir -p $APP_DIR/entries/ cp -R $APP_DIR/files/share/* $APP_DIR/entries/ # modify desktop for desktop in $(find $APP_DIR/entries/applications/ -type f -name "*.desktop"); do sed -i "s#=remmina-file-wrapper#=/opt/apps/org.remmina/files/bin/remmina-file-wrapper#g" $desktop sed -i "s#^Exec=#Exec=env LD_LIBRARY_PATH=/opt/apps/org.remmina/files/lib #g" $desktop done rm -f $APP_DIR/entries/applications/org.remmina-file.desktop rm -rf $APP_DIR/entries/mime rm -rf $APP_DIR/entries/metainfo }

自建库

目前ShiroDEB已经全面支持第三方自建库,从而摆脱UOS V20系统库版本过低的桎梏。通过在构建脚本中使用 export INGREDIENTS=("xxx"),即可在构建和打包过程中使用自建库而不是系统里面的自带依赖。脚本也会自动将运行时需要的库打包到软件包里,并处理相关的环境变量等。搭配szbt已经上传到依赖仓的自建库,更是可以直接使用而不需要打包进软件包内,减少了软件包的体积。

ShiroDEB也支持交互终端,提供给开发者一个方便使用自建库的途径。(如下图)

容器

ShiroDEB也支持使用bubblewrap来提供用户态容器层来实现对glibc等无法简单通过环境变量解决的二进制兼容~(目前这一部分还有待发掘)

其实理论上glibc可以通过patchelf修改rpath和interpreter和直接执行 ld.so来强制使用自定义的glibc,但是不知道为什么在UOS上不行,可能是我的姿势有些问题。

相关仓库

ShiroDEB:ShiroDEB主仓库
Recipes:Recipes是存放构建脚本的仓库
Ingredients:Ingredients是存放自建库和其他运行环境“配置方案”的脚本(二进制分发请关注SIG:deepin-shared-libs

更为详细的使用说明在仓库的README中,如果感兴趣可以看一下~
(仍在开发阶段所以很多地方可能不完善,还请大家多多指教~)

前两个仓库在Gitee上也有镜像,请翻阅Spark Community Works Collections

希望有朝一日能变成另一个AUR(逃)

我会在11月的WHLUG上和大家互相交流学习,期待smirk

Reply Favorite View the author
All Replies
Ziggy
deepin
2023-11-17 09:56
#1

gcc那个我看好像有说法可以走LD_PRELOAD?不知道有没有效果

Reply View the author
DeepinSeek
deepin
2023-11-17 10:01
#2

加载帖子好卡啊sad

Reply View the author
Shiroko
deepin
2023-11-17 10:01
#3
DeepinSeek

加载帖子好卡啊sad

可能是svg动画的原因(
我把动画折叠了,应该会好一些?

Reply View the author
yanjuner
deepin
2023-11-17 10:04
#4

看不太懂,但是好牛的样子

Reply View the author
Shiroko
deepin
2023-11-17 10:04
#5
Ziggy

gcc那个我看好像有说法可以走LD_PRELOAD?不知道有没有效果

glibc最后折腾还是报浮点错误,没辙了。

Reply View the author
神末shenmo
deepin
Spark-App
2023-11-17 11:32
#6

有一个定制版本的在星火跑的,叫SBS,专注二进制打包的同学可以看一下~

只截取了shirodeb的二进制打包维护的部分功能,不包含编译和添加依赖库功能(这部分设计上由ACE解决),额外添加了从其他apt源获取deb和生成app.json的功能,而且所有的apt操作换成了aptss,是定制用于维护星火仓库软件包的

没错我就是抄的shirodeb,shiroko赛高~

小小推广下,不过应该只有我自己在用啦~ https://gitee.com/spark-building-service


Reply View the author
babyfengfjx
Super Moderator
CQA
2023-11-17 14:00
#7

看起来相当牛皮~

Reply View the author
vivian_me
deepin testing team
2023-11-17 16:41
#8

哇,期待你在LUG的分享哦~

Reply View the author