通過《如意玲瓏應用構(gòu)建指南(二):在玲瓏容器中編譯基于 Qt5 的開源應用》的學習后,相信大家已經(jīng)基本了解了在玲瓏容器中通過怎樣的操作可以將基于 Qt5 的開源應用——qBittorrent 的項目源代碼編譯為可以運行的二進制程序文件。
今天, 我們在此基礎上補齊玲瓏應用構(gòu)建基本步驟中的最后步驟——編寫一份完整的玲瓏應用構(gòu)建工程配置文件 linglong.yaml, 主要實現(xiàn)以下的目標:
自動化拉取開源項目源代碼;
自動應用對于源代碼進行修改的 Patch;
自動執(zhí)行編譯構(gòu)建、安裝操作。
01前期準備
根據(jù)玲瓏應用構(gòu)建工程通用資源的規(guī)范要求,我們應當為一款圖形化應用同時提供保障桌面用戶體驗的 icons 圖標文件及 desktop 啟動文件。因此,為了能夠編寫自動編譯 qBittorrent 的完整 linglong.yaml,需要額外準備以下材料:
非二進制文件通用資源,icons圖標、desktop文件;
主程序 qBittorrent 開源項目的倉庫 Git 信息、Tag 版本、Commit 信息;
第三方運行庫 libtorrent 開源項目的倉庫 Git 信息、Tag版本、Commit信息。
1.1 通用資源準備
由于在上節(jié)教程中我們在玲瓏容器內(nèi)已經(jīng)成功編譯并運行了 qBittorrent,并且這款應用在安裝到 $PREFIX 之后一并提供了 icons 目錄、desktop 啟動文件。
我們對這兩項進行檢查, 確認均符合 Freedesktop XDG 規(guī)范,因此我們僅需要直接從容器中復制到本地即可, 即復制到構(gòu)建目錄 /project 中。
ziggy@linyaps23:/project/src/qBittorrent-release-4.6.7-szbt2/build$ ls $PREFIX/share/applications/ org.qbittorrent.qBittorrent.desktop
ziggy@linyaps23:/project/src/qBittorrent-release-4.6.7-szbt2/build$ ls $PREFIX/share/icons/hicolor/128x128/apps/ qbittorrent.png
于是, 我們得到了非二進制文件通用資源,為了方便被構(gòu)建組件使用,我這里將這些文件放到了構(gòu)建目錄的 template_app子目錄中,現(xiàn)在呈現(xiàn)此類結(jié)構(gòu):
template_app ├── linglong.yaml └── template_app ├── applications │ └── org.qbittorrent.qBittorrent.desktop ├── icons │ └── hicolor │ ├── 128x128 │ │ ├── apps │ │ │ └── qbittorrent.png │ │ └── status │ │ └── qbittorrent-tray.png │ └── scalable │ ├── apps │ │ └── qbittorrent.svg │ └── status │ ├── qbittorrent-tray-dark.svg │ ├── qbittorrent-tray-light.svg │ └── qbittorrent-tray.svg
1.2desktop 啟動文件定制
根據(jù)玲瓏應用構(gòu)建工程通用資源的規(guī)范,我們需要確保當前的 desktop 文件符合相關(guān)規(guī)范。
我們打開從容器中導出的 desktop 文件,檢查 Exec 和 Icon 字段,得出以下結(jié)果:
[Desktop Entry] Categories=Network;FileTransfer;P2P;Qt; Exec=qbittorrent %U GenericName=BitTorrent client Comment=Download and share files over BitTorrent Icon=qbittorrent
Icon 字段值與圖標文件一致,符合規(guī)范;
Exec字段值不為玲瓏容器內(nèi)編譯的結(jié)果, 需要修改為符合玲瓏應用構(gòu)建工程通用資源的規(guī)范的內(nèi)容,這里替換為絕對路徑指向容器中的具體二進制文件,用于喚醒容器并啟動該應用。
02構(gòu)建?程配置?件 linglong.yaml
在準備圖形化應用所必備的通用資源后,我們著手編寫構(gòu)建規(guī)則。
由于在上節(jié)教程中我們已經(jīng)準備了一版簡單但不具備完整構(gòu)建功能的 linglong.yaml,因此我們可以在其基礎上進行定制,現(xiàn)在是初始狀態(tài):
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. # # SPDX-License-Identifier: LGPL-3.0-or-later version: "4.6.7.2" package: id: org.qbittorrent.qBittorrent name: "qBittorrent" version: 4.6.7.2 kind: app description: | qBittorrent binary base: org.deepin.foundation/23.0.0 runtime: org.deepin.Runtime/23.0.1 command: - /opt/apps/org.qbittorrent.qBittorrent/files/bin/qbittorrent sources: - kind: local name: "qBittorrent" build: | mkdir -p ${PREFIX}/bin/ ${PREFIX}/share/
2.1構(gòu)建規(guī)則編寫 & 測試
為了能夠平滑過渡,我這里先將編譯指令導入構(gòu)建規(guī)則,暫不引入自動拉取 Git 倉庫的內(nèi)容,以確保我們編寫的構(gòu)建規(guī)則準確可用。
由于不建議在構(gòu)建規(guī)則中執(zhí)行過多 tar指令,因此我這里在構(gòu)建目錄下同時開啟兩個 Shell 窗口,分別用于玲瓏容器操作和普通操作。
以下是正式開始改造的過程:
通過普通操作窗口使用 git 將 qBittorrent 和 libtorrent-rasterbar 源碼拉取或解壓到構(gòu)建目錄中,我這里通過源碼壓縮包單獨解壓到子目錄中:
ziggy@linyaps23:/media/szbt/Data/ll-build/QT/qBittorrent-local$ tar -xvf qBittorrent-4.6.7-git-origin-src.tar.zst -C src/ ziggy@linyaps23:/media/szbt/Data/ll-build/QT/qBittorrent-local$ tar -xvf libtorrent-rasterbar-2.0.9.tar.gz -C 3rd/
從玲瓏應用目錄結(jié)構(gòu)規(guī)范得知, 構(gòu)建目錄會被映射為 /project,,因此我們需要將上節(jié)課程中使用的手動編譯命令寫入 build 模塊中。
build: | mkdir -p ${PREFIX}/bin/ ${PREFIX}/share/ ##Build 3rd libs 注釋:進入 `libtorrent-rasterbar` 源碼目錄并編譯安裝到容器內(nèi) mkdir /project/3rd/libtorrent-rasterbar-2.0.9/build cd /project/3rd/libtorrent-rasterbar-2.0.9/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .. make -j$(nproc) make install ##Build main 注釋:進入 `qBittorrent` 源碼目錄并編譯安裝到容器內(nèi) mkdir /project/src/qBittorrent-release-4.6.7-szbt2/build cd /project/src/qBittorrent-release-4.6.7-szbt2/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .. make -j$(nproc) make install ##Extract common res 注釋: 將通用文件復制安裝到容器對應目錄內(nèi), 符合 `玲瓏應用目錄結(jié)構(gòu)規(guī)范` cp -rf /project/template_app/* ${PREFIX}/share/
在將此塊構(gòu)建規(guī)則補全后,我們可以開始嘗試通過自動化構(gòu)建來將本地源碼編譯為二進制程序并導出玲瓏應用安裝包 binary.layer 了。
注:由于此版配置文件不提供解壓、刪除功能,因此每次重新構(gòu)建前均需要將這些目錄清空并重新解壓。
2.2 本地一站構(gòu)建測試
在補全 build 模塊后, 此時的 linglong.yaml 狀態(tài):
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. # # SPDX-License-Identifier: LGPL-3.0-or-later version: "2" package: id: org.qbittorrent.qBittorrent name: "qBittorrent" version: 4.6.7.2 kind: app description: | qBittorrent binary base: org.deepin.foundation/23.0.0 runtime: org.deepin.Runtime/23.0.1 command: - /opt/apps/org.qbittorrent.qBittorrent/files/bin/qbittorrent source: - kind: local name: "qBittorrent" build: | ##Build 3rd libs mkdir -p ${PREFIX}/bin/ ${PREFIX}/share/ mkdir /project/3rd/libtorrent-rasterbar-2.0.9/build cd /project/3rd/libtorrent-rasterbar-2.0.9/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .. make -j$(nproc) make install ##Build main mkdir /project/src/qBittorrent-release-4.6.7-szbt2/build cd /project/src/qBittorrent-release-4.6.7-szbt2/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX .. make -j$(nproc) make install ##Extract common res cp -rf /project/template_app/* ${PREFIX}/share/
此刻我們可以返回構(gòu)建目錄,開始構(gòu)建測試了,執(zhí)行:
ziggy@linyaps23:/media/szbt/Data/ll-build/QT/qBittorrent-local$ ll-builder build -v
得益于在玲瓏容器中的編譯筆記,此次構(gòu)建很快就成功結(jié)束了,我們執(zhí)行以下指令來將容器導出為玲瓏應用安裝包 binary.layer:
ziggy@linyaps23:/media/szbt/Data/ll-build/QT/qBittorrent-local$ ll-builder export --layer
03本地構(gòu)建結(jié)果測試
在得到玲瓏應用安裝包后,可以在不同支持玲瓏環(huán)境的主流發(fā)行版上嘗試體驗,來確認通過玲瓏容器構(gòu)建的二進制程序是否存在通用性。
deepin 23
openKylin 2.0
Ubuntu 2404
OpenEuler 2403
由此可見,基于 Qt5 的開源應用--qBittorrent 構(gòu)建完成后,在支持如意玲瓏應用方案的第三方發(fā)行版中可以成功運行!本教程至此結(jié)束,歡迎大家上手體驗!
關(guān)于項目
如意玲瓏(Linyaps)是一種新型的獨立包管理工具集,專注于解決 Linux 系統(tǒng)下由傳統(tǒng)軟件包格式的復雜性和交叉依賴關(guān)系引起的兼容性問題。項目通過先進的隔離技術(shù),將應用與系統(tǒng)完全解耦,從根本上解決因環(huán)境變化引發(fā)的應用兼容性問題,實現(xiàn)“一個架構(gòu),一次構(gòu)建”,致力于簡化軟件開發(fā)流程、降低維護成本、加強數(shù)據(jù)安全,促進技術(shù)與平臺間的協(xié)同合作,構(gòu)建一個更加繁榮、安全和高效的 Linux 軟件生態(tài)環(huán)境。
-
開源
+關(guān)注
關(guān)注
3文章
3606瀏覽量
43478 -
容器
+關(guān)注
關(guān)注
0文章
507瀏覽量
22366 -
代碼
+關(guān)注
關(guān)注
30文章
4886瀏覽量
70257 -
編譯
+關(guān)注
關(guān)注
0文章
676瀏覽量
33747
原文標題:如意玲瓏應用構(gòu)建指南(三):如意玲瓏應用構(gòu)建規(guī)則實用案例
文章出處:【微信號:linux_deepin,微信公眾號:深度操作系統(tǒng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
安謀中國“玲瓏”i3/i5 系列詳解及定位

【NanoPi M1試用體驗】開箱評測 小巧玲瓏
###神轟%>小巧玲瓏眼睛紅,地上蹦跳自家園。Fanny 范妮
(:小巧玲瓏眼睛紅,地上蹦跳自家園
推理規(guī)則鏈的確定性構(gòu)建
玲瓏ISP處理器的主要技術(shù)特點
ARM中國發(fā)布首款I(lǐng)SP玲瓏監(jiān)控系統(tǒng)
ARM中國發(fā)布 “玲瓏”ISP處理器
安謀科技發(fā)布“玲瓏”DPU和新一代VPU
如意玲瓏社區(qū)2024年度工作總結(jié)

如意玲瓏應用構(gòu)建的基礎知識

如何在玲瓏容器中編譯qBittorrent并測試運行

評論