-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbuild_flatpak.sh
More file actions
218 lines (186 loc) · 8.47 KB
/
build_flatpak.sh
File metadata and controls
218 lines (186 loc) · 8.47 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# DLSS Updater - Flatpak Build Script
# Run this script in WSL2 or native Linux to build the Flatpak package
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get version from version.py
VERSION=$(grep -oP '__version__\s*=\s*"\K[^"]+' dlss_updater/version.py)
echo -e "${GREEN}Building DLSS Updater v${VERSION} Flatpak${NC}"
# =============================================================================
# Step 1: Check and install system dependencies
# =============================================================================
echo -e "\n${YELLOW}[1/6] Checking system dependencies...${NC}"
install_deps() {
if command -v apt-get &> /dev/null; then
echo "Detected Debian/Ubuntu - installing with apt"
sudo apt-get update
sudo apt-get install -y \
flatpak \
flatpak-builder \
patchelf \
execstack
elif command -v dnf &> /dev/null; then
echo "Detected Fedora/RHEL - installing with dnf"
sudo dnf install -y \
flatpak \
flatpak-builder \
patchelf \
execstack
elif command -v pacman &> /dev/null; then
echo "Detected Arch Linux - installing with pacman"
sudo pacman -S --noconfirm \
flatpak \
flatpak-builder \
patchelf
echo -e "${YELLOW}Note: execstack is in AUR on Arch — install manually if missing (yay -S execstack)${NC}"
else
echo -e "${RED}Could not detect package manager. Please install dependencies manually.${NC}"
exit 1
fi
}
# Check for required tools
MISSING_DEPS=false
for cmd in flatpak flatpak-builder; do
if ! command -v $cmd &> /dev/null; then
MISSING_DEPS=true
break
fi
done
if [ "$MISSING_DEPS" = true ]; then
echo "Installing build dependencies..."
install_deps
else
echo -e "${GREEN}All build dependencies already installed${NC}"
fi
# =============================================================================
# Step 2: Setup Flathub repository and SDK
# =============================================================================
echo -e "\n${YELLOW}[2/6] Setting up Flathub repository and SDK...${NC}"
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
# Check if SDK is installed
if ! flatpak list --user | grep -q "org.freedesktop.Sdk//25.08"; then
echo "Installing Freedesktop SDK 25.08..."
flatpak install --user -y flathub org.freedesktop.Sdk//25.08
else
echo -e "${GREEN}Freedesktop SDK 25.08 already installed${NC}"
fi
if ! flatpak list --user | grep -q "org.freedesktop.Platform//25.08"; then
echo "Installing Freedesktop Platform 25.08..."
flatpak install --user -y flathub org.freedesktop.Platform//25.08
else
echo -e "${GREEN}Freedesktop Platform 25.08 already installed${NC}"
fi
# =============================================================================
# Step 3: Check for uv and install Python dependencies
# =============================================================================
echo -e "\n${YELLOW}[3/6] Installing Python dependencies with uv...${NC}"
if ! command -v uv &> /dev/null; then
echo "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.cargo/bin:$PATH"
fi
# Use Python 3.14.3 free-threaded for Linux builds (matches Windows / .python-version)
if ! uv python list | grep -q "3.14.3+freethreaded"; then
echo "Installing Python 3.14.3 (free-threaded)..."
uv python install 3.14.3+freethreaded
fi
uv python pin 3.14.3+freethreaded
uv sync --extra build
# =============================================================================
# Step 3.5: Clear PT_GNU_STACK on bundled libpython (Issue #217)
# =============================================================================
# python-build-standalone 3.14.3+freethreaded ships libpython3.14t.so.1.0 with
# PT_GNU_STACK marked executable (RWE). Modern Linux kernels (Steam Deck SteamOS,
# CachyOS, recent Arch/Fedora) enforce W^X and reject dlopen() on shared objects
# requesting an executable stack, breaking the PyInstaller-bundled application.
# Clearing the flag here means PyInstaller copies the corrected .so into the
# onefile bundle. 3.14.2+freethreaded did not have this flag set; the regression
# is in the upstream 3.14.3 build.
echo -e "\n${YELLOW}[3.5/6] Clearing PT_GNU_STACK on bundled .so files (Issue #217)...${NC}"
if ! command -v execstack &> /dev/null; then
echo -e "${RED}Error: execstack not installed. Install with: sudo apt-get install -y execstack${NC}"
exit 1
fi
PY_BIN="$(uv python find 3.14.3+freethreaded)"
# Inside a uv project, `uv python find` returns the .venv symlink. Resolve to the
# real interpreter in ~/.local/share/uv/python/... so we patch the source-of-truth
# libpython that PyInstaller will actually bundle.
PY_BIN_REAL="$(readlink -f "$PY_BIN")"
PY_ROOT="$(dirname "$(dirname "$PY_BIN_REAL")")"
echo "Python install root: $PY_ROOT"
# Clear executable stack on all .so files in the Python install.
# execstack returns non-zero on files without a GNU_STACK header; suppress with || true.
find "$PY_ROOT" -name '*.so*' -type f -print0 | xargs -0 -r execstack -c 2>/dev/null || true
# Hard-verify libpython is clean - fail the build rather than ship a broken binary.
LIBPY="$PY_ROOT/lib/libpython3.14t.so.1.0"
if [ ! -f "$LIBPY" ]; then
echo -e "${RED}Error: libpython not found at $LIBPY${NC}"
exit 1
fi
if readelf -lW "$LIBPY" | grep -E '^\s*GNU_STACK' | grep -q 'RWE'; then
echo -e "${RED}Error: libpython still has executable stack after execstack -c${NC}"
readelf -lW "$LIBPY" | grep GNU_STACK
exit 1
fi
echo -e "${GREEN}libpython GNU_STACK verified clean (RW, not RWE)${NC}"
# =============================================================================
# Step 4: Build with PyInstaller
# =============================================================================
echo -e "\n${YELLOW}[4/6] Building Linux application with PyInstaller...${NC}"
# Clean previous builds
rm -rf build/pyinstaller dist/DLSS_Updater .flatpak-builder/ build-dir/ repo/
# Run PyInstaller with the Linux spec file
# PYTHON_GIL=0 suppresses msgpack GIL warning during analysis phase
PYTHON_GIL=0 uv run pyinstaller DLSS_Updater_Linux.spec --distpath dist --workpath build/pyinstaller
# Verify the binary was created
if [ ! -f "dist/DLSS_Updater" ]; then
echo -e "${RED}Error: PyInstaller build failed - dist/DLSS_Updater not found${NC}"
exit 1
fi
echo -e "${GREEN}Flet build successful${NC}"
ls -la dist/
# =============================================================================
# Step 5: Build Flatpak
# =============================================================================
echo -e "\n${YELLOW}[5/6] Building Flatpak package...${NC}"
# Use --build-only to skip the finish phase (which requires appstream-compose)
flatpak-builder --user --force-clean --build-only build-dir io.github.recol.dlss-updater.yml
# Manually apply finish-args (permissions)
flatpak build-finish build-dir \
--socket=wayland \
--socket=fallback-x11 \
--device=dri \
--share=ipc \
--share=network \
--filesystem=home:rw \
--filesystem=/mnt:rw \
--filesystem=/media:rw \
--filesystem=/run/media:rw \
--filesystem=xdg-config/DLSS-Updater:rw \
--filesystem=xdg-cache/DLSS-Updater:rw \
--filesystem=~/.local/share/dlss-updater:create \
--filesystem=~/.flet:create \
--talk-name=org.freedesktop.portal.FileChooser \
--command=dlss-updater
# Export to local repo
flatpak build-export repo build-dir
# =============================================================================
# Step 6: Create distributable bundle
# =============================================================================
echo -e "\n${YELLOW}[6/6] Creating Flatpak bundle...${NC}"
FLATPAK_NAME="DLSS_Updater-${VERSION}.flatpak"
flatpak build-bundle repo "${FLATPAK_NAME}" io.github.recol.dlss-updater
echo -e "\n${GREEN}========================================${NC}"
echo -e "${GREEN}Build complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "Flatpak bundle: ${YELLOW}${FLATPAK_NAME}${NC}"
echo -e "Size: $(du -h "${FLATPAK_NAME}" | cut -f1)"
echo -e "\nTo install and test locally:"
echo -e " ${YELLOW}flatpak install --user ${FLATPAK_NAME}${NC}"
echo -e " ${YELLOW}flatpak run io.github.recol.dlss-updater${NC}"
echo -e "\nTo uninstall:"
echo -e " ${YELLOW}flatpak uninstall --user io.github.recol.dlss-updater${NC}"