Fedora30 构建 Flatpak 应用

系统环境

1
2
Fedora release 30 (Thirty)
Linux Fedora30 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Flatpak 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装flatpak
# yum install flatpak flatpak-builder

# 添加flathub仓库
# flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# 添加GNOME稳定版的仓库(已失效)
# wget https://sdk.gnome.org/keys/gnome-sdk.gpg
# flatpak remote-add --gpg-import=gnome-sdk.gpg gnome https://sdk.gnome.org/repo/
# flatpak remote-add --gpg-import=gnome-sdk.gpg --if-not-exists gnome-apps https://sdk.gnome.org/repo-apps/

# 添加GNOME每日构建版的仓库(最新)
# flatpak remote-add --if-not-exists gnome-nightly https://nightly.gnome.org/gnome-nightly.flatpakrepo

构建 Peek

Peek 是一款 AUR 上人气很高的屏幕录像工具,可保存录像为 gif 动图和兼容于 html5webm 视频,可以运行在 GNOME 桌面环境下。Peek 官方提供的源码里,默认包含了构建 Flatpak 应用的 YAML 文件,直接执行构建操作即可。构建 Peek 之前,需要保证 Flatpak 的版本 >= 1.4.0,如果系统的 Flatpak 版本不满足要求,同时又不能升级 Flatpak 的版本,那么可参考本文最后给出的解决方案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 查看flatpak的版本
# flatpak --version

# 下载源码
# wget -O peek-1.4.0.tar.gz https://github.com/phw/peek/archive/1.4.0.tar.gz

# 解压文件
# tar -xvf peek-1.4.0.tar.gz

# 进入构建目录
# cd peek-1.4.0/data/flatpak/

# 删除旧的应用文件
# rm -rf *.flatpak

# 安装运行时依赖gnome-platform-3.34(耗时较长),依赖flatpak的版本 >= 1.4.0
# flatpak install org.gnome.Sdk/x86_64/3.34
# flatpak install org.gnome.Platform-3.34

# 执行构建脚本
# ./build.sh

# 成功构建应用后,默认会生成".flatpakref"后缀的文件,例如:peek-stable.flatpakref

# 安装构建生成应用
# flatpak install xxxx.flatpakref

构建 Peek 的 YAML 文件

构建 Flatpak 应用离不开 YAML 配置文件,作用类似 Docker 的 docker-file,如果想自定义 Peek 的构建过程,可以参考下面 YAML 配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
app-id: com.uploadedlobster.peek
runtime: org.gnome.Platform
runtime-version: '3.34'
sdk: org.gnome.Sdk
sdk-extensions:
- org.freedesktop.Sdk.Extension.rust-stable
branch: stable
command: peek
finish-args:
- --share=ipc
- --socket=x11
- --env=GDK_BACKEND=x11
- --socket=wayland
- --talk-name=org.freedesktop.FileManager1
- --talk-name=org.gnome.Shell.Screencast
- --filesystem=home
- --filesystem=xdg-run/dconf
- --filesystem=~/.config/dconf:ro
- --talk-name=ca.desrt.dconf
- --env=DCONF_USER_CONFIG_DIR=.config/dconf
- --env=LD_LIBRARY_PATH=/app/lib
build-options:
cflags: -O2 -g -fstack-protector-strong -D_FORTIFY_SOURCE=2
cxxflags: -O2 -g -fstack-protector-strong -D_FORTIFY_SOURCE=2
ldflags: -fstack-protector-strong -Wl,-z,relro,-z,now
append-path: /usr/lib/sdk/rust-stable/bin
cleanup:
- /include
- /lib/pkgconfig
- /share/gtk-doc
- "*.la"

modules:
- name: ffmpeg
config-opts:
- --disable-debug
- --disable-static
- --enable-gpl
- --enable-libvpx
- --enable-libx264
- --enable-shared
- --enable-libxcb
- --enable-libxcb-xfixes
- --disable-libxcb-shape
- --disable-ffplay
- --disable-ffprobe
- --disable-doc
- --disable-everything
- --enable-bsf=vp9_superframe
- --enable-decoder=libvpx_vp9
- --enable-decoder=png
- --enable-decoder=rawvideo
- --enable-encoder=apng
- --enable-encoder=ffvhuff
- --enable-encoder=gif
- --enable-encoder=libvpx_vp9
- --enable-encoder=libx264
- --enable-encoder=png
- --enable-demuxer=image2
- --enable-demuxer=matroska
- --enable-muxer=apng
- --enable-muxer=gif
- --enable-muxer=image2
- --enable-muxer=mp4
- --enable-muxer=webm
- --enable-filter=crop
- --enable-filter=fps
- --enable-filter=palettegen
- --enable-filter=paletteuse
- --enable-filter=scale
- --enable-protocol=file
- --enable-indev=xcbgrab
sources:
- type: archive
url: https://ffmpeg.org/releases/ffmpeg-4.2.1.tar.xz
sha256: cec7c87e9b60d174509e263ac4011b522385fd0775292e1670ecc1180c9bb6d4
modules:
- name: yasm
cleanup: "*"
sources:
- type: archive
url: http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
sha256: 3dce6601b495f5b3d45b59f7d2492a340ee7e84b5beca17e48f862502bd5603f
- name: libx264
config-opts:
- --enable-pic
- --enable-shared
sources:
- type: git
url: https://git.videolan.org/git/x264.git
commit: 72db437770fd1ce3961f624dd57a8e75ff65ae0b
cleanup:
- /bin/x264

- name: gifski
buildsystem: simple
build-options:
build-args:
- --share=network
skip-arches:
- aarch64
- arm
sources:
- type: archive
url: https://github.com/ImageOptim/gifski/archive/0.9.1.tar.gz
sha256: f39a6e510e825bf4b43aebd1d7fb581d3b59a11bf7521bf6f507d4b0fa684b76
build-commands:
- cargo build --release --features=openmp --verbose
- install -Dm755 target/release/gifski /app/bin/gifski

- name: peek
buildsystem: meson
config-opts:
- --buildtype=release
build-options:
cflags: -L/app/lib
sources:
- type: git
url: ../..
branch: 1.4.0
modules:
- name: keybinder3
sources:
- type: archive
url: https://github.com/kupferlauncher/keybinder/releases/download/keybinder-3.0-v0.3.2/keybinder-3.0-0.3.2.tar.gz
sha256: e6e3de4e1f3b201814a956ab8f16dfc8a262db1937ff1eee4d855365398c6020
© 2019 GitHub, Inc.

解决构建 Peek 时依赖 Flatpak 的版本必须大于 1.4.0 的问题

1
2
3
# 更改YAML配置文件,指定org.gnome.Platform为其他低版本
runtime: org.gnome.Platform
runtime-version: '3.32'