Skip to content

Commit 7441813

Browse files
committed
Bundle GCC runtimes and remove forbidden external gconv symlinks
1 parent c594cf7 commit 7441813

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎.github/workflows/snap.yml‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: snap-strict
22
on:
33
workflow_dispatch:
44
push:
5-
branches: [fix/snap-strict-release]
5+
branches: [fix/snap-external-links]
66
permissions:
77
contents: read
88
jobs:
@@ -14,6 +14,14 @@ jobs:
1414
- name: Build strict snap
1515
uses: snapcore/action-build@v1
1616
id: build
17+
- name: Check package with Canonical Store review tools
18+
env:
19+
SNAP_FILE: ${{ steps.build.outputs.snap }}
20+
run: |
21+
sudo snap install review-tools
22+
mkdir -p "$HOME/snap/review-tools/common"
23+
cp "$SNAP_FILE" "$HOME/snap/review-tools/common/medha.snap"
24+
review-tools.snap-review "$HOME/snap/review-tools/common/medha.snap" --json > snap-review.json
1725
- name: Verify confinement and install test package
1826
env:
1927
SNAP_FILE: ${{ steps.build.outputs.snap }}
@@ -29,11 +37,20 @@ jobs:
2937
export MEDHA_SMOKE_RESULT="$HOME/snap/medha-ide/common/gui-smoke.json"
3038
timeout 180 snap run medha-ide --smoke-gui
3139
python3 -c 'import json,os; assert json.load(open(os.environ["MEDHA_SMOKE_RESULT"]))["status"] == "PASS"'
40+
- name: Test C++ shared runtime inside confinement
41+
run: |
42+
cat > "$HOME/snap/medha-ide/common/cpp-runtime.cpp" <<'CPP'
43+
#include <iostream>
44+
#include <stdexcept>
45+
int main() { try { throw std::runtime_error("CPP_RUNTIME_PASS"); } catch (const std::exception& e) { std::cout << e.what() << std::endl; } }
46+
CPP
47+
snap run --shell medha-ide -c '"$SNAP/toolwrap/g++" "$SNAP_USER_COMMON/cpp-runtime.cpp" -o "$SNAP_USER_COMMON/cpp-runtime" && "$SNAP_USER_COMMON/cpp-runtime"' | tee cpp-runtime.log
48+
grep -qx CPP_RUNTIME_PASS cpp-runtime.log
3249
- name: Collect test evidence
3350
if: always()
3451
run: |
3552
mkdir -p snap-evidence
36-
cp snap-metadata.yaml snap-evidence/ 2>/dev/null || true
53+
cp snap-metadata.yaml snap-review.json cpp-runtime.log snap-evidence/ 2>/dev/null || true
3754
cp "$HOME"/snap/medha-ide/common/gui-smoke.* snap-evidence/ 2>/dev/null || true
3855
- uses: actions/upload-artifact@v4
3956
if: always()

‎snap/snapcraft.yaml‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,32 @@ parts:
143143
- libstdc++6
144144
- make
145145

146-
# glibc runtime files are part of the core24 base, so snapcraft does NOT stage them.
147-
# But `gcc --sysroot=$SNAP` makes the linker look for e.g. /lib/x86_64-linux-gnu/libm.so.6
148-
# INSIDE $SNAP. WHAT this part does: for every runtime .so of libc6 / libgcc-s1 / libstdc++6
149-
# that is not already in the snap, add an absolute symlink pointing to the same path.
150-
# Inside the snap's mount namespace "/" IS core24, so the link resolves to the base's copy.
151-
# (Verified: C + C++ compile and run with host headers hidden, only the sysroot visible.)
146+
# GCC's sysroot needs the core24 libc linker targets. Only libc runtime
147+
# targets may point into the base. Bundle GCC/C++ runtimes, and omit gconv
148+
# module aliases (the running libc already loads those from the base).
152149
libc-links:
153150
plugin: nil
154-
# Prime the Python venv first: it creates lib64 -> lib. Creating a real
155-
# lib64 directory before that makes python-deps fail with IsADirectoryError.
151+
# The Python venv must prime lib64 -> lib before these linker aliases.
156152
after: [compilers, python-deps]
157153
override-prime: |
158154
craftctl default
159155
for pkg in libc6 libgcc-s1 libstdc++6; do
160156
dpkg -L "$pkg" 2>/dev/null | grep -E '^/(usr/)?lib(64)?/.*\.so[.0-9]*$' | while read -r f; do
161-
# WHY both paths: noble ships glibc in /usr/lib, but libc6-dev's linker scripts
162-
# (libc.so, libm.so) still name /lib/x86_64-linux-gnu/... and /lib64/ld-linux...
157+
case "$f" in */gconv/*) continue ;; esac
158+
if [ "$pkg" != libc6 ] && [ ! -e "$CRAFT_PRIME$f" ]; then
159+
mkdir -p "$(dirname "$CRAFT_PRIME$f")"
160+
cp -L "$f" "$CRAFT_PRIME$f"
161+
fi
162+
# Noble uses /usr/lib; glibc linker scripts also reference /lib.
163163
for t in "$f" "${f#/usr}"; do
164164
[ -e "$CRAFT_PRIME$t" ] || [ -L "$CRAFT_PRIME$t" ] && continue
165165
mkdir -p "$(dirname "$CRAFT_PRIME$t")"
166-
ln -s "$f" "$CRAFT_PRIME$t"
166+
if [ "$pkg" = libc6 ]; then
167+
ln -s "$f" "$CRAFT_PRIME$t"
168+
else
169+
target=$(realpath --relative-to="$(dirname "$CRAFT_PRIME$t")" "$CRAFT_PRIME$f")
170+
ln -s "$target" "$CRAFT_PRIME$t"
171+
fi
167172
done
168173
done
169174
done

0 commit comments

Comments
 (0)