Skip to content

Commit 558a06e

Browse files
committed
feat: Improve reproducibility of AppImage builds.
Also add a verifier script so the AppImage build can be verified locally. The current 0.8.3 release is a big mess, so we can't actually test this. 0.8.4 should be better, so we can test it there.
1 parent 4112161 commit 558a06e

5 files changed

Lines changed: 438 additions & 8 deletions

File tree

‎platform/appimage/build.sh‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
# Fail out on error
88
set -exuo pipefail
99

10+
# Ensure consistent file permissions
11+
umask 022
12+
13+
# Support reproducible builds
14+
if [ -z "${SOURCE_DATE_EPOCH+x}" ]; then
15+
export SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)"
16+
fi
17+
1018
usage() {
1119
echo "$0 --src-dir SRC_DIR --project-name PROJECT_NAME [cmake args]"
1220
echo "Builds an app image in the CWD based off PROJECT_NAME installation at SRC_DIR"
@@ -70,14 +78,22 @@ git describe --tags --match 'v*'
7078
readonly BUILD_DIR="$(realpath .)"
7179
readonly PROJECT_APP_DIR="$BUILD_DIR/$PROJECT_NAME.AppDir"
7280

81+
# Pin appimagetool version for reproducibility
82+
readonly APPIMAGE_TOOL_VERSION="940"
83+
readonly APPIMAGE_TOOL_URL="https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage"
84+
7385
rm -f appimagetool-*.AppImage
74-
wget "https://github.com/$(wget -q https://github.com/probonopd/go-appimage/releases/expanded_assets/continuous -O - | grep "appimagetool-.*-x86_64.AppImage" | head -n 1 | cut -d '"' -f 2)"
86+
wget "$APPIMAGE_TOOL_URL" -O "appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage"
7587
chmod +x appimagetool-*.AppImage
7688

77-
# https://github.com/probonopd/go-appimage/blob/fced8b8831039daa246ab355f4e2335074abc206/src/appimagetool/appdirtool.go#L400
78-
# This line in the appimagetool breaks musl DNS lookups (looking for /EEE/resolv.conf).
79-
./appimagetool-*.AppImage --appimage-extract
80-
sed -i -e 's!/EEE!/etc!g' squashfs-root/usr/bin/appimagetool
89+
# Extract tool to a isolated directory to avoid polluting the workspace/AppImage
90+
readonly TOOL_EXTRACT_DIR="$BUILD_DIR/tool-extract"
91+
rm -rf "$TOOL_EXTRACT_DIR"
92+
"./appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage" --appimage-extract
93+
mv squashfs-root "$TOOL_EXTRACT_DIR"
94+
95+
# Patch the tool for musl compatibility
96+
sed -i -e 's!/EEE!/etc!g' "$TOOL_EXTRACT_DIR/usr/bin/appimagetool"
8197

8298
export PKG_CONFIG_PATH=/opt/buildhome/lib/pkgconfig
8399

@@ -92,13 +108,21 @@ cmake "$SRC_DIR" \
92108
-DCMAKE_INSTALL_PREFIX=/usr \
93109
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
94110
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
111+
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--build-id=none" \
95112
-B _build \
96113
"$@"
97114
cmake --build _build
98115
cmake --install _build --prefix "$PROJECT_NAME.AppDir/usr"
99116

100117
ccache --show-stats
101118

119+
# Normalize file permissions and timestamps for reproducibility
120+
echo "Normalizing AppDir..."
121+
find "$PROJECT_APP_DIR" -exec touch -h -d @"$SOURCE_DATE_EPOCH" {} +
122+
find "$PROJECT_APP_DIR" -type d -exec chmod 0755 {} +
123+
find "$PROJECT_APP_DIR" -type f -exec chmod 0644 {} +
124+
find "$PROJECT_APP_DIR" -type f -perm /0111 -exec chmod 0755 {} +
125+
102126
export QTDIR=/opt/buildhome/qt
103127
export LD_LIBRARY_PATH="/opt/buildhome/lib:/opt/buildhome/lib64:$QTDIR/lib"
104128

@@ -109,12 +133,19 @@ cp -r "$QTDIR/plugins/platforms/libqwayland-generic.so" "$PROJECT_APP_DIR/$QTDIR
109133
# Copy the tls plugins to the app dir, needed for https connections.
110134
cp -r "$QTDIR/plugins/tls/" "$PROJECT_APP_DIR/$QTDIR/plugins/"
111135

112-
squashfs-root/AppRun -s deploy "$PROJECT_APP_DIR"/usr/share/applications/*.desktop
136+
"$TOOL_EXTRACT_DIR/AppRun" -s deploy "$PROJECT_APP_DIR"/usr/share/applications/*.desktop
113137

114138
# print all links not contained inside the AppDir
115139
LD_LIBRARY_PATH='' find "$PROJECT_APP_DIR" -type f -exec ldd {} \; 2>&1 | grep '=>' | grep -v "$PROJECT_APP_DIR"
116140

117-
squashfs-root/AppRun "$PROJECT_APP_DIR"
141+
# appimagetool (go-appimage) passes -fstime to mksquashfs, which conflicts with
142+
# SOURCE_DATE_EPOCH environment variable.
143+
(
144+
unset SOURCE_DATE_EPOCH
145+
"$TOOL_EXTRACT_DIR/AppRun" "$PROJECT_APP_DIR"
146+
)
118147

119-
APPIMAGE_FILE="$PROJECT_NAME-$(git rev-parse --short HEAD | head -c7)-$ARCH.AppImage"
148+
# Deterministic filename
149+
readonly SHA="$(git rev-parse --short HEAD | head -c7)"
150+
APPIMAGE_FILE="$PROJECT_NAME-$SHA-$ARCH.AppImage"
120151
sha256sum "$APPIMAGE_FILE" >"$APPIMAGE_FILE.sha256"

‎tools/verify/__init__.py‎

Whitespace-only changes.

‎tools/verify/all.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
# Copyright © 2026 The TokTok team
4+
import argparse
5+
import os
6+
import subprocess
7+
import sys
8+
9+
import common
10+
from lib import git
11+
12+
# Add tools directory to path
13+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14+
15+
16+
def main():
17+
parser = argparse.ArgumentParser(
18+
description="Run all reproducibility verifications."
19+
)
20+
parser.add_argument("--tag", help="Tag to verify", default=git.current_tag())
21+
parser.add_argument(
22+
"--repo", help="Repository name", default=common.get_default_repo()
23+
)
24+
args = parser.parse_args()
25+
26+
tag = args.tag
27+
repo = args.repo
28+
verify_dir = os.path.dirname(os.path.abspath(__file__))
29+
30+
scripts = [
31+
os.path.join(verify_dir, "appimage.py"),
32+
# TODO(iphydf): flatpak.py
33+
]
34+
35+
failed = []
36+
for script in scripts:
37+
print(
38+
f"--- Running {os.path.basename(script)} for {repo} {tag} ---",
39+
file=sys.stderr,
40+
)
41+
cmd = [sys.executable, script, "--tag", tag, "--repo", repo]
42+
if subprocess.run(cmd).returncode != 0:
43+
failed.append(os.path.basename(script))
44+
45+
if failed:
46+
print(f"Verifications failed: {', '.join(failed)}", file=sys.stderr)
47+
sys.exit(1)
48+
else:
49+
print(f"All verifications passed for {repo} {tag}!", file=sys.stderr)
50+
sys.exit(0)
51+
52+
53+
if __name__ == "__main__":
54+
main()

‎tools/verify/appimage.py‎

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
# Copyright © 2026 The TokTok team
4+
import argparse
5+
import os
6+
import shutil
7+
import subprocess
8+
import sys
9+
import tempfile
10+
11+
import common
12+
from lib import git, github
13+
14+
# Add tools directory to path to allow importing lib
15+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
16+
17+
18+
def parse_args():
19+
parser = argparse.ArgumentParser(description="Verify AppImage reproducibility.")
20+
parser.add_argument("--tag", help="Tag to verify", default=git.current_tag())
21+
parser.add_argument(
22+
"--repo", help="Repository name", default=common.get_default_repo()
23+
)
24+
parser.add_argument(
25+
"--project-name", help="Project name (defaults to repo name)", default=None
26+
)
27+
return parser.parse_args()
28+
29+
30+
def main():
31+
args = parse_args()
32+
repo_name = args.repo
33+
tag = args.tag
34+
35+
gh = github.GitHub()
36+
assets = gh.release_assets(tag)
37+
# Search for AppImage assets (can be CiTools-... or citools-...)
38+
appimage_asset = next(
39+
(
40+
a
41+
for a in assets
42+
if a.name.lower().endswith(".appimage") and "x86_64" in a.name.lower()
43+
),
44+
None,
45+
)
46+
47+
if not appimage_asset:
48+
print(f"No x86_64 AppImage found for tag {tag} in {repo_name}", file=sys.stderr)
49+
return 1
50+
51+
with common.Workspace(repo_name, tag) as workspace:
52+
# Detect project name from the workspace (the cloned repo)
53+
project_name = (
54+
args.project_name or common.detect_project_name(workspace.root) or repo_name
55+
)
56+
print(f"Detected project name: {project_name}", file=sys.stderr)
57+
58+
released_path = os.path.join(workspace.root, "released.AppImage")
59+
print(f"Downloading {appimage_asset.name}...", file=sys.stderr)
60+
with open(released_path, "wb") as f:
61+
f.write(gh.download_asset(appimage_asset.id))
62+
63+
# 2. Build local
64+
# Get the commit timestamp for SOURCE_DATE_EPOCH
65+
commit_date = subprocess.check_output(
66+
["git", "-C", workspace.root, "log", "-1", "--format=%ct"], text=True
67+
).strip()
68+
69+
print(
70+
f"Building local AppImage via Docker (SOURCE_DATE_EPOCH={commit_date})...",
71+
file=sys.stderr,
72+
)
73+
workspace.run_docker(
74+
"alpine-appimage",
75+
[
76+
"third_party/ci-tools/platform/appimage/build.sh",
77+
"--arch",
78+
"x86_64",
79+
"--src-dir",
80+
"/qtox",
81+
"--project-name",
82+
project_name,
83+
"--",
84+
],
85+
env={
86+
"GITHUB_REPOSITORY": f"TokTok/{repo_name}",
87+
"GITHUB_REF": f"refs/tags/{tag}",
88+
"SOURCE_DATE_EPOCH": commit_date,
89+
},
90+
)
91+
print(f"Build completed successfully.", file=sys.stderr)
92+
93+
# Find the produced AppImage in the workspace root
94+
# Filename format: $PROJECT_NAME-$(git rev-parse --short HEAD | head -c7)-$ARCH.AppImage
95+
sha = subprocess.check_output(
96+
["git", "-C", workspace.root, "rev-parse", "--short", "HEAD"], text=True
97+
).strip()[:7]
98+
local_name = f"{project_name}-{sha}-x86_64.AppImage"
99+
local_path = os.path.join(workspace.root, local_name)
100+
101+
if not os.path.exists(local_path):
102+
print(f"Local build failed to produce {local_path}", file=sys.stderr)
103+
return 1
104+
105+
# 3. Compare
106+
print(f"Comparing released and local AppImages...", file=sys.stderr)
107+
108+
def get_sha256(path):
109+
return subprocess.check_output(["sha256sum", path], text=True).split()[0]
110+
111+
released_sha = get_sha256(released_path)
112+
local_sha = get_sha256(local_path)
113+
114+
print(f"Released SHA256: {released_sha}")
115+
print(f"Local SHA256: {local_sha}")
116+
117+
if released_sha != local_sha:
118+
print("AppImages differ!", file=sys.stderr)
119+
120+
# Deep investigation
121+
print("\n--- Deep Investigation ---", file=sys.stderr)
122+
released_dir = os.path.join(workspace.root, "released_ext")
123+
local_dir = os.path.join(workspace.root, "local_ext")
124+
125+
def extract_appimage(path, out):
126+
"""Extract SquashFS content from AppImage."""
127+
# AppImages extract themselves when called with --appimage-extract
128+
# We make sure it's executable first.
129+
os.chmod(path, 0o755)
130+
try:
131+
# In some environments (like Docker/restricted shells),
132+
# we might need --appimage-extract-and-run or specific env vars.
133+
# But usually this is the most direct way.
134+
subprocess.run(
135+
[path, "--appimage-extract"],
136+
cwd=workspace.root,
137+
check=True,
138+
capture_output=True,
139+
)
140+
target_squash = os.path.join(workspace.root, "squashfs-root")
141+
if os.path.exists(target_squash):
142+
shutil.move(target_squash, out)
143+
else:
144+
print(
145+
f"Extraction of {path} failed to produce squashfs-root",
146+
file=sys.stderr,
147+
)
148+
except Exception as e:
149+
print(f"Extraction of {path} failed: {e}", file=sys.stderr)
150+
# Fallback to unsquashfs if the binary can't run
151+
subprocess.run(
152+
["unsquashfs", "-d", out, "-f", path],
153+
check=True,
154+
capture_output=True,
155+
)
156+
157+
try:
158+
print("Extracting released AppImage...", file=sys.stderr)
159+
extract_appimage(released_path, released_dir)
160+
print("Extracting local AppImage...", file=sys.stderr)
161+
extract_appimage(local_path, local_dir)
162+
163+
print("Comparing extracted filesystem contents...", file=sys.stderr)
164+
# Compare file structures and content hashes
165+
diff_proc = subprocess.run(
166+
["diff", "-rq", released_dir, local_dir],
167+
capture_output=True,
168+
text=True,
169+
)
170+
171+
if diff_proc.returncode == 0:
172+
print(
173+
"SUCCESS: Filesystem contents are bit-for-bit identical!",
174+
file=sys.stderr,
175+
)
176+
print(
177+
"The difference lies solely in the AppImage packaging (SquashFS metadata or Runtime).",
178+
file=sys.stderr,
179+
)
180+
else:
181+
print("DIFFERENCES FOUND in filesystem contents:", file=sys.stderr)
182+
print(diff_proc.stdout)
183+
184+
# Run diffoscope on the directories for a detailed breakdown
185+
if shutil.which("diffoscope"):
186+
print(
187+
"\nRunning diffoscope on extracted directories...",
188+
file=sys.stderr,
189+
)
190+
# Limit output to avoid huge logs
191+
subprocess.run(
192+
["diffoscope", "--text", "-", released_dir, local_dir]
193+
)
194+
except Exception as e:
195+
print(f"Deep investigation failed: {e}", file=sys.stderr)
196+
197+
# Always run diffoscope on the full AppImage as a final reference
198+
if shutil.which("diffoscope"):
199+
print("\n--- Full AppImage Diff (Reference) ---", file=sys.stderr)
200+
subprocess.run(["diffoscope", released_path, local_path])
201+
202+
return 1
203+
else:
204+
print("AppImages are identical!", file=sys.stderr)
205+
return 0
206+
207+
208+
if __name__ == "__main__":
209+
sys.exit(main())

0 commit comments

Comments
 (0)